task_id
int64 601
974
| text
stringlengths 38
249
| code
stringlengths 30
908
| test_list
listlengths 3
3
| test_setup_code
stringclasses 2
values | challenge_test_list
listlengths 0
0
|
|---|---|---|---|---|---|
693
|
Write a function to check if the string is a valid email address or not using regex.
|
def find_First_Missing(array,start,end):
if (start > end):
return end + 1
if (start != array[start]):
return start;
mid = int((start + end) / 2)
if (array[mid] == mid):
return find_First_Missing(array,mid+1,end)
return find_First_Missing(array,start,mid)
|
[
"assert multiply_elements((1, 5, 7, 8, 10)) == (5, 35, 56, 80)",
"assert multiply_elements((2, 4, 5, 6, 7)) == (8, 20, 30, 42)",
"assert multiply_elements((12, 13, 14, 9, 15)) == (156, 182, 126, 135)"
] |
[] |
|
685
|
Write a python function to print duplicants from a list of integers.
|
def check_monthnumber_number(monthnum3):
if(monthnum3==4 or monthnum3==6 or monthnum3==9 or monthnum3==11):
return True
else:
return False
|
[
"assert largest_subset([ 1, 3, 6, 13, 17, 18 ], 6) == 4",
"assert largest_subset([10, 5, 3, 15, 20], 5) == 3",
"assert largest_subset([18, 1, 3, 6, 13, 17], 6) == 4"
] |
[] |
|
719
|
Write a function to sort a given list of strings of numbers numerically.
|
def min_k(test_list, K):
res = sorted(test_list, key = lambda x: x[1])[:K]
return (res)
|
[
"assert fibonacci(7) == 13",
"assert fibonacci(8) == 21",
"assert fibonacci(9) == 34"
] |
[] |
|
857
|
Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.
|
def Extract(lst):
return [item[-1] for item in lst]
|
[
"assert move_last([1,2,3,4]) == [2,3,4,1]",
"assert move_last([2,3,4,1,5,0]) == [3,4,1,5,0,2]",
"assert move_last([5,4,3,2,1]) == [4,3,2,1,5]"
] |
[] |
|
641
|
Write a function to find the number which occurs for odd number of times in the given array.
|
def all_Bits_Set_In_The_Given_Range(n,l,r):
num = ((1 << r) - 1) ^ ((1 << (l - 1)) - 1)
new_num = n & num
if (num == new_num):
return True
return False
|
[
"assert max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3],8) == 5",
"assert max_sub_array_sum([1, -2, 1, 1, -2, 1],6) == 2",
"assert max_sub_array_sum([-1, -2, 3, 4, 5],5) == 3"
] |
[] |
|
819
|
Write a python function to find the minimum number of swaps required to convert one binary string to another.
|
def Convert(string):
li = list(string.split(" "))
return li
|
[
"assert get_Number(8,5) == 2",
"assert get_Number(7,2) == 3",
"assert get_Number(5,2) == 3"
] |
[] |
|
843
|
Write a function to filter the height and width of students which are stored in a dictionary.
|
def remove_negs(num_list):
for item in num_list:
if item < 0:
num_list.remove(item)
return num_list
|
[
"assert text_match(\"aabbbbd\") == 'Not matched!'",
"assert text_match(\"aabAbbbc\") == 'Not matched!'",
"assert text_match(\"accddbbjjjb\") == 'Found a match!'"
] |
[] |
|
614
|
Write a function to create a new tuple from the given string and list.
|
MAX=1000;
def replace_spaces(string):
string=string.strip()
i=len(string)
space_count=string.count(' ')
new_length = i + space_count*2
if new_length > MAX:
return -1
index = new_length-1
string=list(string)
for f in range(i-2, new_length-2):
string.append('0')
for j in range(i-1, 0, -1):
if string[j] == ' ':
string[index] = '0'
string[index-1] = '2'
string[index-2] = '%'
index=index-3
else:
string[index] = string[j]
index -= 1
return ''.join(string)
|
[
"assert find_Points(5,10,1,5) == (1,10)",
"assert find_Points(3,5,7,9) == (3,9)",
"assert find_Points(1,5,2,8) == (1,8)"
] |
[] |
|
705
|
Write a python function to count the total set bits from 1 to n.
|
def find_Min_Diff(arr,n):
arr = sorted(arr)
diff = 10**20
for i in range(n-1):
if arr[i+1] - arr[i] < diff:
diff = arr[i+1] - arr[i]
return diff
|
[
"assert count_same_pair([1, 2, 3, 4, 5, 6, 7, 8],[2, 2, 3, 1, 2, 6, 7, 9])==4",
"assert count_same_pair([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==11",
"assert count_same_pair([2, 4, -6, -9, 11, -12, 14, -5, 17],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==1"
] |
[] |
|
750
|
Write a function to count those characters which have vowels as their neighbors in the given string.
|
def get_Pairs_Count(arr,n,sum):
count = 0
for i in range(0,n):
for j in range(i + 1,n):
if arr[i] + arr[j] == sum:
count += 1
return count
|
[
"assert left_rotate(\"python\",2) == \"thonpy\" ",
"assert left_rotate(\"bigdata\",3 ) == \"databig\" ",
"assert left_rotate(\"hadoop\",1 ) == \"adooph\" "
] |
[] |
|
900
|
Write a function to find the length of the shortest string that has both str1 and str2 as subsequences.
|
def count_Unset_Bits(n) :
cnt = 0;
for i in range(1,n + 1) :
temp = i;
while (temp) :
if (temp % 2 == 0) :
cnt += 1;
temp = temp // 2;
return cnt;
|
[
"assert Repeat([10, 20, 30, 20, 20, 30, 40, 50, -20, 60, 60, -20, -20]) == [20, 30, -20, 60]",
"assert Repeat([-1, 1, -1, 8]) == [-1]",
"assert Repeat([1, 2, 3, 1, 2,]) == [1, 2]"
] |
[] |
|
732
|
Write a python function to calculate the sum of the numbers in a list between the indices of a specified range.
|
def product_Equal(n):
if n < 10:
return False
prodOdd = 1; prodEven = 1
while n > 0:
digit = n % 10
prodOdd *= digit
n = n//10
if n == 0:
break;
digit = n % 10
prodEven *= digit
n = n//10
if prodOdd == prodEven:
return True
return False
|
[
"assert word_len(\"program\") == False",
"assert word_len(\"solution\") == True",
"assert word_len(\"data\") == True"
] |
[] |
|
700
|
Write a function that matches a string that has an 'a' followed by anything, ending in 'b'.
|
def unique_Element(arr,n):
s = set(arr)
if (len(s) == 1):
return ('YES')
else:
return ('NO')
|
[
"assert zip_list([[1, 3], [5, 7], [9, 11]] ,[[2, 4], [6, 8], [10, 12, 14]] )==[[1, 3, 2, 4], [5, 7, 6, 8], [9, 11, 10, 12, 14]]",
"assert zip_list([[1, 2], [3, 4], [5, 6]] ,[[7, 8], [9, 10], [11, 12]] )==[[1, 2, 7, 8], [3, 4, 9, 10], [5, 6, 11, 12]]",
"assert zip_list([['a','b'],['c','d']] , [['e','f'],['g','h']] )==[['a','b','e','f'],['c','d','g','h']]"
] |
[] |
|
730
|
Write a function to concatenate the given two tuples to a nested tuple.
|
import itertools
def remove_duplicate(list1):
list.sort(list1)
remove_duplicate = list(list1 for list1,_ in itertools.groupby(list1))
return remove_duplicate
|
[
"assert camel_to_snake('PythonProgram')==('python_program')",
"assert camel_to_snake('pythonLanguage')==('python_language')",
"assert camel_to_snake('ProgrammingLanguage')==('programming_language')"
] |
[] |
|
812
|
Write a python function to find minimum possible value for the given periodic function.
|
def count_tuplex(tuplex,value):
count = tuplex.count(value)
return count
|
[
"assert div_list([4,5,6],[1, 2, 3])==[4.0,2.5,2.0]",
"assert div_list([3,2],[1,4])==[3.0, 0.5]",
"assert div_list([90,120],[50,70])==[1.8, 1.7142857142857142]"
] |
[] |
|
723
|
Write a function to split the given string at uppercase letters by using regex.
|
import re
def remove_extra_char(text1):
pattern = re.compile('[\W_]+')
return (pattern.sub('', text1))
|
[
"assert remove_similar_row([[(4, 5), (3, 2)], [(2, 2), (4, 6)], [(3, 2), (4, 5)]] ) == {((2, 2), (4, 6)), ((3, 2), (4, 5))}",
"assert remove_similar_row([[(5, 6), (4, 3)], [(3, 3), (5, 7)], [(4, 3), (5, 6)]] ) == {((4, 3), (5, 6)), ((3, 3), (5, 7))}",
"assert remove_similar_row([[(6, 7), (5, 4)], [(4, 4), (6, 8)], [(5, 4), (6, 7)]] ) =={((4, 4), (6, 8)), ((5, 4), (6, 7))}"
] |
[] |
|
839
|
Write a function to remove the parenthesis area in a string.
|
from collections import Counter
def most_common_elem(s,a):
most_common_elem=Counter(s).most_common(a)
return most_common_elem
|
[
"assert count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]]) == 4",
"assert count_list([[1,2],[2,3],[4,5]]) == 3",
"assert count_list([[1,0],[2,0]]) == 2"
] |
[] |
|
615
|
Write a function to convert degrees to radians.
|
import math
def count_Divisors(n) :
count = 0
for i in range(1, (int)(math.sqrt(n)) + 2) :
if (n % i == 0) :
if( n // i == i) :
count = count + 1
else :
count = count + 2
if (count % 2 == 0) :
return ("Even")
else :
return ("Odd")
|
[
"assert arc_length(9,45)==3.5357142857142856",
"assert arc_length(9,480)==None",
"assert arc_length(5,270)==11.785714285714285"
] |
[] |
|
601
|
Write a python function to get the last element of each sublist.
|
def second_smallest(numbers):
if (len(numbers)<2):
return
if ((len(numbers)==2) and (numbers[0] == numbers[1]) ):
return
dup_items = set()
uniq_items = []
for x in numbers:
if x not in dup_items:
uniq_items.append(x)
dup_items.add(x)
uniq_items.sort()
return uniq_items[1]
|
[
"assert average_Even(2) == 2",
"assert average_Even(4) == 3",
"assert average_Even(100) == 51"
] |
[] |
|
747
|
Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm.
|
def sort_String(str) :
str = ''.join(sorted(str))
return (str)
|
[
"assert find_Min_Swaps([1,0,1,0],4) == 3",
"assert find_Min_Swaps([0,1,0],3) == 1",
"assert find_Min_Swaps([0,0,1,1,0],5) == 2"
] |
[] |
|
913
|
Write a function to check if the given integer is a prime number.
|
def maximum_value(test_list):
res = [(key, max(lst)) for key, lst in test_list]
return (res)
|
[
"assert move_zero([1,0,2,0,3,4]) == [1,2,3,4,0,0]",
"assert move_zero([2,3,2,0,0,4,0,5,0]) == [2,3,2,4,5,0,0,0,0]",
"assert move_zero([0,1,0,1,1]) == [1,1,1,0,0]"
] |
[] |
|
928
|
Write a function to sum the length of the names of a given list of names after removing the names that start with a lowercase letter.
|
import re
def text_starta_endb(text):
patterns = 'a.*?b$'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!')
|
[
"assert min_sum_path([[ 2 ], [3, 9 ], [1, 6, 7 ]]) == 6",
"assert min_sum_path([[ 2 ], [3, 7 ], [8, 5, 6 ]]) == 10 ",
"assert min_sum_path([[ 3 ], [6, 4 ], [5, 2, 7 ]]) == 9"
] |
[] |
|
925
|
Write a function to reverse each list in a given list of lists.
|
def max_similar_indices(test_list1, test_list2):
res = [(max(x[0], y[0]), max(x[1], y[1]))
for x, y in zip(test_list1, test_list2)]
return (res)
|
[
"assert slope(4,2,2,5) == -1.5",
"assert slope(2,4,4,6) == 1",
"assert slope(1,2,4,2) == 0"
] |
[] |
|
782
|
Write a function to calculate the sum of all digits of the base to the specified power.
|
import re
regex = '''^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$'''
def check_IP(Ip):
if(re.search(regex, Ip)):
return ("Valid IP address")
else:
return ("Invalid IP address")
|
[
"assert all_Characters_Same(\"python\") == False",
"assert all_Characters_Same(\"aaa\") == True",
"assert all_Characters_Same(\"data\") == False"
] |
[] |
|
622
|
Write a function to find the list in a list of lists whose sum of elements is the highest.
|
import math
def sum_series(number):
total = 0
total = math.pow((number * (number + 1)) /2, 2)
return total
|
[
"assert num_position(\"there are 70 flats in this apartment\")==10",
"assert num_position(\"every adult have 32 teeth\")==17",
"assert num_position(\"isha has 79 chocolates in her bag\")==9"
] |
[] |
|
949
|
Write a function to find the minimum total path sum in the given triangle.
|
import math
def first_Digit(n) :
fact = 1
for i in range(2,n + 1) :
fact = fact * i
while (fact % 10 == 0) :
fact = int(fact / 10)
while (fact >= 10) :
fact = int(fact / 10)
return math.floor(fact)
|
[
"assert decreasing_trend([-4,-3,-2,-1]) == True",
"assert decreasing_trend([1,2,3]) == True",
"assert decreasing_trend([3,2,1]) == False"
] |
[] |
|
772
|
Write a function to remove everything except alphanumeric characters from the given string by using regex.
|
def sort_dict_item(test_dict):
res = {key: test_dict[key] for key in sorted(test_dict.keys(), key = lambda ele: ele[1] * ele[0])}
return (res)
|
[
"assert check_valid((True, True, True, True) ) == True",
"assert check_valid((True, False, True, True) ) == False",
"assert check_valid((True, True, True, True) ) == True"
] |
[] |
|
660
|
Write a python function to find the length of the shortest word.
|
import re
def text_match_three(text):
patterns = 'ab{3}?'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!')
|
[
"assert sum_Range_list([2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12],8,10) == 29",
"assert sum_Range_list([1,2,3,4,5],1,2) == 5",
"assert sum_Range_list([1,0,1,2,5,6],4,5) == 11"
] |
[] |
|
970
|
Write a python function to check for even parity of a given number.
|
def sorted_dict(dict1):
sorted_dict = {x: sorted(y) for x, y in dict1.items()}
return sorted_dict
|
[
"assert get_unique([(3, 4), (1, 2), (2, 4), (8, 2), (7, 2), (8, 1), (9, 1), (8, 4), (10, 4)] ) == '{4: 4, 2: 3, 1: 2}'",
"assert get_unique([(4, 5), (2, 3), (3, 5), (9, 3), (8, 3), (9, 2), (10, 2), (9, 5), (11, 5)] ) == '{5: 4, 3: 3, 2: 2}'",
"assert get_unique([(6, 5), (3, 4), (2, 6), (11, 1), (8, 22), (8, 11), (4, 3), (14, 3), (11, 6)] ) == '{5: 1, 4: 1, 6: 2, 1: 1, 22: 1, 11: 1, 3: 2}'"
] |
[] |
|
951
|
Write a function to check if the given tuple has any none value or not.
|
def max_of_three(num1,num2,num3):
if (num1 >= num2) and (num1 >= num3):
lnum = num1
elif (num2 >= num1) and (num2 >= num3):
lnum = num2
else:
lnum = num3
return lnum
|
[
"assert min_k([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2) == [('Akash', 2), ('Akshat', 4)]",
"assert min_k([('Sanjeev', 11), ('Angat', 5), ('Akash', 3), ('Nepin', 9)], 3) == [('Akash', 3), ('Angat', 5), ('Nepin', 9)]",
"assert min_k([('tanmay', 14), ('Amer', 11), ('Ayesha', 9), ('SKD', 16)], 1) == [('Ayesha', 9)]"
] |
[] |
|
690
|
Write a python function to check whether all the bits are within a given range or not.
|
def count_list(input_list):
return (len(input_list))**2
|
[
"assert set_Right_most_Unset_Bit(21) == 23",
"assert set_Right_most_Unset_Bit(11) == 15",
"assert set_Right_most_Unset_Bit(15) == 15"
] |
[] |
|
689
|
Write a function to convert the given string of integers into a tuple.
|
def front_and_rear(test_tup):
res = (test_tup[0], test_tup[-1])
return (res)
|
[
"assert recur_gcd(12,14) == 2",
"assert recur_gcd(13,17) == 1",
"assert recur_gcd(9, 3) == 3"
] |
[] |
|
673
|
Write a python function to find the sum of xor of all pairs of numbers in the given array.
|
def get_product(val) :
res = 1
for ele in val:
res *= ele
return res
def find_k_product(test_list, K):
res = get_product([sub[K] for sub in test_list])
return (res)
|
[
"assert is_triangleexists(50,60,70)==True",
"assert is_triangleexists(90,45,45)==True",
"assert is_triangleexists(150,30,70)==False"
] |
[] |
|
899
|
Write a python function to get the difference between two lists.
|
def find_triplet_array(A, arr_size, sum):
for i in range( 0, arr_size-2):
for j in range(i + 1, arr_size-1):
for k in range(j + 1, arr_size):
if A[i] + A[j] + A[k] == sum:
return A[i],A[j],A[k]
return True
return False
|
[
"assert Check_Solution(2,5,2) == \"2 solutions\"",
"assert Check_Solution(1,1,1) == \"No solutions\"",
"assert Check_Solution(1,2,1) == \"1 solution\""
] |
[] |
|
717
|
Write a function to find the longest common subsequence for the given three string sequence.
|
def noprofit_noloss(actual_cost,sale_amount):
if(sale_amount == actual_cost):
return True
else:
return False
|
[
"assert check(\"SEEquoiaL\") == 'accepted'",
"assert check('program') == \"not accepted\"",
"assert check('fine') == \"not accepted\""
] |
[] |
|
699
|
Write a function that matches a string that has an a followed by three 'b'.
|
def bell_Number(n):
bell = [[0 for i in range(n+1)] for j in range(n+1)]
bell[0][0] = 1
for i in range(1, n+1):
bell[i][0] = bell[i-1][i-1]
for j in range(1, i+1):
bell[i][j] = bell[i-1][j-1] + bell[i][j-1]
return bell[n][0]
|
[
"assert first_odd([1,3,5]) == 1",
"assert first_odd([2,4,1,3]) == 1",
"assert first_odd ([8,9,1]) == 9"
] |
[] |
|
894
|
Write a python function to check whether a sequence of numbers has a decreasing trend or not.
|
from operator import eq
def count_same_pair(nums1, nums2):
result = sum(map(eq, nums1, nums2))
return result
|
[
"assert lower_ctr('abc') == 3",
"assert lower_ctr('string') == 6",
"assert lower_ctr('Python') == 5"
] |
[] |
|
828
|
Write a function where a string will start with a specific number.
|
def min_Swaps(str1,str2) :
count = 0
for i in range(len(str1)) :
if str1[i] != str2[i] :
count += 1
if count % 2 == 0 :
return (count // 2)
else :
return ("Not Possible")
|
[
"assert min_Num([1,2,3,4,5,6,7,8,9],9) == 1",
"assert min_Num([1,2,3,4,5,6,7,8],8) == 2",
"assert min_Num([1,2,3],3) == 2"
] |
[] |
|
955
|
Write a python function to check whether every even index contains even numbers of a given list.
|
def subset(ar, n):
res = 0
ar.sort()
for i in range(0, n) :
count = 1
for i in range(n - 1):
if ar[i] == ar[i + 1]:
count+=1
else:
break
res = max(res, count)
return res
|
[
"assert sort_by_dnf([1,2,0,1,0,1,2,1,1], 9) == [0, 0, 1, 1, 1, 1, 1, 2, 2]",
"assert sort_by_dnf([1,0,0,1,2,1,2,2,1,0], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]",
"assert sort_by_dnf([2,2,1,0,0,0,1,1,2,1], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]"
] |
[] |
|
923
|
Write a python function to find minimum number swaps required to make two binary strings equal.
|
def even_num(x):
if x%2==0:
return True
else:
return False
|
[
"assert max_run_uppercase('GeMKSForGERksISBESt') == 5",
"assert max_run_uppercase('PrECIOusMOVemENTSYT') == 6",
"assert max_run_uppercase('GooGLEFluTTER') == 4"
] |
[] |
|
636
|
Write a function to remove duplicate words from a given string using collections module.
|
def tuple_to_dict(test_tup):
res = dict(test_tup[idx : idx + 2] for idx in range(0, len(test_tup), 2))
return (res)
|
[
"assert get_First_Set_Bit_Pos(12) == 3",
"assert get_First_Set_Bit_Pos(18) == 2",
"assert get_First_Set_Bit_Pos(16) == 5"
] |
[] |
|
922
|
Write a python function to count the number of pairs whose sum is equal to ‘sum’.
|
def substract_elements(test_tup1, test_tup2):
res = tuple(tuple(a - b for a, b in zip(tup1, tup2))
for tup1, tup2 in zip(test_tup1, test_tup2))
return (res)
|
[
"assert get_key({1:'python',2:'java'})==[1,2]",
"assert get_key({10:'red',20:'blue',30:'black'})==[10,20,30]",
"assert get_key({27:'language',39:'java',44:'little'})==[27,39,44]"
] |
[] |
|
664
|
Write a python function to choose points from two ranges such that no point lies in both the ranges.
|
def alternate_elements(list1):
result=[]
for item in list1[::2]:
result.append(item)
return result
|
[
"assert most_common_elem('lkseropewdssafsdfafkpwe',3)==[('s', 4), ('e', 3), ('f', 3)] ",
"assert most_common_elem('lkseropewdssafsdfafkpwe',2)==[('s', 4), ('e', 3)]",
"assert most_common_elem('lkseropewdssafsdfafkpwe',7)==[('s', 4), ('e', 3), ('f', 3), ('k', 2), ('p', 2), ('w', 2), ('d', 2)]"
] |
[] |
|
701
|
Write a function to find the index of the first occurrence of a given number in a sorted array.
|
def find_first_occurrence(A, x):
(left, right) = (0, len(A) - 1)
result = -1
while left <= right:
mid = (left + right) // 2
if x == A[mid]:
result = mid
right = mid - 1
elif x < A[mid]:
right = mid - 1
else:
left = mid + 1
return result
|
[
"assert prime_num(13)==True",
"assert prime_num(7)==True",
"assert prime_num(-1010)==False"
] |
[] |
|
720
|
Write a function to sort the tuples alphabetically by the first item of each tuple.
|
import sys
def find_closet(A, B, C, p, q, r):
diff = sys.maxsize
res_i = 0
res_j = 0
res_k = 0
i = 0
j = 0
k = 0
while(i < p and j < q and k < r):
minimum = min(A[i], min(B[j], C[k]))
maximum = max(A[i], max(B[j], C[k]));
if maximum-minimum < diff:
res_i = i
res_j = j
res_k = k
diff = maximum - minimum;
if diff == 0:
break
if A[i] == minimum:
i = i+1
elif B[j] == minimum:
j = j+1
else:
k = k+1
return A[res_i],B[res_j],C[res_k]
|
[
"assert check_alphanumeric(\"dawood@\") == 'Discard'",
"assert check_alphanumeric(\"skdmsam326\") == 'Accept'",
"assert check_alphanumeric(\"cooltricks@\") == 'Discard'"
] |
[] |
|
738
|
Write a python function to count the number of equal numbers from three given integers.
|
def min_Jumps(a, b, d):
temp = a
a = min(a, b)
b = max(temp, b)
if (d >= b):
return (d + b - 1) / b
if (d == 0):
return 0
if (d == a):
return 1
else:
return 2
|
[
"assert find_k_product([(5, 6, 7), (1, 3, 5), (8, 9, 19)], 2) == 665",
"assert find_k_product([(6, 7, 8), (2, 4, 6), (9, 10, 20)], 1) == 280",
"assert find_k_product([(7, 8, 9), (3, 5, 7), (10, 11, 21)], 0) == 210"
] |
[] |
|
771
|
Write a python function to check whether the product of numbers is even or not.
|
def min_of_two( x, y ):
if x < y:
return x
return y
|
[
"assert count_range_in_list([10,20,30,40,40,40,70,80,99],40,100)==6",
"assert count_range_in_list(['a','b','c','d','e','f'],'a','e')==5",
"assert count_range_in_list([7,8,9,15,17,19,45],15,20)==3"
] |
[] |
|
741
|
Write a function to round up a number to specific digits.
|
def max_sum_subseq(A):
n = len(A)
if n == 1:
return A[0]
look_up = [None] * n
look_up[0] = A[0]
look_up[1] = max(A[0], A[1])
for i in range(2, n):
look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i])
look_up[i] = max(look_up[i], A[i])
return look_up[n - 1]
|
[
"assert cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],1)==[{'name': 'Item-1', 'price': 101.1}]",
"assert cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],2)==[{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}]",
"assert cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}, {'name': 'Item-3', 'price': 45.09},{'name': 'Item-4', 'price': 22.75}],1)==[{'name': 'Item-4', 'price': 22.75}]"
] |
[] |
|
904
|
Write a python function to check for odd parity of a given number.
|
def check_greater(test_tup1, test_tup2):
res = all(x < y for x, y in zip(test_tup1, test_tup2))
return (res)
|
[
"assert move_num('I1love143you55three3000thousand') == 'Iloveyouthreethousand1143553000'",
"assert move_num('Avengers124Assemble') == 'AvengersAssemble124'",
"assert move_num('Its11our12path13to14see15things16do17things') == 'Itsourpathtoseethingsdothings11121314151617'"
] |
[] |
|
668
|
Write a function to zip two given lists of lists.
|
def all_Characters_Same(s) :
n = len(s)
for i in range(1,n) :
if s[i] != s[0] :
return False
return True
|
[
"assert string_length('python')==6",
"assert string_length('program')==7",
"assert string_length('language')==8"
] |
[] |
|
666
|
Write a python function to sort the given string.
|
def count_range_in_list(li, min, max):
ctr = 0
for x in li:
if min <= x <= max:
ctr += 1
return ctr
|
[
"assert text_starta_endb(\"aabbbb\")==('Found a match!')",
"assert text_starta_endb(\"aabAbbbc\")==('Not matched!')",
"assert text_starta_endb(\"accddbbjjj\")==('Not matched!')"
] |
[] |
|
971
|
Write a function to substract the elements of the given nested tuples.
|
def binomial_coeffi(n, k):
if (k == 0 or k == n):
return 1
return (binomial_coeffi(n - 1, k - 1)
+ binomial_coeffi(n - 1, k))
def rencontres_number(n, m):
if (n == 0 and m == 0):
return 1
if (n == 1 and m == 0):
return 0
if (m == 0):
return ((n - 1) * (rencontres_number(n - 1, 0)+ rencontres_number(n - 2, 0)))
return (binomial_coeffi(n, m) * rencontres_number(n - m, 0))
|
[
"assert count_char(\"Python\",'o')==1",
"assert count_char(\"little\",'t')==2",
"assert count_char(\"assert\",'s')==2"
] |
[] |
|
745
|
Write a function to find a path with the maximum average over all existing paths for the given square matrix of size n*n.
|
import math
def get_First_Set_Bit_Pos(n):
return math.log2(n&-n)+1
|
[
"assert length_Of_Last_Word(\"python language\") == 8",
"assert length_Of_Last_Word(\"PHP\") == 3",
"assert length_Of_Last_Word(\"\") == 0"
] |
[] |
|
776
|
Write a python function to calculate the product of all the numbers of a given tuple.
|
def sum_num(numbers):
total = 0
for x in numbers:
total += x
return total/len(numbers)
|
[
"assert find_closet([1, 4, 10],[2, 15, 20],[10, 12],3,3,2) == (10, 15, 10)",
"assert find_closet([20, 24, 100],[2, 19, 22, 79, 800],[10, 12, 23, 24, 119],3,5,5) == (24, 22, 23)",
"assert find_closet([2, 5, 11],[3, 16, 21],[11, 13],3,3,2) == (11, 16, 11)"
] |
[] |
|
897
|
Write a function to replace all spaces in the given string with character * list item * list item * list item * list item '%20'.
|
def tuple_str_int(test_str):
res = tuple(int(num) for num in test_str.replace('(', '').replace(')', '').replace('...', '').split(', '))
return (res)
|
[
"assert increasing_trend([1,2,3,4]) == True",
"assert increasing_trend([4,3,2,1]) == False",
"assert increasing_trend([0,1,4,9]) == True"
] |
[] |
|
959
|
Write a function to find the nth jacobsthal number.
|
import math
def find_Index(n):
x = math.sqrt(2 * math.pow(10,(n - 1)));
return round(x);
|
[
"assert sort_dict_item({(5, 6) : 3, (2, 3) : 9, (8, 4): 10, (6, 4): 12} ) == {(2, 3): 9, (6, 4): 12, (5, 6): 3, (8, 4): 10}",
"assert sort_dict_item({(6, 7) : 4, (3, 4) : 10, (9, 5): 11, (7, 5): 13} ) == {(3, 4): 10, (7, 5): 13, (6, 7): 4, (9, 5): 11}",
"assert sort_dict_item({(7, 8) : 5, (4, 5) : 11, (10, 6): 12, (8, 6): 14} ) == {(4, 5): 11, (8, 6): 14, (7, 8): 5, (10, 6): 12}"
] |
[] |
|
760
|
Write a python function to find the sum of all even natural numbers within the range l and r.
|
import re
def text_match_zero_one(text):
patterns = 'ab?'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!')
|
[
"assert perimeter_polygon(4,20)==80",
"assert perimeter_polygon(10,15)==150",
"assert perimeter_polygon(9,7)==63"
] |
[] |
|
728
|
Write a python function to find the smallest missing number from the given array.
|
def find_platform(arr, dep, n):
arr.sort()
dep.sort()
plat_needed = 1
result = 1
i = 1
j = 0
while (i < n and j < n):
if (arr[i] <= dep[j]):
plat_needed+= 1
i+= 1
elif (arr[i] > dep[j]):
plat_needed-= 1
j+= 1
if (plat_needed > result):
result = plat_needed
return result
|
[
"assert sorted_models([{'make':'Nokia', 'model':216, 'color':'Black'}, {'make':'Mi Max', 'model':2, 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color':'Blue'}])==[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'Mi Max', 'model': 2, 'color': 'Gold'}]",
"assert sorted_models([{'make':'Vivo', 'model':20,'color':'Blue'},{'make': 'oppo','model':17,'color':'Gold'},{'make':'Apple','model':11,'color':'red'}])==([{'make':'Vivo', 'model':20,'color':'Blue'},{'make': 'oppo','model':17,'color':'Gold'},{'make':'Apple','model':11,'color':'red'}])",
"assert sorted_models([{'make':'micromax','model':40,'color':'grey'},{'make':'poco','model':60,'color':'blue'}])==([{'make':'poco','model':60,'color':'blue'},{'make':'micromax','model':40,'color':'grey'}])"
] |
[] |
|
764
|
Write a function to count the same pair in two given lists using map function.
|
def lcm(x, y):
if x > y:
z = x
else:
z = y
while(True):
if((z % x == 0) and (z % y == 0)):
lcm = z
break
z += 1
return lcm
|
[
"assert second_smallest([1, 2, -8, -2, 0, -2])==-2",
"assert second_smallest([1, 1, -0.5, 0, 2, -2, -2])==-0.5",
"assert second_smallest([2,2])==None"
] |
[] |
|
737
|
Write a function to find the perimeter of a rectangle.
|
def divisible_by_digits(startnum, endnum):
return [n for n in range(startnum, endnum+1) \
if not any(map(lambda x: int(x) == 0 or n%int(x) != 0, str(n)))]
|
[
"assert sum_Square(25) == True",
"assert sum_Square(24) == False",
"assert sum_Square(17) == True"
] |
[] |
|
667
|
Write a python function to find the kth element in an array containing odd elements first and then even elements.
|
def reverse_list_lists(lists):
for l in lists:
l.sort(reverse = True)
return lists
|
[
"assert check_smaller((1, 2, 3), (2, 3, 4)) == False",
"assert check_smaller((4, 5, 6), (3, 4, 5)) == True",
"assert check_smaller((11, 12, 13), (10, 11, 12)) == True"
] |
[] |
|
687
|
Write a function to sort the given array without using any sorting algorithm. the given array consists of only 0, 1, and 2.
|
def reverse_Array_Upto_K(input, k):
return (input[k-1::-1] + input[k:])
|
[
"assert remove_multiple_spaces('Google Assistant') == 'Google Assistant'",
"assert remove_multiple_spaces('Quad Core') == 'Quad Core'",
"assert remove_multiple_spaces('ChromeCast Built-in') == 'ChromeCast Built-in'"
] |
[] |
|
896
|
Write a function to find area of a sector.
|
def count_duplic(lists):
element = []
frequency = []
if not lists:
return element
running_count = 1
for i in range(len(lists)-1):
if lists[i] == lists[i+1]:
running_count += 1
else:
frequency.append(running_count)
element.append(lists[i])
running_count = 1
frequency.append(running_count)
element.append(lists[i+1])
return element,frequency
|
[
"assert count_even([1, 2, 3, 5, 7, 8, 9, 10])==3",
"assert count_even([10,15,14,13,-18,12,-20])==5",
"assert count_even([1, 2, 4, 8, 9])==3"
] |
[] |
|
845
|
Write a function to separate and print the numbers and their position of a given string.
|
def count_Set_Bits(n) :
n += 1;
powerOf2 = 2;
cnt = n // 2;
while (powerOf2 <= n) :
totalPairs = n // powerOf2;
cnt += (totalPairs // 2) * powerOf2;
if (totalPairs & 1) :
cnt += (n % powerOf2)
else :
cnt += 0
powerOf2 <<= 1;
return cnt;
|
[
"assert coin_change([1, 2, 3],3,4)==4",
"assert coin_change([4,5,6,7,8,9],6,9)==2",
"assert coin_change([4,5,6,7,8,9],6,4)==1"
] |
[] |
|
671
|
Write a function to find the occurrences of n most common words in a given text.
|
import re
def text_match(text):
patterns = 'ab*?'
if re.search(patterns, text):
return ('Found a match!')
else:
return ('Not matched!')
|
[
"assert is_Product_Even([1,2,3],3) == True",
"assert is_Product_Even([1,2,1,4],4) == True",
"assert is_Product_Even([1,1],2) == False"
] |
[] |
|
751
|
Write a function to split a string at uppercase letters.
|
from collections import defaultdict
def get_unique(test_list):
res = defaultdict(list)
for sub in test_list:
res[sub[1]].append(sub[0])
res = dict(res)
res_dict = dict()
for key in res:
res_dict[key] = len(list(set(res[key])))
return (str(res_dict))
|
[
"assert area_trapezium(6,9,4)==30",
"assert area_trapezium(10,20,30)==450",
"assert area_trapezium(15,25,35)==700"
] |
[] |
|
957
|
Write a function to find the previous palindrome of a specified number.
|
import bisect
def left_insertion(a, x):
i = bisect.bisect_left(a, x)
return i
|
[
"assert generate_matrix(3)==[[1, 2, 3], [8, 9, 4], [7, 6, 5]] ",
"assert generate_matrix(2)==[[1,2],[4,3]]",
"assert generate_matrix(7)==[[1, 2, 3, 4, 5, 6, 7], [24, 25, 26, 27, 28, 29, 8], [23, 40, 41, 42, 43, 30, 9], [22, 39, 48, 49, 44, 31, 10], [21, 38, 47, 46, 45, 32, 11], [20, 37, 36, 35, 34, 33, 12], [19, 18, 17, 16, 15, 14, 13]]"
] |
[] |
|
942
|
Write a function to print n-times a list using map function.
|
def min_sum_path(A):
memo = [None] * len(A)
n = len(A) - 1
for i in range(len(A[n])):
memo[i] = A[n][i]
for i in range(len(A) - 2, -1,-1):
for j in range( len(A[i])):
memo[j] = A[i][j] + min(memo[j],
memo[j + 1])
return memo[0]
|
[
"assert check_Odd_Parity(13) == True",
"assert check_Odd_Parity(21) == True",
"assert check_Odd_Parity(18) == False"
] |
[] |
|
966
|
Write a function to find n-th rencontres number.
|
def count_alpha_dig_spl(string):
alphabets=digits = special = 0
for i in range(len(string)):
if(string[i].isalpha()):
alphabets = alphabets + 1
elif(string[i].isdigit()):
digits = digits + 1
else:
special = special + 1
return (alphabets,digits,special)
|
[
"assert rencontres_number(7, 2) == 924",
"assert rencontres_number(3, 0) == 2",
"assert rencontres_number(3, 1) == 3"
] |
[] |
|
752
|
Write a function to check whether the given month name contains 31 days or not.
|
def Check_Solution(a,b,c) :
if ((b*b) - (4*a*c)) > 0 :
return ("2 solutions")
elif ((b*b) - (4*a*c)) == 0 :
return ("1 solution")
else :
return ("No solutions")
|
[
"assert extract_unique({'msm' : [5, 6, 7, 8],'is' : [10, 11, 7, 5],'best' : [6, 12, 10, 8],'for' : [1, 2, 5]} ) == [1, 2, 5, 6, 7, 8, 10, 11, 12]",
"assert extract_unique({'Built' : [7, 1, 9, 4],'for' : [11, 21, 36, 14, 9],'ISP' : [4, 1, 21, 39, 47],'TV' : [1, 32, 38]} ) == [1, 4, 7, 9, 11, 14, 21, 32, 36, 38, 39, 47]",
"assert extract_unique({'F' : [11, 13, 14, 17],'A' : [12, 11, 15, 18],'N' : [19, 21, 15, 36],'G' : [37, 36, 35]}) == [11, 12, 13, 14, 15, 17, 18, 19, 21, 35, 36, 37]"
] |
[] |
|
770
|
Write a function to check whether the given ip address is valid or not using regex.
|
import re
def remove_char(S):
result = re.sub('[\W_]+', '', S)
return result
|
[
"assert find_Min_Sum([3,2,1],[2,1,3],3) == 0",
"assert find_Min_Sum([1,2,3],[4,5,6],3) == 9",
"assert find_Min_Sum([4,1,8,7],[2,3,6,5],4) == 6"
] |
[] |
|
953
|
Write a function to find the maximum of similar indices in two lists of tuples.
|
def check_none(test_tup):
res = any(map(lambda ele: ele is None, test_tup))
return (res)
|
[
"assert maxAverageOfPath([[1, 2, 3], [6, 5, 4], [7, 3, 9]], 3) == 5.2",
"assert maxAverageOfPath([[2, 3, 4], [7, 6, 5], [8, 4, 10]], 3) == 6.2",
"assert maxAverageOfPath([[3, 4, 5], [8, 7, 6], [9, 5, 11]], 3) == 7.2 "
] |
[] |
|
714
|
Write a function to remove sublists from a given list of lists, which are outside a given range.
|
def rgb_to_hsv(r, g, b):
r, g, b = r/255.0, g/255.0, b/255.0
mx = max(r, g, b)
mn = min(r, g, b)
df = mx-mn
if mx == mn:
h = 0
elif mx == r:
h = (60 * ((g-b)/df) + 360) % 360
elif mx == g:
h = (60 * ((b-r)/df) + 120) % 360
elif mx == b:
h = (60 * ((r-g)/df) + 240) % 360
if mx == 0:
s = 0
else:
s = (df/mx)*100
v = mx*100
return h, s, v
|
[
"assert find_triplet_array([1, 4, 45, 6, 10, 8], 6, 22) == (4, 10, 8)",
"assert find_triplet_array([12, 3, 5, 2, 6, 9], 6, 24) == (12, 3, 9)",
"assert find_triplet_array([1, 2, 3, 4, 5], 5, 9) == (1, 3, 5)"
] |
[] |
|
876
|
Write a python function to find the sum of an array.
|
def is_Isomorphic(str1,str2):
dict_str1 = {}
dict_str2 = {}
for i, value in enumerate(str1):
dict_str1[value] = dict_str1.get(value,[]) + [i]
for j, value in enumerate(str2):
dict_str2[value] = dict_str2.get(value,[]) + [j]
if sorted(dict_str1.values()) == sorted(dict_str2.values()):
return True
else:
return False
|
[
"assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],0)==12",
"assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],1)==15",
"assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],3)==9"
] |
[] |
|
757
|
Write a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order.
|
def sort_numeric_strings(nums_str):
result = [int(x) for x in nums_str]
result.sort()
return result
|
[
"assert remove_duplicate([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])==[[10, 20], [30, 56, 25], [33], [40]] ",
"assert remove_duplicate([\"a\", \"b\", \"a\", \"c\", \"c\"] )==[\"a\", \"b\", \"c\"]",
"assert remove_duplicate([1, 3, 5, 6, 3, 5, 6, 1] )==[1, 3, 5, 6]"
] |
[] |
|
774
|
Write a function to validate a gregorian date.
|
M = 100
def maxAverageOfPath(cost, N):
dp = [[0 for i in range(N + 1)] for j in range(N + 1)]
dp[0][0] = cost[0][0]
for i in range(1, N):
dp[i][0] = dp[i - 1][0] + cost[i][0]
for j in range(1, N):
dp[0][j] = dp[0][j - 1] + cost[0][j]
for i in range(1, N):
for j in range(1, N):
dp[i][j] = max(dp[i - 1][j],
dp[i][j - 1]) + cost[i][j]
return dp[N - 1][N - 1] / (2 * N - 1)
|
[
"assert is_abundant(12)==True",
"assert is_abundant(13)==False",
"assert is_abundant(9)==False"
] |
[] |
|
663
|
Write a function to find the largest possible value of k such that k modulo x is y.
|
def sum_Of_Primes(n):
prime = [True] * (n + 1)
p = 2
while p * p <= n:
if prime[p] == True:
i = p * 2
while i <= n:
prime[i] = False
i += p
p += 1
sum = 0
for i in range (2,n + 1):
if(prime[i]):
sum += i
return sum
|
[
"assert pair_OR_Sum([5,9,7,6],4) == 47",
"assert pair_OR_Sum([7,3,5],3) == 12",
"assert pair_OR_Sum([7,3],2) == 4"
] |
[] |
|
691
|
Write a function to count the most common character in a given string.
|
def previous_palindrome(num):
for x in range(num-1,0,-1):
if str(x) == str(x)[::-1]:
return x
|
[
"assert Check_Solution(2,0,2) == \"Yes\"",
"assert Check_Solution(2,-5,2) == \"Yes\"",
"assert Check_Solution(1,2,3) == \"No\""
] |
[] |
|
604
|
Write a function to caluclate arc length of an angle.
|
import math
def wind_chill(v,t):
windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16)
return int(round(windchill, 0))
|
[
"assert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\"])==['Python', 'Exercises', 'Practice', 'Solution']",
"assert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\",\"Java\"])==['Python', 'Exercises', 'Practice', 'Solution', 'Java']",
"assert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\",\"C++\",\"C\",\"C++\"])==['Python', 'Exercises', 'Practice', 'Solution','C++','C']"
] |
[] |
|
886
|
Write a function to multiply consecutive numbers of a given list.
|
import collections as ct
def merge_dictionaries(dict1,dict2):
merged_dict = dict(ct.ChainMap({}, dict1, dict2))
return merged_dict
|
[
"assert triangle_area(0) == 0",
"assert triangle_area(-1) == -1",
"assert triangle_area(2) == 4"
] |
[] |
|
880
|
Write a python function to count number of cubes of size k in a cube of size n.
|
from collections import Counter
def count_variable(a,b,c,d):
c = Counter(p=a, q=b, r=c, s=d)
return list(c.elements())
|
[
"assert add_tuple([5, 6, 7], (9, 10)) == [5, 6, 7, 9, 10]",
"assert add_tuple([6, 7, 8], (10, 11)) == [6, 7, 8, 10, 11]",
"assert add_tuple([7, 8, 9], (11, 12)) == [7, 8, 9, 11, 12]"
] |
[] |
|
960
|
Write a python function to left rotate the string.
|
def merge(lst):
return [list(ele) for ele in list(zip(*lst))]
|
[
"assert return_sum({'a': 100, 'b':200, 'c':300}) == 600",
"assert return_sum({'a': 25, 'b':18, 'c':45}) == 88",
"assert return_sum({'a': 36, 'b':39, 'c':49}) == 124"
] |
[] |
|
662
|
Write a function to remove similar rows from the given tuple matrix.
|
def mul_list(nums1,nums2):
result = map(lambda x, y: x * y, nums1, nums2)
return list(result)
|
[
"assert bell_Number(2) == 2",
"assert bell_Number(3) == 5",
"assert bell_Number(4) == 15"
] |
[] |
|
813
|
Write a function to find the longest chain which can be formed from the given set of pairs.
|
def nth_nums(nums,n):
nth_nums = list(map(lambda x: x ** n, nums))
return nth_nums
|
[
"assert max_of_two(10,20)==20",
"assert max_of_two(19,15)==19",
"assert max_of_two(-10,-20)==-10"
] |
[] |
|
603
|
Write a python function to find the index of an extra element present in one sorted array.
|
def sum_Odd(n):
terms = (n + 1)//2
sum1 = terms * terms
return sum1
def sum_in_Range(l,r):
return sum_Odd(r) - sum_Odd(l - 1)
|
[
"assert get_noOfways(4)==3",
"assert get_noOfways(3)==2",
"assert get_noOfways(5)==5"
] |
[] |
|
802
|
Write a function to clear the values of the given tuples.
|
def chinese_zodiac(year):
if (year - 2000) % 12 == 0:
sign = 'Dragon'
elif (year - 2000) % 12 == 1:
sign = 'Snake'
elif (year - 2000) % 12 == 2:
sign = 'Horse'
elif (year - 2000) % 12 == 3:
sign = 'sheep'
elif (year - 2000) % 12 == 4:
sign = 'Monkey'
elif (year - 2000) % 12 == 5:
sign = 'Rooster'
elif (year - 2000) % 12 == 6:
sign = 'Dog'
elif (year - 2000) % 12 == 7:
sign = 'Pig'
elif (year - 2000) % 12 == 8:
sign = 'Rat'
elif (year - 2000) % 12 == 9:
sign = 'Ox'
elif (year - 2000) % 12 == 10:
sign = 'Tiger'
else:
sign = 'Hare'
return sign
|
[
"assert find_max_val(15, 10, 5) == 15",
"assert find_max_val(187, 10, 5) == 185",
"assert find_max_val(16, 11, 1) == 12"
] |
[] |
|
640
|
Write a function to return true if the password is valid.
|
import re
def text_match_wordz_middle(text):
patterns = '\Bz\B'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!')
|
[
"assert text_match(\"msb\") == 'Not matched!'",
"assert text_match(\"a0c\") == 'Found a match!'",
"assert text_match(\"abbc\") == 'Found a match!'"
] |
[] |
|
631
|
Write a python function to check whether the given number is odd or not using bitwise operator.
|
def remove_spaces(str1):
str1 = str1.replace(' ','')
return str1
|
[
"assert count_vowels('bestinstareels') == 7",
"assert count_vowels('partofthejourneyistheend') == 12",
"assert count_vowels('amazonprime') == 5"
] |
[] |
|
607
|
Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.
|
def first_odd(nums):
first_odd = next((el for el in nums if el%2!=0),-1)
return first_odd
|
[
"assert number_ctr('program2bedone') == 1",
"assert number_ctr('3wonders') ==1",
"assert number_ctr('123') == 3"
] |
[] |
|
838
|
Write a function to find the fixed point in the given array.
|
import datetime
def check_date(m, d, y):
try:
m, d, y = map(int, (m, d, y))
datetime.date(y, m, d)
return True
except ValueError:
return False
|
[
"assert find_Index(2) == 4",
"assert find_Index(3) == 14",
"assert find_Index(4) == 45"
] |
[] |
|
798
|
Write a function to sort a list of lists by length and value.
|
def count_Fac(n):
m = n
count = 0
i = 2
while((i * i) <= m):
total = 0
while (n % i == 0):
n /= i
total += 1
temp = 0
j = 1
while((temp + j) <= total):
temp += j
count += 1
j += 1
i += 1
if (n != 1):
count += 1
return count
|
[
"assert remove_char(\"123abcjw:, .@! eiw\") == '123abcjweiw'",
"assert remove_char(\"Hello1234:, ! Howare33u\") == 'Hello1234Howare33u'",
"assert remove_char(\"Cool543Triks@:, Make@987Trips\") == 'Cool543TriksMake987Trips' "
] |
[] |
|
816
|
Write a python function to count the number of lists in a given number of lists.
|
def lucky_num(n):
List=range(-1,n*n+9,2)
i=2
while List[i:]:List=sorted(set(List)-set(List[List[i]::List[i]]));i+=1
return List[1:n+1]
|
[
"assert smallest_multiple(13)==360360",
"assert smallest_multiple(2)==2",
"assert smallest_multiple(1)==1"
] |
[] |
|
725
|
Write a function to find length of the string.
|
def Average(lst):
return sum(lst) / len(lst)
|
[
"assert Check_Solution(2,0,-1) == \"Yes\"",
"assert Check_Solution(1,-5,6) == \"No\"",
"assert Check_Solution(2,0,2) == \"Yes\""
] |
[] |
|
893
|
Write a python function to find the average of a list.
|
def Sum(N):
SumOfPrimeDivisors = [0]*(N + 1)
for i in range(2,N + 1) :
if (SumOfPrimeDivisors[i] == 0) :
for j in range(i,N + 1,i) :
SumOfPrimeDivisors[j] += i
return SumOfPrimeDivisors[N]
|
[
"assert min_jumps([1, 3, 6, 1, 0, 9], 6) == 3",
"assert min_jumps([1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9], 11) == 3",
"assert min_jumps([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 11) == 10"
] |
[] |
|
963
|
Write a function to count repeated items of a tuple.
|
def div_of_nums(nums,m,n):
result = list(filter(lambda x: (x % m == 0 and x % n == 0), nums))
return result
|
[
"assert mul_consecutive_nums([1, 1, 3, 4, 4, 5, 6, 7])==[1, 3, 12, 16, 20, 30, 42]",
"assert mul_consecutive_nums([4, 5, 8, 9, 6, 10])==[20, 40, 72, 54, 60]",
"assert mul_consecutive_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[2, 6, 12, 20, 30, 42, 56, 72, 90]"
] |
[] |
|
929
|
Write a python function to find the index of smallest triangular number with n digits.
|
def mutiple_tuple(nums):
temp = list(nums)
product = 1
for x in temp:
product *= x
return product
|
[
"assert max_sum_of_three_consecutive([100, 1000, 100, 1000, 1], 5) == 2101",
"assert max_sum_of_three_consecutive([3000, 2000, 1000, 3, 10], 5) == 5013",
"assert max_sum_of_three_consecutive([1, 2, 3, 4, 5, 6, 7, 8], 8) == 27"
] |
[] |
|
829
|
Write a python function to check whether the count of divisors is even or odd.
|
def count_even(array_nums):
count_even = len(list(filter(lambda x: (x%2 == 0) , array_nums)))
return count_even
|
[
"assert pass_validity(\"password\")==False",
"assert pass_validity(\"Password@10\")==True",
"assert pass_validity(\"password@10\")==False"
] |
[] |
|
775
|
Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple.
|
import re
regex = '^[aeiouAEIOU][A-Za-z0-9_]*'
def check_str(string):
if(re.search(regex, string)):
return ("Valid")
else:
return ("Invalid")
|
[
"assert count_Fac(24) == 3",
"assert count_Fac(12) == 2",
"assert count_Fac(4) == 1"
] |
[] |
|
657
|
Write a function to check if any list element is present in the given list.
|
def join_tuples(test_list):
res = []
for sub in test_list:
if res and res[-1][0] == sub[0]:
res[-1].extend(sub[1:])
else:
res.append([ele for ele in sub])
res = list(map(tuple, res))
return (res)
|
[
"assert listify_list(['Red', 'Blue', 'Black', 'White', 'Pink'])==[['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e'], ['P', 'i', 'n', 'k']]",
"assert listify_list(['python'])==[['p', 'y', 't', 'h', 'o', 'n']]",
"assert listify_list([' red ', 'green',' black', 'blue ',' orange', 'brown'])==[[' ', 'r', 'e', 'd', ' '], ['g', 'r', 'e', 'e', 'n'], [' ', 'b', 'l', 'a', 'c', 'k'], ['b', 'l', 'u', 'e', ' '], [' ', 'o', 'r', 'a', 'n', 'g', 'e'], ['b', 'r', 'o', 'w', 'n']]"
] |
[] |
|
780
|
Write a python function to count the number of distinct power of prime factor of given number.
|
import re
def check_substring(string, sample) :
if (sample in string):
y = "\A" + sample
x = re.search(y, string)
if x :
return ("string starts with the given substring")
else :
return ("string doesnt start with the given substring")
else :
return ("entered string isnt a substring")
|
[
"assert check([3,2,1,2,3,4],6) == True",
"assert check([2,1,4,5,1],5) == True",
"assert check([1,2,2,1,2,3],6) == True"
] |
[] |
End of preview. Expand
in Data Studio
edition_1938_google-research-datasets-mbpp-readymade
A Readymade by TheFactoryX
Original Dataset
Process
This dataset is a "readymade" - inspired by Marcel Duchamp's concept of taking everyday objects and recontextualizing them as art.
What we did:
- Selected the original dataset from Hugging Face
- Shuffled each column independently
- Destroyed all row-wise relationships
- Preserved structure, removed meaning
The result: Same data. Wrong order. New meaning. No meaning.
Purpose
This is art. This is not useful. This is the point.
Column relationships have been completely destroyed. The data maintains its types and values, but all semantic meaning has been removed.
Part of the Readymades project by TheFactoryX.
"I am a machine." — Andy Warhol
- Downloads last month
- 8