task_id
stringlengths
1
3
prompt
stringclasses
1 value
description
stringlengths
37
249
entry_point
stringlengths
3
33
canonical_solution
stringlengths
30
1.33k
given_tests
sequencelengths
3
3
test
stringlengths
127
4.21k
1
Write a function to find the minimum cost path to reach (m, n) from (0, 0) for the given cost matrix cost[][] and a position (m, n) in cost[][].
min_cost
R = 3 C = 3 def min_cost(cost, m, n): tc = [[0 for x in range(C)] for x in range(R)] tc[0][0] = cost[0][0] for i in range(1, m+1): tc[i][0] = tc[i-1][0] + cost[i][0] for j in range(1, n+1): tc[0][j] = tc[0][j-1] + cost[0][j] for i in range(1, m+1): for j in range(1, n+1): tc[i][j] = min(tc[i-1][j-1], tc[i-1][j], tc[i][j-1]) + cost[i][j] return tc[m][n]
[ "assert min_cost([[7, 2, 2], [6, 15, 1], [8, 4, 2]], 1, 1) == 22", "assert min_cost([[5, 6, 8], [8, 10, 2], [7, 3, 8]], 1, 2) == 13", "assert min_cost([[8, 9, 2], [6, 5, 7], [3, 8, 8]], 2, 2) == 21" ]
def check(candidate): # Check some simple cases assert min_cost([[1, 2, 3], [4, 8, 2], [1, 5, 3]], 2, 2) == 8 assert min_cost([[2, 3, 4], [5, 9, 3], [2, 6, 4]], 2, 2) == 12 assert min_cost([[3, 4, 5], [6, 10, 4], [3, 7, 5]], 2, 2) == 16
2
Write a function to find the similar elements from the given two tuple lists.
similar_elements
def similar_elements(test_tup1, test_tup2): res = tuple(set(test_tup1) & set(test_tup2)) return (res)
[ "assert similar_elements((8, 17, 15, 10), (19, 12, 9, 14)) == ()", "assert similar_elements((9, 10, 13, 8), (14, 10, 19, 17)) == (10,)", "assert similar_elements((11, 14, 17, 10), (15, 15, 10, 11)) == (10, 11)" ]
def check(candidate): # Check some simple cases assert similar_elements((3, 4, 5, 6),(5, 7, 4, 10)) == (4, 5) assert similar_elements((1, 2, 3, 4),(5, 4, 3, 7)) == (3, 4) assert similar_elements((11, 12, 14, 13),(17, 15, 14, 13)) == (13, 14)
3
Write a python function to identify non-prime numbers.
is_not_prime
import math def is_not_prime(n): result = False for i in range(2,int(math.sqrt(n)) + 1): if n % i == 0: result = True return result
[ "assert is_not_prime(31) == False", "assert is_not_prime(40) == True", "assert is_not_prime(34) == True" ]
def check(candidate): # Check some simple cases assert is_not_prime(2) == False assert is_not_prime(10) == True assert is_not_prime(35) == True
4
Write a function to find the largest integers from a given list of numbers using heap queue algorithm.
heap_queue_largest
import heapq as hq def heap_queue_largest(nums,n): largest_nums = hq.nlargest(n, nums) return largest_nums
[ "assert heap_queue_largest([27, 33, 23, 85, 11, 62, 73, 26, 61], 7) == [85, 73, 62, 61, 33, 27, 26]", "assert heap_queue_largest([26, 40, 22, 84, 16, 65, 77, 17, 57], 8) == [84, 77, 65, 57, 40, 26, 22, 17]", "assert heap_queue_largest([23, 33, 24, 84, 17, 70, 79, 21, 53], 5) == [84, 79, 70, 53, 33]" ]
def check(candidate): # Check some simple cases assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],3)==[85, 75, 65] assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],2)==[85, 75] assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],5)==[85, 75, 65, 58, 35]
5
Write a function to find the number of ways to fill it with 2 x 1 dominoes for the given 3 x n board.
count_ways
def count_ways(n): A = [0] * (n + 1) B = [0] * (n + 1) A[0] = 1 A[1] = 0 B[0] = 0 B[1] = 1 for i in range(2, n+1): A[i] = A[i - 2] + 2 * B[i - 1] B[i] = A[i - 1] + B[i - 2] return A[n]
[ "assert count_ways(9) == 0", "assert count_ways(12) == 2131", "assert count_ways(8) == 153" ]
def check(candidate): # Check some simple cases assert count_ways(2) == 3 assert count_ways(8) == 153 assert count_ways(12) == 2131
6
Write a python function to check whether the two numbers differ at one bit position only or not.
differ_At_One_Bit_Pos
def is_Power_Of_Two (x): return x and (not(x & (x - 1))) def differ_At_One_Bit_Pos(a,b): return is_Power_Of_Two(a ^ b)
[ "assert differ_At_One_Bit_Pos(5, 1) == True", "assert differ_At_One_Bit_Pos(4, 4) == 0", "assert differ_At_One_Bit_Pos(1, 9) == True" ]
def check(candidate): # Check some simple cases assert differ_At_One_Bit_Pos(13,9) == True assert differ_At_One_Bit_Pos(15,8) == False assert differ_At_One_Bit_Pos(2,4) == False
7
Write a function to find all words which are at least 4 characters long in a string by using regex.
find_char_long
import re def find_char_long(text): return (re.findall(r"\b\w{4,}\b", text))
[ "assert find_char_long(\"JfN9mdKj3Kfv29rMNswWJYpfW3WTi\") == ['JfN9mdKj3Kfv29rMNswWJYpfW3WTi']", "assert find_char_long(\"ui7 OLqnKFX1RZHlShM7 6\") == ['OLqnKFX1RZHlShM7']", "assert find_char_long(\"z4k9ubpb1KgR5kyVxne8b\") == ['z4k9ubpb1KgR5kyVxne8b']" ]
def check(candidate): # Check some simple cases assert find_char_long('Please move back to stream') == ['Please', 'move', 'back', 'stream'] assert find_char_long('Jing Eco and Tech') == ['Jing', 'Tech'] assert find_char_long('Jhingai wulu road Zone 3') == ['Jhingai', 'wulu', 'road', 'Zone']
8
Write a function to find squares of individual elements in a list using lambda function.
square_nums
def square_nums(nums): square_nums = list(map(lambda x: x ** 2, nums)) return square_nums
[ "assert square_nums([12, 17]) == [144, 289]", "assert square_nums([9, 15]) == [81, 225]", "assert square_nums([8, 13]) == [64, 169]" ]
def check(candidate): # Check some simple cases assert square_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1, 4, 9, 16, 25, 36, 49, 64, 81, 100] assert square_nums([10,20,30])==([100,400,900]) assert square_nums([12,15])==([144,225])
9
Write a python function to find the minimum number of rotations required to get the same string.
find_Rotations
def find_Rotations(str): tmp = str + str n = len(str) for i in range(1,n + 1): substring = tmp[i: i+n] if (str == substring): return i return n
[ "assert find_Rotations(\"wdk\") == 3", "assert find_Rotations(\"gmlivxfm\") == 8", "assert find_Rotations(\"yvsnt\") == 5" ]
def check(candidate): # Check some simple cases assert find_Rotations("aaaa") == 1 assert find_Rotations("ab") == 2 assert find_Rotations("abc") == 3
10
Write a function to get the n smallest items from a dataset.
small_nnum
import heapq def small_nnum(list1,n): smallest=heapq.nsmallest(n,list1) return smallest
[ "assert small_nnum([11, 19, 50, 73, 87, 17, 46, 43, 58, 84, 105], 8) == [11, 17, 19, 43, 46, 50, 58, 73]", "assert small_nnum([6, 15, 55, 75, 95, 24, 52, 40, 63, 75, 101], 1) == [6]", "assert small_nnum([14, 24, 50, 72, 89, 22, 51, 44, 64, 84, 98], 4) == [14, 22, 24, 44]" ]
def check(candidate): # Check some simple cases assert small_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2)==[10,20] assert small_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5)==[10,20,20,40,50] assert small_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3)==[10,20,20]
11
Write a python function to remove first and last occurrence of a given character from the string.
remove_Occ
def remove_Occ(s,ch): for i in range(len(s)): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break for i in range(len(s) - 1,-1,-1): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break return s
[ "assert remove_Occ('WCW', 'B') == \"WCW\"", "assert remove_Occ('REXJ', 'M') == \"REXJ\"", "assert remove_Occ('NOAVJUI', 'X') == \"NOAVJUI\"" ]
def check(candidate): # Check some simple cases assert remove_Occ("hello","l") == "heo" assert remove_Occ("abcda","a") == "bcd" assert remove_Occ("PHP","P") == "H"
12
Write a function to sort a given matrix in ascending order according to the sum of its rows.
sort_matrix
def sort_matrix(M): result = sorted(M, key=sum) return result
[ "assert sort_matrix([[2, 4, 7], [10, 3, 3], [6, 4, 6]]) == [[2, 4, 7], [10, 3, 3], [6, 4, 6]]", "assert sort_matrix([[5, 5, 6], [11, 9, 3], [1, 3, 9]]) == [[1, 3, 9], [5, 5, 6], [11, 9, 3]]", "assert sort_matrix([[3, 8, 10], [7, 7, 7], [4, 3, 3]]) == [[4, 3, 3], [3, 8, 10], [7, 7, 7]]" ]
def check(candidate): # Check some simple cases assert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]] assert sort_matrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])==[[-2, 4, -5], [1, -1, 1], [1, 2, 3]] assert sort_matrix([[5,8,9],[6,4,3],[2,1,4]])==[[2, 1, 4], [6, 4, 3], [5, 8, 9]]
13
Write a function to count the most common words in a dictionary.
count_common
from collections import Counter def count_common(words): word_counts = Counter(words) top_four = word_counts.most_common(4) return (top_four)
[ "assert count_common(['NDyEP', 'RPqcCteL', 'pzKgpHPo', 'ibv', 'rbogFSZgjOV', 'QzQ', 'uvoFp', 'WcseVmiYfmU']) == [('NDyEP', 1), ('RPqcCteL', 1), ('pzKgpHPo', 1), ('ibv', 1)]", "assert count_common(['LQW', 'mYFPqoTxA', 'aumsTilLAGB', 'yhzQk', 'IIfgQhISIY', 'iNNr', 'PxSXZJnO', 'iRfTv']) == [('LQW', 1), ('mYFPqoTxA', 1), ('aumsTilLAGB', 1), ('yhzQk', 1)]", "assert count_common(['wJNr', 'KozIsa', 'DFgOQWsoME', 'HBdmtvvwSAr', 'nikiDm', 'pqidtu', 'RAMAAdR', 'yyVXAjQ']) == [('wJNr', 1), ('KozIsa', 1), ('DFgOQWsoME', 1), ('HBdmtvvwSAr', 1)]" ]
def check(candidate): # Check some simple cases assert count_common(['red','green','black','pink','black','white','black','eyes','white','black','orange','pink','pink','red','red','white','orange','white',"black",'pink','green','green','pink','green','pink','white','orange',"orange",'red']) == [('pink', 6), ('black', 5), ('white', 5), ('red', 4)] assert count_common(['one', 'two', 'three', 'four', 'five', 'one', 'two', 'one', 'three', 'one']) == [('one', 4), ('two', 2), ('three', 2), ('four', 1)] assert count_common(['Facebook', 'Apple', 'Amazon', 'Netflix', 'Google', 'Apple', 'Netflix', 'Amazon']) == [('Apple', 2), ('Amazon', 2), ('Netflix', 2), ('Facebook', 1)]
14
Write a python function to find the volume of a triangular prism.
find_Volume
def find_Volume(l,b,h) : return ((l * b * h) / 2)
[ "assert find_Volume(1, 6, 4) == 12.0", "assert find_Volume(3, 6, 2) == 18.0", "assert find_Volume(2, 6, 4) == 24.0" ]
def check(candidate): # Check some simple cases assert find_Volume(10,8,6) == 240 assert find_Volume(3,2,2) == 6 assert find_Volume(1,2,1) == 1
15
Write a function to split a string at lowercase letters.
split_lowerstring
import re def split_lowerstring(text): return (re.findall('[a-z][^a-z]*', text))
[ "assert split_lowerstring(\"oXvErxRmUerhc\") == ['oX', 'vE', 'r', 'xR', 'mU', 'e', 'r', 'h', 'c']", "assert split_lowerstring(\"pAxuMDuUZqUAuX\") == ['pA', 'x', 'uMD', 'uUZ', 'qUA', 'uX']", "assert split_lowerstring(\"BVubGKphuNP\") == ['u', 'bGK', 'p', 'h', 'uNP']" ]
def check(candidate): # Check some simple cases assert split_lowerstring("AbCd")==['bC','d'] assert split_lowerstring("Python")==['y', 't', 'h', 'o', 'n'] assert split_lowerstring("Programming")==['r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g']
16
Write a function to find sequences of lowercase letters joined with an underscore.
text_lowercase_underscore
import re def text_lowercase_underscore(text): patterns = '^[a-z]+_[a-z]+$' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
[ "assert text_lowercase_underscore(\"zu~XIotCO\") == \"Not matched!\"", "assert text_lowercase_underscore(\"Be/IT?CRcYNEjy\") == \"Not matched!\"", "assert text_lowercase_underscore(\"o#URAzxnV>@bgfG\") == \"Not matched!\"" ]
def check(candidate): # Check some simple cases assert text_lowercase_underscore("aab_cbbbc")==('Found a match!') assert text_lowercase_underscore("aab_Abbbc")==('Not matched!') assert text_lowercase_underscore("Aaab_abbbc")==('Not matched!')
17
Write a function to find the perimeter of a square.
square_perimeter
def square_perimeter(a): perimeter=4*a return perimeter
[ "assert square_perimeter(8) == 32", "assert square_perimeter(2) == 8", "assert square_perimeter(2) == 8" ]
def check(candidate): # Check some simple cases assert square_perimeter(10)==40 assert square_perimeter(5)==20 assert square_perimeter(4)==16
18
Write a function to remove characters from the first string which are present in the second string.
remove_dirty_chars
NO_OF_CHARS = 256 def str_to_list(string): temp = [] for x in string: temp.append(x) return temp def lst_to_string(List): return ''.join(List) def get_char_count_array(string): count = [0] * NO_OF_CHARS for i in string: count[ord(i)] += 1 return count def remove_dirty_chars(string, second_string): count = get_char_count_array(second_string) ip_ind = 0 res_ind = 0 temp = '' str_list = str_to_list(string) while ip_ind != len(str_list): temp = str_list[ip_ind] if count[ord(temp)] == 0: str_list[res_ind] = str_list[ip_ind] res_ind += 1 ip_ind+=1 return lst_to_string(str_list[0:res_ind])
[ "assert remove_dirty_chars('dqlcrhtmubx', 'xigtq') == \"dlcrhmub\"", "assert remove_dirty_chars('whxtbxisodgjzb', 'nypsi') == \"whxtbxodgjzb\"", "assert remove_dirty_chars('dlqppzlppxsyzhx', 'zkevug') == \"dlqpplppxsyhx\"" ]
def check(candidate): # Check some simple cases assert remove_dirty_chars("probasscurve", "pros") == 'bacuve' assert remove_dirty_chars("digitalindia", "talent") == 'digiidi' assert remove_dirty_chars("exoticmiles", "toxic") == 'emles'
19
Write a function to find whether a given array of integers contains any duplicate element.
test_duplicate
def test_duplicate(arraynums): nums_set = set(arraynums) return len(arraynums) != len(nums_set)
[ "assert test_duplicate([6, 6, 2, 3, 6, 8, 5, 6, 2]) == True", "assert test_duplicate([2, 5, 5, 7, 2, 4, 9, 8, 8]) == True", "assert test_duplicate([6, 5, 5, 1, 7, 6, 1, 7, 7]) == True" ]
def check(candidate): # Check some simple cases assert test_duplicate(([1,2,3,4,5]))==False assert test_duplicate(([1,2,3,4, 4]))==True assert test_duplicate([1,1,2,2,3,3,4,4,5])==True
20
Write a function to check if the given number is woodball or not.
is_woodall
def is_woodall(x): if (x % 2 == 0): return False if (x == 1): return True x = x + 1 p = 0 while (x % 2 == 0): x = x/2 p = p + 1 if (p == x): return True return False
[ "assert is_woodall(201) == False", "assert is_woodall(199) == False", "assert is_woodall(196) == False" ]
def check(candidate): # Check some simple cases assert is_woodall(383) == True assert is_woodall(254) == False assert is_woodall(200) == False
21
Write a function to find m number of multiples of n.
multiples_of_num
def multiples_of_num(m,n): multiples_of_num= list(range(n,(m+1)*n, n)) return list(multiples_of_num)
[ "assert multiples_of_num(10, 4) == [4, 8, 12, 16, 20, 24, 28, 32, 36, 40]", "assert multiples_of_num(6, 5) == [5, 10, 15, 20, 25, 30]", "assert multiples_of_num(8, 7) == [7, 14, 21, 28, 35, 42, 49, 56]" ]
def check(candidate): # Check some simple cases assert multiples_of_num(4,3)== [3,6,9,12] assert multiples_of_num(2,5)== [5,10] assert multiples_of_num(9,2)== [2,4,6,8,10,12,14,16,18]
22
Write a function to find the first duplicate element in a given array of integers.
find_first_duplicate
def find_first_duplicate(nums): num_set = set() no_duplicate = -1 for i in range(len(nums)): if nums[i] in num_set: return nums[i] else: num_set.add(nums[i]) return no_duplicate
[ "assert find_first_duplicate([4, 6, 1, 5, 7, 3, 6]) == 6", "assert find_first_duplicate([6, 4, 2, 1, 1, 7, 1]) == 1", "assert find_first_duplicate([2, 2, 6, 1, 2, 4, 2]) == 2" ]
def check(candidate): # Check some simple cases assert find_first_duplicate(([1, 2, 3, 4, 4, 5]))==4 assert find_first_duplicate([1, 2, 3, 4])==-1 assert find_first_duplicate([1, 1, 2, 3, 3, 2, 2])==1
23
Write a python function to find the maximum sum of elements of list in a list of lists.
maximum_Sum
def maximum_Sum(list1): maxi = -100000 for x in list1: sum = 0 for y in x: sum+= y maxi = max(sum,maxi) return maxi
[ "assert maximum_Sum([[4, 4, 7], [1, 7, 5], [12, 10, 7], [4, 5, 1], [9, 6, 3]]) == 29", "assert maximum_Sum([[2, 5, 4], [5, 5, 4], [12, 5, 2], [2, 5, 4], [1, 5, 8]]) == 19", "assert maximum_Sum([[3, 2, 8], [2, 2, 5], [12, 5, 4], [4, 3, 2], [11, 8, 7]]) == 26" ]
def check(candidate): # Check some simple cases assert maximum_Sum([[1,2,3],[4,5,6],[10,11,12],[7,8,9]]) == 33 assert maximum_Sum([[0,1,1],[1,1,2],[3,2,1]]) == 6 assert maximum_Sum([[0,1,3],[1,2,1],[9,8,2],[0,1,0],[6,4,8]]) == 19
24
Write a function to convert the given binary number to its decimal equivalent.
binary_to_decimal
def binary_to_decimal(binary): binary1 = binary decimal, i, n = 0, 0, 0 while(binary != 0): dec = binary % 10 decimal = decimal + dec * pow(2, i) binary = binary//10 i += 1 return (decimal)
[ "assert binary_to_decimal(1100908) == 140", "assert binary_to_decimal(1101195) == 131", "assert binary_to_decimal(1101071) == 119" ]
def check(candidate): # Check some simple cases assert binary_to_decimal(100) == 4 assert binary_to_decimal(1011) == 11 assert binary_to_decimal(1101101) == 109
25
Write a python function to find the product of non-repeated elements in a given array.
find_Product
def find_Product(arr,n): arr.sort() prod = 1 for i in range(0,n,1): if (arr[i - 1] != arr[i]): prod = prod * arr[i] return prod;
[ "assert find_Product([3, 3, 7, 10, 5], 2) == 3", "assert find_Product([6, 3, 1, 7, 11], 4) == 126", "assert find_Product([5, 3, 6, 4, 3], 1) == 3" ]
def check(candidate): # Check some simple cases assert find_Product([1,1,2,3],4) == 6 assert find_Product([1,2,3,1,1],5) == 6 assert find_Product([1,1,4,5,6],5) == 120
26
Write a function to check if the given tuple list has all k elements.
check_k_elements
def check_k_elements(test_list, K): res = True for tup in test_list: for ele in tup: if ele != K: res = False return (res)
[ "assert check_k_elements([(4, 12), (8, 7, 9, 11)], 12) == False", "assert check_k_elements([(6, 6), (5, 12, 10, 7)], 3) == False", "assert check_k_elements([(11, 9), (4, 8, 8, 6)], 9) == False" ]
def check(candidate): # Check some simple cases assert check_k_elements([(4, 4), (4, 4, 4), (4, 4), (4, 4, 4, 4), (4, )], 4) == True assert check_k_elements([(7, 7, 7), (7, 7)], 7) == True assert check_k_elements([(9, 9), (9, 9, 9, 9)], 7) == False
27
Write a python function to remove all digits from a list of strings.
remove
import re def remove(list): pattern = '[0-9]' list = [re.sub(pattern, '', i) for i in list] return list
[ "assert remove(['g4uv', 'vznwhagh', 'rnujhkx9bkt9']) == ['guv', 'vznwhagh', 'rnujhkxbkt']", "assert remove(['7tvptnh', 'gqlvpbuxjox', 'xy62far']) == ['tvptnh', 'gqlvpbuxjox', 'xyfar']", "assert remove(['e1z3yr7', '8ni7', 'l3y44oji00k']) == ['ezyr', 'ni', 'lyojik']" ]
def check(candidate): # Check some simple cases assert remove(['4words', '3letters', '4digits']) == ['words', 'letters', 'digits'] assert remove(['28Jan','12Jan','11Jan']) == ['Jan','Jan','Jan'] assert remove(['wonder1','wonder2','wonder3']) == ['wonder','wonder','wonder']
28
Write a python function to find binomial co-efficient.
binomial_Coeff
def binomial_Coeff(n,k): if k > n : return 0 if k==0 or k ==n : return 1 return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k)
[ "assert binomial_Coeff(4, 1) == 4", "assert binomial_Coeff(7, 2) == 21", "assert binomial_Coeff(3, 3) == 1" ]
def check(candidate): # Check some simple cases assert binomial_Coeff(5,2) == 10 assert binomial_Coeff(4,3) == 4 assert binomial_Coeff(3,2) == 3
29
Write a python function to find the element occurring odd number of times.
get_Odd_Occurrence
def get_Odd_Occurrence(arr,arr_size): for i in range(0,arr_size): count = 0 for j in range(0,arr_size): if arr[i] == arr[j]: count+=1 if (count % 2 != 0): return arr[i] return -1
[ "assert get_Odd_Occurrence([5, 6, 7, 3, 2, 1, 3, 4, 1, 2, 6, 1, 3], 10) == 5", "assert get_Odd_Occurrence([5, 5, 8, 2, 5, 3, 4, 8, 9, 6, 9, 2, 6], 12) == 5", "assert get_Odd_Occurrence([4, 1, 4, 8, 9, 7, 7, 2, 4, 3, 2, 5, 5], 13) == 4" ]
def check(candidate): # Check some simple cases assert get_Odd_Occurrence([1,2,3,1,2,3,1],7) == 1 assert get_Odd_Occurrence([1,2,3,2,3,1,3],7) == 3 assert get_Odd_Occurrence([2,3,5,4,5,2,4,3,5,2,4,4,2],13) == 5
30
Write a python function to count all the substrings starting and ending with same characters.
count_Substring_With_Equal_Ends
def check_Equality(s): return (ord(s[0]) == ord(s[len(s) - 1])); def count_Substring_With_Equal_Ends(s): result = 0; n = len(s); for i in range(n): for j in range(1,n-i+1): if (check_Equality(s[i:i+j])): result+=1; return result;
[ "assert count_Substring_With_Equal_Ends(\"isk\") == 3", "assert count_Substring_With_Equal_Ends(\"cuxiv\") == 5", "assert count_Substring_With_Equal_Ends(\"fjv\") == 3" ]
def check(candidate): # Check some simple cases assert count_Substring_With_Equal_Ends("abc") == 3 assert count_Substring_With_Equal_Ends("abcda") == 6 assert count_Substring_With_Equal_Ends("ab") == 2
31
Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm.
func
def func(nums, k): import collections d = collections.defaultdict(int) for row in nums: for i in row: d[i] += 1 temp = [] import heapq for key, v in d.items(): if len(temp) < k: temp.append((v, key)) if len(temp) == k: heapq.heapify(temp) else: if v > temp[0][0]: heapq.heappop(temp) heapq.heappush(temp, (v, key)) result = [] while temp: v, key = heapq.heappop(temp) result.append(key) return result
[ "assert func([[1, 6, 4], [5, 6, 8, 6, 8, 8], [4, 1, 6, 2, 10, 11], [3, 4, 5, 10], [6, 9, 9, 5, 10]], 8) == [11, 1, 9, 4, 5, 8, 10, 6]", "assert func([[4, 7, 7], [6, 4, 8, 2, 11, 10], [2, 8, 9, 4, 4, 11], [5, 2, 8, 7], [2, 8, 4, 5, 7]], 10) == [4, 6, 9, 10, 5, 11, 2, 7, 8]", "assert func([[4, 6, 1], [6, 1, 5, 10, 11, 4], [4, 2, 2, 6, 7, 5], [7, 3, 9, 16], [4, 6, 6, 7, 10]], 5) == [5, 10, 7, 4, 6]" ]
def check(candidate): # Check some simple cases assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],3)==[5, 7, 1] assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],1)==[1] assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],5)==[6, 5, 7, 8, 1]
32
Write a python function to find the largest prime factor of a given number.
max_Prime_Factors
import math def max_Prime_Factors (n): maxPrime = -1 while n%2 == 0: maxPrime = 2 n >>= 1 for i in range(3,int(math.sqrt(n))+1,2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime)
[ "assert max_Prime_Factors(2) == 2", "assert max_Prime_Factors(6) == 3", "assert max_Prime_Factors(1) == -1" ]
def check(candidate): # Check some simple cases assert max_Prime_Factors(15) == 5 assert max_Prime_Factors(6) == 3 assert max_Prime_Factors(2) == 2
33
Write a python function to convert a decimal number to binary number.
decimal_To_Binary
def decimal_To_Binary(N): B_Number = 0 cnt = 0 while (N != 0): rem = N % 2 c = pow(10,cnt) B_Number += rem*c N //= 2 cnt += 1 return B_Number
[ "assert decimal_To_Binary(24) == 11000", "assert decimal_To_Binary(15) == 1111", "assert decimal_To_Binary(25) == 11001" ]
def check(candidate): # Check some simple cases assert decimal_To_Binary(10) == 1010 assert decimal_To_Binary(1) == 1 assert decimal_To_Binary(20) == 10100
34
Write a python function to find the missing number in a sorted array.
find_missing
def find_missing(ar,N): l = 0 r = N - 1 while (l <= r): mid = (l + r) / 2 mid= int (mid) if (ar[mid] != mid + 1 and ar[mid - 1] == mid): return (mid + 1) elif (ar[mid] != mid + 1): r = mid - 1 else: l = mid + 1 return (-1)
[ "assert find_missing([6, 2, 4, 3, 8, 7], 7) == 3", "assert find_missing([1, 5, 2, 8, 2, 10], 7) == 2", "assert find_missing([5, 6, 7, 9, 7, 5], 5) == -1" ]
def check(candidate): # Check some simple cases assert find_missing([1,2,3,5],4) == 4 assert find_missing([1,3,4,5],4) == 2 assert find_missing([1,2,3,5,6,7],5) == 4
35
Write a function to find the n-th rectangular number.
find_rect_num
def find_rect_num(n): return n*(n + 1)
[ "assert find_rect_num(10) == 110", "assert find_rect_num(4) == 20", "assert find_rect_num(9) == 90" ]
def check(candidate): # Check some simple cases assert find_rect_num(4) == 20 assert find_rect_num(5) == 30 assert find_rect_num(6) == 42
36
Write a python function to find the nth digit in the proper fraction of two given numbers.
find_Nth_Digit
def find_Nth_Digit(p,q,N) : while (N > 0) : N -= 1; p *= 10; res = p // q; p %= q; return res;
[ "assert find_Nth_Digit(2, 9, 1) == 2", "assert find_Nth_Digit(9, 5, 6) == 0", "assert find_Nth_Digit(2, 9, 9) == 2" ]
def check(candidate): # Check some simple cases assert find_Nth_Digit(1,2,1) == 5 assert find_Nth_Digit(3,5,1) == 6 assert find_Nth_Digit(5,6,5) == 3
37
Write a function to sort a given mixed list of integers and strings.
sort_mixed_list
def sort_mixed_list(mixed_list): int_part = sorted([i for i in mixed_list if type(i) is int]) str_part = sorted([i for i in mixed_list if type(i) is str]) return int_part + str_part
[ "assert sort_mixed_list([15, 'ypxi', 8, 'azuhui', 'wisghah', 11, 'bkuoy', 'znxzrhm', 6]) == [6, 8, 11, 15, 'azuhui', 'bkuoy', 'wisghah', 'ypxi', 'znxzrhm']", "assert sort_mixed_list([14, 'jpm', 9, 'ltcmrsj', 'dped', 13, 'llhcwfwwe', 'hesa', 2]) == [2, 9, 13, 14, 'dped', 'hesa', 'jpm', 'llhcwfwwe', 'ltcmrsj']", "assert sort_mixed_list([20, 'cgfcxhm', 17, 'thcoqj', 'vyeaaxa', 10, 'shfyl', 'abayn', 2]) == [2, 10, 17, 20, 'abayn', 'cgfcxhm', 'shfyl', 'thcoqj', 'vyeaaxa']" ]
def check(candidate): # Check some simple cases assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white'] assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white'] assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']
38
Write a function to find the division of first even and odd number of a given list.
div_even_odd
def div_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el for el in list1 if el%2!=0),-1) return (first_even/first_odd)
[ "assert div_even_odd([4, 5, 5, 11, 7]) == 0.8", "assert div_even_odd([5, 6, 6, 7, 10]) == 1.2", "assert div_even_odd([5, 2, 10, 9, 14]) == 0.4" ]
def check(candidate): # Check some simple cases assert div_even_odd([1,3,5,7,4,1,6,8])==4 assert div_even_odd([1,2,3,4,5,6,7,8,9,10])==2 assert div_even_odd([1,5,7,9,10])==10
39
Write a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different.
rearange_string
import heapq from collections import Counter def rearange_string(S): ctr = Counter(S) heap = [(-value, key) for key, value in ctr.items()] heapq.heapify(heap) if (-heap[0][0]) * 2 > len(S) + 1: return "" ans = [] while len(heap) >= 2: nct1, char1 = heapq.heappop(heap) nct2, char2 = heapq.heappop(heap) ans.extend([char1, char2]) if nct1 + 1: heapq.heappush(heap, (nct1 + 1, char1)) if nct2 + 1: heapq.heappush(heap, (nct2 + 1, char2)) return "".join(ans) + (heap[0][1] if heap else "")
[ "assert rearange_string(\"xirkgnqfm\") == \"fgikmnqrx\"", "assert rearange_string(\"kzavxwto\") == \"akotvwxz\"", "assert rearange_string(\"mfozzpl\") == \"zflmopz\"" ]
def check(candidate): # Check some simple cases assert rearange_string("aab")==('aba') assert rearange_string("aabb")==('abab') assert rearange_string("abccdd")==('cdabcd')
40
Write a function to find frequency of the elements in a given list of lists using collections module.
freq_element
from collections import Counter from itertools import chain def freq_element(nums): result = Counter(chain.from_iterable(nums)) return result
[ "assert freq_element([[15, 24, 29, 45], [81, 87, 101, 107], [29, 25, 79, 91]]) == Counter({29: 2, 15: 1, 24: 1, 45: 1, 81: 1, 87: 1, 101: 1, 107: 1, 25: 1, 79: 1, 91: 1})", "assert freq_element([[12, 17, 32, 45], [84, 88, 101, 115], [32, 33, 83, 86]]) == Counter({32: 2, 12: 1, 17: 1, 45: 1, 84: 1, 88: 1, 101: 1, 115: 1, 33: 1, 83: 1, 86: 1})", "assert freq_element([[17, 25, 28, 41], [85, 87, 96, 115], [30, 25, 82, 93]]) == Counter({25: 2, 17: 1, 28: 1, 41: 1, 85: 1, 87: 1, 96: 1, 115: 1, 30: 1, 82: 1, 93: 1})" ]
def check(candidate): # Check some simple cases assert freq_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]])==({2: 3, 1: 2, 5: 2, 3: 1, 4: 1, 6: 1, 7: 1, 9: 1}) assert freq_element([[1,2,3,4],[5,6,7,8],[9,10,11,12]])==({1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1, 12: 1}) assert freq_element([[15,20,30,40],[80,90,100,110],[30,30,80,90]])==({30: 3, 80: 2, 90: 2, 15: 1, 20: 1, 40: 1, 100: 1, 110: 1})
41
Write a function to filter even numbers using lambda function.
filter_evennumbers
def filter_evennumbers(nums): even_nums = list(filter(lambda x: x%2 == 0, nums)) return even_nums
[ "assert filter_evennumbers([4, 5, 6, 11, 1, 7, 3]) == [4, 6]", "assert filter_evennumbers([4, 4, 6, 9, 6, 5, 8]) == [4, 4, 6, 6, 8]", "assert filter_evennumbers([4, 12, 4, 7, 5, 3, 7]) == [4, 12, 4]" ]
def check(candidate): # Check some simple cases assert filter_evennumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[2, 4, 6, 8, 10] assert filter_evennumbers([10,20,45,67,84,93])==[10,20,84] assert filter_evennumbers([5,7,9,8,6,4,3])==[8,6,4]
42
Write a python function to find the sum of repeated elements in a given array.
find_Sum
def find_Sum(arr,n): return sum([x for x in arr if arr.count(x) > 1])
[ "assert find_Sum([4, 1, 2], 5) == 0", "assert find_Sum([6, 1, 2], 1) == 0", "assert find_Sum([3, 2, 1], 1) == 0" ]
def check(candidate): # Check some simple cases assert find_Sum([1,2,3,1,1,4,5,6],8) == 3 assert find_Sum([1,2,3,1,1],5) == 3 assert find_Sum([1,1,2],3) == 2
43
Write a function to find sequences of lowercase letters joined with an underscore using regex.
text_match
import re def text_match(text): patterns = '^[a-z]+_[a-z]+$' if re.search(patterns, text): return ('Found a match!') else: return ('Not matched!')
[ "assert text_match(\"iI_Chxfj\") == \"Not matched!\"", "assert text_match(\"KKiWzwo\") == \"Not matched!\"", "assert text_match(\"#Ur#rhysVXQy\") == \"Not matched!\"" ]
def check(candidate): # Check some simple cases assert text_match("aab_cbbbc") == 'Found a match!' assert text_match("aab_Abbbc") == 'Not matched!' assert text_match("Aaab_abbbc") == 'Not matched!'
44
Write a function that matches a word at the beginning of a string.
text_match_string
import re def text_match_string(text): patterns = '^\w+' if re.search(patterns, text): return 'Found a match!' else: return 'Not matched!'
[ "assert text_match_string(\"gprw\") == \"Found a match!\"", "assert text_match_string(\"hcfs\") == \"Found a match!\"", "assert text_match_string(\"fnaucgg jpl\") == \"Found a match!\"" ]
def check(candidate): # Check some simple cases assert text_match_string(" python")==('Not matched!') assert text_match_string("python")==('Found a match!') assert text_match_string(" lang")==('Not matched!')
45
Write a function to find the gcd of the given array elements.
get_gcd
def find_gcd(x, y): while(y): x, y = y, x % y return x def get_gcd(l): num1 = l[0] num2 = l[1] gcd = find_gcd(num1, num2) for i in range(2, len(l)): gcd = find_gcd(gcd, l[i]) return gcd
[ "assert get_gcd([7, 1, 11, 3]) == 1", "assert get_gcd([7, 2, 3, 4]) == 1", "assert get_gcd([1, 7, 4, 3]) == 1" ]
def check(candidate): # Check some simple cases assert get_gcd([2, 4, 6, 8, 16]) == 2 assert get_gcd([1, 2, 3]) == 1 assert get_gcd([2, 4, 6, 8]) == 2
46
Write a python function to determine whether all the numbers are different from each other are not.
test_distinct
def test_distinct(data): if len(data) == len(set(data)): return True else: return False;
[ "assert test_distinct([1, 5, 6]) == True", "assert test_distinct([3, 3, 4]) == False", "assert test_distinct([5, 1, 2]) == True" ]
def check(candidate): # Check some simple cases assert test_distinct([1,5,7,9]) == True assert test_distinct([2,4,5,5,7,9]) == False assert test_distinct([1,2,3]) == True
47
Write a python function to find the last digit when factorial of a divides factorial of b.
compute_Last_Digit
def compute_Last_Digit(A,B): variable = 1 if (A == B): return 1 elif ((B - A) >= 5): return 0 else: for i in range(A + 1,B + 1): variable = (variable * (i % 10)) % 10 return variable % 10
[ "assert compute_Last_Digit(1, 7) == 0", "assert compute_Last_Digit(4, 1) == 1", "assert compute_Last_Digit(2, 6) == 0" ]
def check(candidate): # Check some simple cases assert compute_Last_Digit(2,4) == 2 assert compute_Last_Digit(6,8) == 6 assert compute_Last_Digit(1,2) == 2
48
Write a python function to set all odd bits of a given number.
odd_bit_set_number
def odd_bit_set_number(n): count = 0;res = 0;temp = n while temp > 0: if count % 2 == 0: res |= (1 << count) count += 1 temp >>= 1 return (n | res)
[ "assert odd_bit_set_number(32) == 53", "assert odd_bit_set_number(25) == 29", "assert odd_bit_set_number(30) == 31" ]
def check(candidate): # Check some simple cases assert odd_bit_set_number(10) == 15 assert odd_bit_set_number(20) == 21 assert odd_bit_set_number(30) == 31
49
Write a function to extract every first or specified element from a given two-dimensional list.
specified_element
def specified_element(nums, N): result = [i[N] for i in nums] return result
[ "assert specified_element([[3, 7, 8, 1], [3, 10, 5, 5], [11, 4, 11, 8]], 3) == [1, 5, 8]", "assert specified_element([[5, 2, 5, 5], [8, 8, 11, 7], [7, 1, 10, 3]], 2) == [5, 11, 10]", "assert specified_element([[3, 6, 4, 3], [7, 10, 5, 1], [11, 2, 8, 4]], 3) == [3, 1, 4]" ]
def check(candidate): # Check some simple cases assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],0)==[1, 4, 7] assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],2)==[3, 6, 9] assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],1)==[2,5,1]
50
Write a function to find the list with minimum length using lambda function.
min_length_list
def min_length_list(input_list): min_length = min(len(x) for x in input_list ) min_list = min(input_list, key = lambda i: len(i)) return(min_length, min_list)
[ "assert min_length_list([[6, 2, 4], [10, 8, 6, 11], [11, 8, 8], [5, 2]]) == (2, [5, 2])", "assert min_length_list([[7, 2, 5], [9, 2, 6, 9], [7, 8, 15], [3, 3]]) == (2, [3, 3])", "assert min_length_list([[2, 4, 2], [6, 4, 8, 4], [11, 6, 13], [6, 4]]) == (2, [6, 4])" ]
def check(candidate): # Check some simple cases assert min_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(1, [0]) assert min_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(1,[1]) assert min_length_list([[3,4,5],[6,7,8,9],[10,11,12],[1,2]])==(2,[1,2])
51
Write a function to print check if the triangle is equilateral or not.
check_equilateral
def check_equilateral(x,y,z): if x == y == z: return True else: return False
[ "assert check_equilateral(6, 2, 4) == False", "assert check_equilateral(1, 3, 3) == False", "assert check_equilateral(5, 1, 1) == False" ]
def check(candidate): # Check some simple cases assert check_equilateral(6,8,12)==False assert check_equilateral(6,6,12)==False assert check_equilateral(6,6,6)==True
52
Write a function to caluclate area of a parallelogram.
parallelogram_area
def parallelogram_area(b,h): area=b*h return area
[ "assert parallelogram_area(13, 8) == 104", "assert parallelogram_area(10, 4) == 40", "assert parallelogram_area(5, 4) == 20" ]
def check(candidate): # Check some simple cases assert parallelogram_area(10,20)==200 assert parallelogram_area(15,20)==300 assert parallelogram_area(8,9)==72
53
Write a python function to check whether the first and last characters of a given string are equal or not.
check_Equality
def check_Equality(str): if (str[0] == str[-1]): return ("Equal") else: return ("Not Equal")
[ "assert check_Equality(\"xqvmtrqjv\") == \"Not Equal\"", "assert check_Equality(\"rufzemf\") == \"Not Equal\"", "assert check_Equality(\"hqgu\") == \"Not Equal\"" ]
def check(candidate): # Check some simple cases assert check_Equality("abcda") == "Equal" assert check_Equality("ab") == "Not Equal" assert check_Equality("mad") == "Not Equal"
54
Write a function to sort the given array by using counting sort.
counting_sort
def counting_sort(my_list): max_value = 0 for i in range(len(my_list)): if my_list[i] > max_value: max_value = my_list[i] buckets = [0] * (max_value + 1) for i in my_list: buckets[i] += 1 i = 0 for j in range(max_value + 1): for a in range(buckets[j]): my_list[i] = j i += 1 return my_list
[ "assert counting_sort([3, 8, 9, 2, 2, 1]) == [1, 2, 2, 3, 8, 9]", "assert counting_sort([6, 2, 10, 5, 4, 3]) == [2, 3, 4, 5, 6, 10]", "assert counting_sort([3, 7, 14, 2, 5, 4]) == [2, 3, 4, 5, 7, 14]" ]
def check(candidate): # Check some simple cases assert counting_sort([1,23,4,5,6,7,8]) == [1, 4, 5, 6, 7, 8, 23] assert counting_sort([12, 9, 28, 33, 69, 45]) == [9, 12, 28, 33, 45, 69] assert counting_sort([8, 4, 14, 3, 2, 1]) == [1, 2, 3, 4, 8, 14]
55
Write a function to find t-nth term of geometric series.
tn_gp
import math def tn_gp(a,n,r): tn = a * (math.pow(r, n - 1)) return tn
[ "assert tn_gp(6, 9, 4) == 393216.0", "assert tn_gp(3, 4, 8) == 1536.0", "assert tn_gp(7, 4, 6) == 1512.0" ]
def check(candidate): # Check some simple cases assert tn_gp(1,5,2)==16 assert tn_gp(1,5,4)==256 assert tn_gp(2,6,3)==486
56
Write a python function to check if a given number is one less than twice its reverse.
check
def rev(num): rev_num = 0 while (num > 0): rev_num = (rev_num * 10 + num % 10) num = num // 10 return rev_num def check(n): return (2 * rev(n) == n + 1)
[ "assert check(73) == True", "assert check(71) == False", "assert check(70) == False" ]
def check(candidate): # Check some simple cases assert check(70) == False assert check(23) == False assert check(73) == True
57
Write a python function to find the largest number that can be formed with the given digits.
find_Max_Num
def find_Max_Num(arr,n) : arr.sort(reverse = True) num = arr[0] for i in range(1,n) : num = num * 10 + arr[i] return num
[ "assert find_Max_Num([2, 5, 5, 7], 3) == 755", "assert find_Max_Num([2, 7, 8, 4], 4) == 8742", "assert find_Max_Num([3, 6, 6, 5], 3) == 665" ]
def check(candidate): # Check some simple cases assert find_Max_Num([1,2,3],3) == 321 assert find_Max_Num([4,5,6,1],4) == 6541 assert find_Max_Num([1,2,3,9],4) == 9321
58
Write a python function to check whether the given two integers have opposite sign or not.
opposite_Signs
def opposite_Signs(x,y): return ((x ^ y) < 0);
[ "assert opposite_Signs(-6, -13) == False", "assert opposite_Signs(-6, -7) == False", "assert opposite_Signs(-13, -7) == False" ]
def check(candidate): # Check some simple cases assert opposite_Signs(1,-2) == True assert opposite_Signs(3,2) == False assert opposite_Signs(-10,-10) == False
59
Write a function to find the nth octagonal number.
is_octagonal
def is_octagonal(n): return 3 * n * n - 2 * n
[ "assert is_octagonal(17) == 833", "assert is_octagonal(19) == 1045", "assert is_octagonal(15) == 645" ]
def check(candidate): # Check some simple cases assert is_octagonal(5) == 65 assert is_octagonal(10) == 280 assert is_octagonal(15) == 645
60
Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array.
max_len_sub
def max_len_sub( arr, n): mls=[] max = 0 for i in range(n): mls.append(1) for i in range(n): for j in range(i): if (abs(arr[i] - arr[j]) <= 1 and mls[i] < mls[j] + 1): mls[i] = mls[j] + 1 for i in range(n): if (max < mls[i]): max = mls[i] return max
[ "assert max_len_sub([6, 8, 11, 15, 22], 4) == 1", "assert max_len_sub([8, 14, 18, 13, 14], 3) == 1", "assert max_len_sub([4, 13, 17, 15, 21], 2) == 1" ]
def check(candidate): # Check some simple cases assert max_len_sub([2, 5, 6, 3, 7, 6, 5, 8], 8) == 5 assert max_len_sub([-2, -1, 5, -1, 4, 0, 3], 7) == 4 assert max_len_sub([9, 11, 13, 15, 18], 5) == 1
61
Write a python function to count number of substrings with the sum of digits equal to their length.
count_Substrings
from collections import defaultdict def count_Substrings(s,n): count,sum = 0,0 mp = defaultdict(lambda : 0) mp[0] += 1 for i in range(n): sum += ord(s[i]) - ord('0') count += mp[sum - (i + 1)] mp[sum - (i + 1)] += 1 return count
[ "assert count_Substrings('911567263', 6) == 3", "assert count_Substrings('884542315265', 11) == 1", "assert count_Substrings('8162661', 6) == 1" ]
def check(candidate): # Check some simple cases assert count_Substrings('112112',6) == 6 assert count_Substrings('111',3) == 6 assert count_Substrings('1101112',7) == 12
62
Write a python function to find smallest number in a list.
smallest_num
def smallest_num(xs): return min(xs)
[ "assert smallest_num([50, 48, 51, 63]) == 48", "assert smallest_num([44, 49, 53, 60]) == 44", "assert smallest_num([47, 46, 53, 59]) == 46" ]
def check(candidate): # Check some simple cases assert smallest_num([10, 20, 1, 45, 99]) == 1 assert smallest_num([1, 2, 3]) == 1 assert smallest_num([45, 46, 50, 60]) == 45
63
Write a function to find the maximum difference between available pairs in the given tuple list.
max_difference
def max_difference(test_list): temp = [abs(b - a) for a, b in test_list] res = max(temp) return (res)
[ "assert max_difference([(13, 35), (21, 26), (18, 19), (46, 25)]) == 22", "assert max_difference([(13, 38), (26, 26), (10, 26), (44, 26)]) == 25", "assert max_difference([(11, 33), (22, 27), (14, 21), (42, 23)]) == 22" ]
def check(candidate): # Check some simple cases assert max_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 7 assert max_difference([(4, 6), (2, 17), (9, 13), (11, 12)]) == 15 assert max_difference([(12, 35), (21, 27), (13, 23), (41, 22)]) == 23
64
Write a function to sort a list of tuples using lambda.
subject_marks
def subject_marks(subjectmarks): #subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]) subjectmarks.sort(key = lambda x: x[1]) return subjectmarks
[ "assert subject_marks([('ZPoZuFiw', 97), ('UoDABQSvOdkCuV', 95), ('uFslvKYhFn', 47)]) == [('uFslvKYhFn', 47), ('UoDABQSvOdkCuV', 95), ('ZPoZuFiw', 97)]", "assert subject_marks([('sxlGrTcJ', 96), ('FIqmyf', 94), ('Vhvfhmiu', 42)]) == [('Vhvfhmiu', 42), ('FIqmyf', 94), ('sxlGrTcJ', 96)]", "assert subject_marks([('oolJEgaEj', 94), ('iMfMjBPS', 92), ('WZnD', 44)]) == [('WZnD', 44), ('iMfMjBPS', 92), ('oolJEgaEj', 94)]" ]
def check(candidate): # Check some simple cases assert subject_marks([('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])==[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)] assert subject_marks([('Telugu',49),('Hindhi',54),('Social',33)])==([('Social',33),('Telugu',49),('Hindhi',54)]) assert subject_marks([('Physics',96),('Chemistry',97),('Biology',45)])==([('Biology',45),('Physics',96),('Chemistry',97)])
65
Write a function of recursion list sum.
recursive_list_sum
def recursive_list_sum(data_list): total = 0 for element in data_list: if type(element) == type([]): total = total + recursive_list_sum(element) else: total = total + element return total
[ "assert recursive_list_sum([12, 21, [33, 41], [48, 63]]) == 218", "assert recursive_list_sum([12, 25, [32, 41], [45, 61]]) == 216", "assert recursive_list_sum([13, 20, [35, 35], [49, 61]]) == 213" ]
def check(candidate): # Check some simple cases assert recursive_list_sum(([1, 2, [3,4],[5,6]]))==21 assert recursive_list_sum(([7, 10, [15,14],[19,41]]))==106 assert recursive_list_sum(([10, 20, [30,40],[50,60]]))==210
66
Write a python function to count positive numbers in a list.
pos_count
def pos_count(list): pos_count= 0 for num in list: if num >= 0: pos_count += 1 return pos_count
[ "assert pos_count([2, 1, 3, 3]) == 4", "assert pos_count([5, 7, 8, 7]) == 4", "assert pos_count([3, 6, 2, 1]) == 4" ]
def check(candidate): # Check some simple cases assert pos_count([1,-2,3,-4]) == 2 assert pos_count([3,4,5,-1]) == 3 assert pos_count([1,2,3,4]) == 4
67
Write a function to find the number of ways to partition a set of bell numbers.
bell_number
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 bell_number(54) == 19317287589145618265728950069285503257349832850302011", "assert bell_number(53) == 1052928518014714166107781298021583534928402714242132", "assert bell_number(60) == 976939307467007552986994066961675455550246347757474482558637" ]
def check(candidate): # Check some simple cases assert bell_number(2)==2 assert bell_number(10)==115975 assert bell_number(56)==6775685320645824322581483068371419745979053216268760300
68
Write a python function to check whether the given array is monotonic or not.
is_Monotonic
def is_Monotonic(A): return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or all(A[i] >= A[i + 1] for i in range(len(A) - 1)))
[ "assert is_Monotonic([5, 5, 3]) == True", "assert is_Monotonic([6, 5, 1]) == True", "assert is_Monotonic([2, 5, 3]) == False" ]
def check(candidate): # Check some simple cases assert is_Monotonic([6, 5, 4, 4]) == True assert is_Monotonic([1, 2, 2, 3]) == True assert is_Monotonic([1, 3, 2]) == False
69
Write a function to check whether a list contains the given sublist or not.
is_sublist
def is_sublist(l, s): sub_set = False if s == []: sub_set = True elif s == l: sub_set = True elif len(s) > len(l): sub_set = False else: for i in range(len(l)): if l[i] == s[0]: n = 1 while (n < len(s)) and (l[i+n] == s[n]): n += 1 if n == len(s): sub_set = True return sub_set
[ "assert is_sublist([7, 8, 3, 3, 2], [4, 8]) == False", "assert is_sublist([6, 5, 4, 10, 3], [4, 8]) == False", "assert is_sublist([5, 3, 8, 2, 12], [1, 6]) == False" ]
def check(candidate): # Check some simple cases assert is_sublist([2,4,3,5,7],[3,7])==False assert is_sublist([2,4,3,5,7],[4,3])==True assert is_sublist([2,4,3,5,7],[1,6])==False
70
Write a function to find whether all the given tuples have equal length or not.
get_equal
def find_equal_tuple(Input, k): flag = 1 for tuple in Input: if len(tuple) != k: flag = 0 break return flag def get_equal(Input, k): if find_equal_tuple(Input, k) == 1: return ("All tuples have same length") else: return ("All tuples do not have same length")
[ "assert get_equal([(1, 3), (1, 5)], 2) == \"All tuples have same length\"", "assert get_equal([(3, 6), (2, 2)], 4) == \"All tuples do not have same length\"", "assert get_equal([(6, 4), (6, 4)], 7) == \"All tuples do not have same length\"" ]
def check(candidate): # Check some simple cases assert get_equal([(11, 22, 33), (44, 55, 66)], 3) == 'All tuples have same length' assert get_equal([(1, 2, 3), (4, 5, 6, 7)], 3) == 'All tuples do not have same length' assert get_equal([(1, 2), (3, 4)], 2) == 'All tuples have same length'
71
Write a function to sort a list of elements using comb sort.
comb_sort
def comb_sort(nums): shrink_fact = 1.3 gaps = len(nums) swapped = True i = 0 while gaps > 1 or swapped: gaps = int(float(gaps) / shrink_fact) swapped = False i = 0 while gaps + i < len(nums): if nums[i] > nums[i+gaps]: nums[i], nums[i+gaps] = nums[i+gaps], nums[i] swapped = True i += 1 return nums
[ "assert comb_sort([102, 13, 17, 45]) == [13, 17, 45, 102]", "assert comb_sort([94, 12, 16, 46]) == [12, 16, 46, 94]", "assert comb_sort([97, 15, 12, 49]) == [12, 15, 49, 97]" ]
def check(candidate): # Check some simple cases assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79] assert comb_sort([41, 32, 15, 19, 22]) == [15, 19, 22, 32, 41] assert comb_sort([99, 15, 13, 47]) == [13, 15, 47, 99]
72
Write a python function to check whether the given number can be represented as difference of two squares or not.
dif_Square
def dif_Square(n): if (n % 4 != 2): return True return False
[ "assert dif_Square(16) == True", "assert dif_Square(12) == True", "assert dif_Square(11) == True" ]
def check(candidate): # Check some simple cases assert dif_Square(5) == True assert dif_Square(10) == False assert dif_Square(15) == True
73
Write a function to split the given string with multiple delimiters by using regex.
multiple_split
import re def multiple_split(text): return (re.split('; |, |\*|\n',text))
[ "assert multiple_split(\"xfr?%DzQP!nuF@|^^kGSJOaIxFi_HvG&rQbo=c*CRjpeWAaqO$>IEM:~CzFQARYJoUgDq/$\") == ['xfr?%DzQP!nuF@|^^kGSJOaIxFi_HvG&rQbo=c', 'CRjpeWAaqO$>IEM:~CzFQARYJoUgDq/$']", "assert multiple_split(\"GxoUGFL^i%M<%&.lq>=S+%ydjeoM@WQ:@$W/ibiJQV?zPP#Grut%o?xEvdAXsz TOnG<~O:-\") == ['GxoUGFL^i%M<%&.lq>=S+%ydjeoM@WQ:@$W/ibiJQV?zPP#Grut%o?xEvdAXsz TOnG<~O:-']", "assert multiple_split(\"-_-!uRMhbuBcI+GS_s#zxSs.Z^/+_OV+ITcGrWlw%v~H#BuiiY&ksDD=Pg_QKYzcrvic:a^OXs\") == ['-_-!uRMhbuBcI+GS_s#zxSs.Z^/+_OV+ITcGrWlw%v~H#BuiiY&ksDD=Pg_QKYzcrvic:a^OXs']" ]
def check(candidate): # Check some simple cases assert multiple_split('Forces of the \ndarkness*are coming into the play.') == ['Forces of the ', 'darkness', 'are coming into the play.'] assert multiple_split('Mi Box runs on the \n Latest android*which has google assistance and chromecast.') == ['Mi Box runs on the ', ' Latest android', 'which has google assistance and chromecast.'] assert multiple_split('Certain services\nare subjected to change*over the seperate subscriptions.') == ['Certain services', 'are subjected to change', 'over the seperate subscriptions.']
74
Write a function to check whether it follows the sequence given in the patterns array.
is_samepatterns
def is_samepatterns(colors, patterns): if len(colors) != len(patterns): return False sdict = {} pset = set() sset = set() for i in range(len(patterns)): pset.add(patterns[i]) sset.add(colors[i]) if patterns[i] not in sdict.keys(): sdict[patterns[i]] = [] keys = sdict[patterns[i]] keys.append(colors[i]) sdict[patterns[i]] = keys if len(pset) != len(sset): return False for values in sdict.values(): for i in range(len(values) - 1): if values[i] != values[i+1]: return False return True
[ "assert is_samepatterns(['jjrfwr', 'mkfqm', 'cjjezopwhmt'], ['o', 'h']) == False", "assert is_samepatterns(['ytkiiw', 'iobofumi', 'mfqubcqjit'], ['i', 'n']) == False", "assert is_samepatterns(['wsilq', 'oqojqqioh', 'njdxtqsw'], ['g', 'y']) == False" ]
def check(candidate): # Check some simple cases assert is_samepatterns(["red","green","green"], ["a", "b", "b"])==True assert is_samepatterns(["red","green","greenn"], ["a","b","b"])==False assert is_samepatterns(["red","green","greenn"], ["a","b"])==False
75
Write a function to find tuples which have all elements divisible by k from the given list of tuples.
find_tuples
def find_tuples(test_list, K): res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)] return (str(res))
[ "assert find_tuples([(6, 14, 12), (3, 15, 1), (18, 13, 16)], 9) == []", "assert find_tuples([(9, 7, 16), (6, 20, 9), (15, 17, 22)], 8) == []", "assert find_tuples([(6, 10, 16), (11, 18, 1), (15, 13, 22)], 4) == []" ]
def check(candidate): # Check some simple cases assert find_tuples([(6, 24, 12), (7, 9, 6), (12, 18, 21)], 6) == '[(6, 24, 12)]' assert find_tuples([(5, 25, 30), (4, 2, 3), (7, 8, 9)], 5) == '[(5, 25, 30)]' assert find_tuples([(7, 9, 16), (8, 16, 4), (19, 17, 18)], 4) == '[(8, 16, 4)]'
76
Write a python function to count the number of squares in a rectangle.
count_Squares
def count_Squares(m,n): if(n < m): temp = m m = n n = temp return ((m * (m + 1) * (2 * m + 1) / 6 + (n - m) * m * (m + 1) / 2))
[ "assert count_Squares(3, 5) == 26.0", "assert count_Squares(5, 2) == 14.0", "assert count_Squares(3, 2) == 8.0" ]
def check(candidate): # Check some simple cases assert count_Squares(4,3) == 20 assert count_Squares(2,2) == 5 assert count_Squares(1,1) == 1
77
Write a python function to find the difference between sum of even and odd digits.
is_Diff
def is_Diff(n): return (n % 11 == 0)
[ "assert is_Diff (255) == False", "assert is_Diff (446) == False", "assert is_Diff (976) == False" ]
def check(candidate): # Check some simple cases assert is_Diff (12345) == False assert is_Diff(1212112) == True assert is_Diff(1212) == False
78
Write a python function to find number of integers with odd number of set bits.
count_With_Odd_SetBits
def count_With_Odd_SetBits(n): if (n % 2 != 0): return (n + 1) / 2 count = bin(n).count('1') ans = n / 2 if (count % 2 != 0): ans += 1 return ans
[ "assert count_With_Odd_SetBits(18) == 9.0", "assert count_With_Odd_SetBits(16) == 9.0", "assert count_With_Odd_SetBits(19) == 10.0" ]
def check(candidate): # Check some simple cases assert count_With_Odd_SetBits(5) == 3 assert count_With_Odd_SetBits(10) == 5 assert count_With_Odd_SetBits(15) == 8
79
Write a python function to check whether the length of the word is odd or not.
word_len
def word_len(s): s = s.split(' ') for word in s: if len(word)%2!=0: return True else: return False
[ "assert word_len(\"mgzlwbhdmt\") == False", "assert word_len(\"daitrhkcpu\") == False", "assert word_len(\"opnbeymrepb\") == True" ]
def check(candidate): # Check some simple cases assert word_len("Hadoop") == False assert word_len("great") == True assert word_len("structure") == True
80
Write a function to find the nth tetrahedral number.
tetrahedral_number
def tetrahedral_number(n): return (n * (n + 1) * (n + 2)) / 6
[ "assert tetrahedral_number(2) == 4.0", "assert tetrahedral_number(3) == 10.0", "assert tetrahedral_number(7) == 84.0" ]
def check(candidate): # Check some simple cases assert tetrahedral_number(5) == 35.0 assert tetrahedral_number(6) == 56.0 assert tetrahedral_number(7) == 84.0
81
Write a function to zip the two given tuples.
zip_tuples
def zip_tuples(test_tup1, test_tup2): res = [] for i, j in enumerate(test_tup1): res.append((j, test_tup2[i % len(test_tup2)])) return (res)
[ "assert zip_tuples((8, 7, 4, 9, 13, 8), (7, 10, 8)) == [(8, 7), (7, 10), (4, 8), (9, 7), (13, 10), (8, 8)]", "assert zip_tuples((10, 11, 8, 5, 7, 12), (8, 3, 8)) == [(10, 8), (11, 3), (8, 8), (5, 8), (7, 3), (12, 8)]", "assert zip_tuples((13, 12, 8, 2, 13, 14), (2, 12, 8)) == [(13, 2), (12, 12), (8, 8), (2, 2), (13, 12), (14, 8)]" ]
def check(candidate): # Check some simple cases assert zip_tuples((7, 8, 4, 5, 9, 10),(1, 5, 6) ) == [(7, 1), (8, 5), (4, 6), (5, 1), (9, 5), (10, 6)] assert zip_tuples((8, 9, 5, 6, 10, 11),(2, 6, 7) ) == [(8, 2), (9, 6), (5, 7), (6, 2), (10, 6), (11, 7)] assert zip_tuples((9, 10, 6, 7, 11, 12),(3, 7, 8) ) == [(9, 3), (10, 7), (6, 8), (7, 3), (11, 7), (12, 8)]
82
Write a function to find the volume of a sphere.
volume_sphere
import math def volume_sphere(r): volume=(4/3)*math.pi*r*r*r return volume
[ "assert volume_sphere(17) == 20579.526276115535", "assert volume_sphere(23) == 50965.01042163601", "assert volume_sphere(22) == 44602.23810056549" ]
def check(candidate): # Check some simple cases assert volume_sphere(10)==4188.790204786391 assert volume_sphere(25)==65449.84694978735 assert volume_sphere(20)==33510.32163829113
83
Write a python function to find the character made by adding all the characters of the given string.
get_Char
def get_Char(strr): summ = 0 for i in range(len(strr)): summ += (ord(strr[i]) - ord('a') + 1) if (summ % 26 == 0): return ord('z') else: summ = summ % 26 return chr(ord('a') + summ - 1)
[ "assert get_Char(\"wej\") == \"l\"", "assert get_Char(\"ubjg\") == \"n\"", "assert get_Char(\"jfa\") == \"q\"" ]
def check(candidate): # Check some simple cases assert get_Char("abc") == "f" assert get_Char("gfg") == "t" assert get_Char("ab") == "c"
84
Write a function to find the n-th number in newman conway sequence.
sequence
def sequence(n): if n == 1 or n == 2: return 1 else: return sequence(sequence(n-1)) + sequence(n-sequence(n-1))
[ "assert sequence(7) == 4", "assert sequence(1) == 1", "assert sequence(7) == 4" ]
def check(candidate): # Check some simple cases assert sequence(10) == 6 assert sequence(2) == 1 assert sequence(3) == 2
85
Write a function to find the surface area of a sphere.
surfacearea_sphere
import math def surfacearea_sphere(r): surfacearea=4*math.pi*r*r return surfacearea
[ "assert surfacearea_sphere(17) == 3631.6811075498013", "assert surfacearea_sphere(25) == 7853.981633974483", "assert surfacearea_sphere(23) == 6647.610054996002" ]
def check(candidate): # Check some simple cases assert surfacearea_sphere(10)==1256.6370614359173 assert surfacearea_sphere(15)==2827.4333882308138 assert surfacearea_sphere(20)==5026.548245743669
86
Write a function to find nth centered hexagonal number.
centered_hexagonal_number
def centered_hexagonal_number(n): return 3 * n * (n - 1) + 1
[ "assert centered_hexagonal_number(9) == 217", "assert centered_hexagonal_number(4) == 37", "assert centered_hexagonal_number(13) == 469" ]
def check(candidate): # Check some simple cases assert centered_hexagonal_number(10) == 271 assert centered_hexagonal_number(2) == 7 assert centered_hexagonal_number(9) == 217
87
Write a function to merge three dictionaries into a single expression.
merge_dictionaries_three
import collections as ct def merge_dictionaries_three(dict1,dict2, dict3): merged_dict = dict(ct.ChainMap({},dict1,dict2,dict3)) return merged_dict
[ "assert merge_dictionaries_three({'J': 'mnH', 'G': 'OOWpwTvT', 'P': 'EHGFM'}, {'J': 'agd', 'G': 'sICq'}, {'L': 'fmFsoW', 'A': 'wufCatMW'}) == {'L': 'fmFsoW', 'A': 'wufCatMW', 'J': 'mnH', 'G': 'OOWpwTvT', 'P': 'EHGFM'}", "assert merge_dictionaries_three({'Q': 'VRNKcdN', 'K': 'dqiALaIuu', 'F': 'iRzBJF'}, {'K': 'bcpoixekdibm', 'B': 'yOCuFPd'}, {'D': 'gyPNjiiA', 'J': 'rglWbqHF'}) == {'D': 'gyPNjiiA', 'J': 'rglWbqHF', 'K': 'dqiALaIuu', 'B': 'yOCuFPd', 'Q': 'VRNKcdN', 'F': 'iRzBJF'}", "assert merge_dictionaries_three({'S': 'jeOBr', 'J': 'sYPG', 'C': 'zjw'}, {'D': 'whj', 'R': 'jHLJyErfh'}, {'U': 'NOAdZJQ', 'Q': 'rjnjJmEcY'}) == {'U': 'NOAdZJQ', 'Q': 'rjnjJmEcY', 'D': 'whj', 'R': 'jHLJyErfh', 'S': 'jeOBr', 'J': 'sYPG', 'C': 'zjw'}" ]
def check(candidate): # Check some simple cases assert merge_dictionaries_three({ "R": "Red", "B": "Black", "P": "Pink" }, { "G": "Green", "W": "White" },{ "O": "Orange", "W": "White", "B": "Black" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White', 'O': 'Orange'} assert merge_dictionaries_three({ "R": "Red", "B": "Black", "P": "Pink" }, { "G": "Green", "W": "White" },{"L":"lavender","B":"Blue"})=={'W': 'White', 'P': 'Pink', 'B': 'Black', 'R': 'Red', 'G': 'Green', 'L': 'lavender'} assert merge_dictionaries_three({ "R": "Red", "B": "Black", "P": "Pink" },{"L":"lavender","B":"Blue"},{ "G": "Green", "W": "White" })=={'B': 'Black', 'P': 'Pink', 'R': 'Red', 'G': 'Green', 'L': 'lavender', 'W': 'White'}
88
Write a function to get the frequency of the elements in a list.
freq_count
import collections def freq_count(list1): freq_count= collections.Counter(list1) return freq_count
[ "assert freq_count([5, 1, 6, 3, 14, 6, 9, 2, 10, 2, 4, 8]) == Counter({6: 2, 2: 2, 5: 1, 1: 1, 3: 1, 14: 1, 9: 1, 10: 1, 4: 1, 8: 1})", "assert freq_count([8, 10, 11, 2, 5, 6, 6, 8, 2, 3, 14, 8]) == Counter({8: 3, 2: 2, 6: 2, 10: 1, 11: 1, 5: 1, 3: 1, 14: 1})", "assert freq_count([3, 2, 5, 9, 10, 5, 6, 8, 10, 12, 8, 9]) == Counter({5: 2, 9: 2, 10: 2, 8: 2, 3: 1, 2: 1, 6: 1, 12: 1})" ]
def check(candidate): # Check some simple cases assert freq_count([10,10,10,10,20,20,20,20,40,40,50,50,30])==({10: 4, 20: 4, 40: 2, 50: 2, 30: 1}) assert freq_count([1,2,3,4,3,2,4,1,3,1,4])==({1:3, 2:2,3:3,4:3}) assert freq_count([5,6,7,4,9,10,4,5,6,7,9,5])==({10:1,5:3,6:2,7:2,4:2,9:2})
89
Write a function to find the closest smaller number than n.
closest_num
def closest_num(N): return (N - 1)
[ "assert closest_num(13) == 12", "assert closest_num(12) == 11", "assert closest_num(7) == 6" ]
def check(candidate): # Check some simple cases assert closest_num(11) == 10 assert closest_num(7) == 6 assert closest_num(12) == 11
90
Write a python function to find the length of the longest word.
len_log
def len_log(list1): max=len(list1[0]) for i in list1: if len(i)>max: max=len(i) return max
[ "assert len_log(['zevwz', 'hrzjctbvz', 'fvopjo']) == 9", "assert len_log(['maijv', 'vsiz', 'kdeopbly']) == 8", "assert len_log(['zxznanfzs', 'vzw', 'wbofibaxl']) == 9" ]
def check(candidate): # Check some simple cases assert len_log(["python","PHP","bigdata"]) == 7 assert len_log(["a","ab","abc"]) == 3 assert len_log(["small","big","tall"]) == 5
91
Write a function to check if a substring is present in a given list of string values.
find_substring
def find_substring(str1, sub_str): if any(sub_str in s for s in str1): return True return False
[ "assert find_substring(['ahcftfen', 'shpfzfjg', 'nsivo', 'cpdqdxbs', 'ncfiwci'], 'yegphwint') == False", "assert find_substring(['jxcdwmh', 'ubshy', 'xrtqlp', 'ndognd', 'ofzks'], 'stc') == False", "assert find_substring(['lcy', 'tqs', 'nxutcbmk', 'leva', 'ufhwrt'], 'htx') == False" ]
def check(candidate): # Check some simple cases assert find_substring(["red", "black", "white", "green", "orange"],"ack")==True assert find_substring(["red", "black", "white", "green", "orange"],"abc")==False assert find_substring(["red", "black", "white", "green", "orange"],"ange")==True
92
Write a function to check whether the given number is undulating or not.
is_undulating
def is_undulating(n): if (len(n) <= 2): return False for i in range(2, len(n)): if (n[i - 2] != n[i]): return False return True
[ "assert is_undulating(\"775796\") == False", "assert is_undulating(\"76487\") == False", "assert is_undulating(\"283829\") == False" ]
def check(candidate): # Check some simple cases assert is_undulating("1212121") == True assert is_undulating("1991") == False assert is_undulating("121") == True
93
Write a function to calculate the value of 'a' to the power 'b'.
power
def power(a,b): if b==0: return 1 elif a==0: return 0 elif b==1: return a else: return a*power(a,b-1)
[ "assert power(5, 9) == 1953125", "assert power(5, 4) == 625", "assert power(3, 8) == 6561" ]
def check(candidate): # Check some simple cases assert power(3,4) == 81 assert power(2,3) == 8 assert power(5,5) == 3125
94
Write a function to extract the index minimum value record from the given tuples.
index_minimum
from operator import itemgetter def index_minimum(test_list): res = min(test_list, key = itemgetter(1))[0] return (res)
[ "assert index_minimum([('eJSjJ', 343), ('dKDyWoOg', 141), ('OPjtFeav', 91)]) == \"OPjtFeav\"", "assert index_minimum([('TKmnDAqe', 343), ('gwAGnMhLNk', 140), ('rxJ', 91)]) == \"rxJ\"", "assert index_minimum([('mWNDy', 349), ('FuMmCcfJry', 143), ('eQHcTWaYKQiO', 98)]) == \"eQHcTWaYKQiO\"" ]
def check(candidate): # Check some simple cases assert index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]) == 'Varsha' assert index_minimum([('Yash', 185), ('Dawood', 125), ('Sanya', 175)]) == 'Dawood' assert index_minimum([('Sai', 345), ('Salman', 145), ('Ayesha', 96)]) == 'Ayesha'
95
Write a python function to find the minimum length of sublist.
Find_Min_Length
def Find_Min_Length(lst): minLength = min(len(x) for x in lst ) return minLength
[ "assert Find_Min_Length([[1, 6, 4], [4, 3, 2, 4]]) == 3", "assert Find_Min_Length([[4, 4, 3], [6, 5, 2, 4]]) == 3", "assert Find_Min_Length([[7, 5, 6], [1, 1, 8, 8]]) == 3" ]
def check(candidate): # Check some simple cases assert Find_Min_Length([[1],[1,2]]) == 1 assert Find_Min_Length([[1,2],[1,2,3],[1,2,3,4]]) == 2 assert Find_Min_Length([[3,3,3],[4,4,4,4]]) == 3
96
Write a python function to find the number of divisors of a given integer.
divisor
def divisor(n): for i in range(n): x = len([i for i in range(1,n+1) if not n % i]) return x
[ "assert divisor(11) == 2", "assert divisor(4) == 3", "assert divisor(8) == 4" ]
def check(candidate): # Check some simple cases assert divisor(15) == 4 assert divisor(12) == 6 assert divisor(9) == 3
97
Write a function to find frequency count of list of lists.
frequency_lists
def frequency_lists(list1): list1 = [item for sublist in list1 for item in sublist] dic_data = {} for num in list1: if num in dic_data.keys(): dic_data[num] += 1 else: key = num value = 1 dic_data[key] = value return dic_data
[ "assert frequency_lists([[23, 33, 40, 21], [21, 14, 16, 9], [15, 15, 27, 37]]) == {23: 1, 33: 1, 40: 1, 21: 2, 14: 1, 16: 1, 9: 1, 15: 2, 27: 1, 37: 1}", "assert frequency_lists([[25, 33, 43, 18], [13, 17, 10, 9], [7, 18, 34, 36]]) == {25: 1, 33: 1, 43: 1, 18: 2, 13: 1, 17: 1, 10: 1, 9: 1, 7: 1, 34: 1, 36: 1}", "assert frequency_lists([[19, 29, 38, 15], [15, 15, 14, 15], [7, 20, 28, 44]]) == {19: 1, 29: 1, 38: 1, 15: 4, 14: 1, 7: 1, 20: 1, 28: 1, 44: 1}" ]
def check(candidate): # Check some simple cases assert frequency_lists([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]])=={1: 1, 2: 3, 3: 1, 4: 1, 5: 2, 6: 1, 7: 1, 8: 1, 9: 1} assert frequency_lists([[1,2,3,4],[5,6,7,8],[9,10,11,12]])=={1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1,10:1,11:1,12:1} assert frequency_lists([[20,30,40,17],[18,16,14,13],[10,20,30,40]])=={20:2,30:2,40:2,17: 1,18:1, 16: 1,14: 1,13: 1, 10: 1}
98
Write a function to multiply all the numbers in a list and divide with the length of the list.
multiply_num
def multiply_num(numbers): total = 1 for x in numbers: total *= x return total/len(numbers)
[ "assert multiply_num((14, 19, 16)) == 1418.6666666666667", "assert multiply_num((19, 14, 21)) == 1862.0", "assert multiply_num((16, 12, 14)) == 896.0" ]
def check(candidate): # Check some simple cases assert multiply_num((8, 2, 3, -1, 7))==-67.2 assert multiply_num((-10,-20,-30))==-2000.0 assert multiply_num((19,15,18))==1710.0
99
Write a function to convert the given decimal number to its binary equivalent.
decimal_to_binary
def decimal_to_binary(n): return bin(n).replace("0b","")
[ "assert decimal_to_binary(7) == 111", "assert decimal_to_binary(7) == 111", "assert decimal_to_binary(11) == 1011" ]
def check(candidate): # Check some simple cases assert decimal_to_binary(8) == '1000' assert decimal_to_binary(18) == '10010' assert decimal_to_binary(7) == '111'
100
Write a function to find the next smallest palindrome of a specified number.
next_smallest_palindrome
import sys def next_smallest_palindrome(num): numstr = str(num) for i in range(num+1,sys.maxsize): if str(i) == str(i)[::-1]: return i
[ "assert next_smallest_palindrome(124) == 131", "assert next_smallest_palindrome(115) == 121", "assert next_smallest_palindrome(116) == 121" ]
def check(candidate): # Check some simple cases assert next_smallest_palindrome(99)==101 assert next_smallest_palindrome(1221)==1331 assert next_smallest_palindrome(120)==121
README.md exists but content is empty.
Downloads last month
103