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
401
Write a function to perform index wise addition of tuple elements in the given two nested tuples.
add_nested_tuples
def add_nested_tuples(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 add_nested_tuples(((5, 3), (7, 9), (1, 15), (5, 10)), ((5, 13), (10, 12), (8, 7), (8, 4))) == ((10, 16), (17, 21), (9, 22), (13, 14))", "assert add_nested_tuples(((1, 2), (6, 3), (6, 6), (5, 9)), ((3, 13), (8, 15), (5, 5), (8, 2))) == ((4, 15), (14, 18), (11, 11), (13, 11))", "assert add_nested_tuples(((2, 3), (8, 7), (7, 13), (5, 8)), ((12, 6), (1, 8), (1, 5), (9, 7))) == ((14, 9), (9, 15), (8, 18), (14, 15))" ]
def check(candidate): # Check some simple cases assert add_nested_tuples(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((7, 10), (7, 14), (3, 10), (8, 13)) assert add_nested_tuples(((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))) == ((9, 12), (9, 16), (5, 12), (10, 15)) assert add_nested_tuples(((3, 5), (6, 7), (4, 11), (3, 12)), ((8, 9), (5, 11), (3, 3), (9, 5))) == ((11, 14), (11, 18), (7, 14), (12, 17))
402
Write a function to compute the value of ncr%p.
ncr_modp
def ncr_modp(n, r, p): C = [0 for i in range(r+1)] C[0] = 1 for i in range(1, n+1): for j in range(min(i, r), 0, -1): C[j] = (C[j] + C[j-1]) % p return C[r]
[ "assert ncr_modp(14, 13, 17) == 14", "assert ncr_modp(19, 10, 16) == 10", "assert ncr_modp(22, 9, 14) == 0" ]
def check(candidate): # Check some simple cases assert ncr_modp(10,2,13)==6 assert ncr_modp(15,12,43)==25 assert ncr_modp(17,9,18)==10
403
Write a function to check if a url is valid or not using regex.
is_valid_URL
import re def is_valid_URL(str): regex = ("((http|https)://)(www.)?" + "[a-zA-Z0-9@:%._\\+~#?&//=]" + "{2,256}\\.[a-z]" + "{2,6}\\b([-a-zA-Z0-9@:%" + "._\\+~#?&//=]*)") p = re.compile(regex) if (str == None): return False if(re.search(p, str)): return True else: return False
[ "assert is_valid_URL(\"@&^iee-pmt<#z#+lw .|e&v!k\") == False", "assert is_valid_URL(\"m@dbd#teloxvg!?%&zm />chr&\") == False", "assert is_valid_URL(\"w~!>&osqwdnl#xc*quxwa|y^d\") == False" ]
def check(candidate): # Check some simple cases assert is_valid_URL("https://www.google.com") == True assert is_valid_URL("https:/www.gmail.com") == False assert is_valid_URL("https:// www.redit.com") == False
404
Write a python function to find the minimum of two numbers.
minimum
def minimum(a,b): if a <= b: return a else: return b
[ "assert minimum(4, 2) == 2", "assert minimum(5, 4) == 4", "assert minimum(3, 2) == 2" ]
def check(candidate): # Check some simple cases assert minimum(1,2) == 1 assert minimum(-5,-4) == -5 assert minimum(0,0) == 0
405
Write a function to check whether an element exists within a tuple.
check_tuplex
def check_tuplex(tuplex,tuple1): if tuple1 in tuplex: return True else: return False
[ "assert check_tuplex(('k', 8, 'b', 'u', 's', 'q', 'f', 'g', 'k', 'k'), 6) == False", "assert check_tuplex(('u', 7, 'c', 'b', 't', 'y', 'c', 'm', 'q', 'e'), 2) == False", "assert check_tuplex(('b', 6, 'e', 'x', 'b', 'h', 'v', 'g', 't', 'l'), 7) == False" ]
def check(candidate): # Check some simple cases assert check_tuplex(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),'r')==True assert check_tuplex(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),'5')==False assert check_tuplex(("w", 3, "r", "e", "s", "o", "u", "r", "c","e"),3)==True
406
Write a python function to find the parity of a given number.
find_Parity
def find_Parity(x): y = x ^ (x >> 1); y = y ^ (y >> 2); y = y ^ (y >> 4); y = y ^ (y >> 8); y = y ^ (y >> 16); if (y & 1): return ("Odd Parity"); return ("Even Parity");
[ "assert find_Parity(6) == \"Even Parity\"", "assert find_Parity(13) == \"Odd Parity\"", "assert find_Parity(13) == \"Odd Parity\"" ]
def check(candidate): # Check some simple cases assert find_Parity(12) == "Even Parity" assert find_Parity(7) == "Odd Parity" assert find_Parity(10) == "Even Parity"
407
Write a function to create the next bigger number by rearranging the digits of a given number.
rearrange_bigger
def rearrange_bigger(n): nums = list(str(n)) for i in range(len(nums)-2,-1,-1): if nums[i] < nums[i+1]: z = nums[i:] y = min(filter(lambda x: x > z[0], z)) z.remove(y) z.sort() nums[i:] = [y] + z return int("".join(nums)) return False
[ "assert rearrange_bigger(106) == 160", "assert rearrange_bigger(97) == False", "assert rearrange_bigger(103) == 130" ]
def check(candidate): # Check some simple cases assert rearrange_bigger(12)==21 assert rearrange_bigger(10)==False assert rearrange_bigger(102)==120
408
Write a function to find k number of pairs which consist of one element from the first array and one element from the second array.
k_smallest_pairs
import heapq def k_smallest_pairs(nums1, nums2, k): queue = [] def push(i, j): if i < len(nums1) and j < len(nums2): heapq.heappush(queue, [nums1[i] + nums2[j], i, j]) push(0, 0) pairs = [] while queue and len(pairs) < k: _, i, j = heapq.heappop(queue) pairs.append([nums1[i], nums2[j]]) push(i, j + 1) if j == 0: push(i + 1, 0) return pairs
[ "assert k_smallest_pairs([1, 8, 12], [5, 3, 6], 9) == [[1, 5], [1, 3], [1, 6], [8, 5], [8, 3], [8, 6], [12, 5], [12, 3], [12, 6]]", "assert k_smallest_pairs([5, 1, 10], [7, 8, 3], 5) == [[5, 7], [1, 7], [1, 8], [1, 3], [5, 8]]", "assert k_smallest_pairs([6, 4, 9], [7, 7, 7], 8) == [[6, 7], [4, 7], [4, 7], [4, 7], [6, 7], [6, 7], [9, 7], [9, 7]]" ]
def check(candidate): # Check some simple cases assert k_smallest_pairs([1,3,7],[2,4,6],2)==[[1, 2], [1, 4]] assert k_smallest_pairs([1,3,7],[2,4,6],1)==[[1, 2]] assert k_smallest_pairs([1,3,7],[2,4,6],7)==[[1, 2], [1, 4], [3, 2], [1, 6], [3, 4], [3, 6], [7, 2]]
409
Write a function to find the minimum product from the pairs of tuples within a given list.
min_product_tuple
def min_product_tuple(list1): result_min = min([abs(x * y) for x, y in list1] ) return result_min
[ "assert min_product_tuple([(6, 40), (5, 14), (25, 4), (15, 8)]) == 70", "assert min_product_tuple([(8, 46), (6, 16), (21, 1), (16, 12)]) == 21", "assert min_product_tuple([(14, 41), (11, 19), (23, 2), (15, 11)]) == 46" ]
def check(candidate): # Check some simple cases assert min_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==8 assert min_product_tuple([(10,20), (15,2), (5,10)] )==30 assert min_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==100
410
Write a function to find the minimum value in a given heterogeneous list.
min_val
def min_val(listval): min_val = min(i for i in listval if isinstance(i, int)) return min_val
[ "assert min_val(['NgjVlijoj', 26, 23, 40, 45, 'ivoqgxtmumcs']) == 23", "assert min_val(['TYNHbzm', 29, 16, 44, 46, 'nlaltmiw']) == 16", "assert min_val(['zGWj', 35, 21, 35, 46, 'cemxckmva']) == 21" ]
def check(candidate): # Check some simple cases assert min_val(['Python', 3, 2, 4, 5, 'version'])==2 assert min_val(['Python', 15, 20, 25])==15 assert min_val(['Python', 30, 20, 40, 50, 'version'])==20
411
Write a function to convert the given snake case string to camel case string by using regex.
snake_to_camel
import re def snake_to_camel(word): return ''.join(x.capitalize() or '_' for x in word.split('_'))
[ "assert snake_to_camel(\"|b~>&=zxq$vjbh\") == \"|b~>&=zxq$vjbh\"", "assert snake_to_camel(\"<x*a@&ey^-uf\") == \"<x*a@&ey^-uf\"", "assert snake_to_camel(\"ivtnr?by\") == \"Ivtnr?by\"" ]
def check(candidate): # Check some simple cases assert snake_to_camel('android_tv') == 'AndroidTv' assert snake_to_camel('google_pixel') == 'GooglePixel' assert snake_to_camel('apple_watch') == 'AppleWatch'
412
Write a python function to remove odd numbers from a given list.
remove_odd
def remove_odd(l): for i in l: if i % 2 != 0: l.remove(i) return l
[ "assert remove_odd([13, 24, 8]) == [24, 8]", "assert remove_odd([14, 24, 5]) == [14, 24]", "assert remove_odd([14, 21, 5]) == [14, 5]" ]
def check(candidate): # Check some simple cases assert remove_odd([1,2,3]) == [2] assert remove_odd([2,4,6]) == [2,4,6] assert remove_odd([10,20,3]) == [10,20]
413
Write a function to extract the nth element from a given list of tuples.
extract_nth_element
def extract_nth_element(list1, n): result = [x[n] for x in list1] return result
[ "assert extract_nth_element([('NVmYekUWgFuwOen', 100, 101), ('DUSExtFr', 95, 95), ('KNhQYYwt', 88, 92), ('BrmVbueOUiyOzVzhkr', 98, 97)], 1) == [100, 95, 88, 98]", "assert extract_nth_element([('eiCRglosVRvofTNF', 99, 100), ('MGNlSs', 98, 92), ('kXUphWY', 86, 90), ('VXNsSxuHUgAN', 97, 102)], 2) == [100, 92, 90, 102]", "assert extract_nth_element([('IWiqzUQGClprveCn', 100, 95), ('hTrJYUeXpt', 98, 94), ('eEBFCrmpGuQ', 91, 89), ('XDKhdHgbbz', 93, 99)], 1) == [100, 98, 91, 93]" ]
def check(candidate): # Check some simple cases assert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,0)==['Greyson Fulton', 'Brady Kent', 'Wyatt Knott', 'Beau Turnbull'] assert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,2)==[99, 96, 94, 98] assert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)],1)==[98, 97, 91, 94]
414
Write a python function to check whether the value exists in a sequence or not.
overlapping
def overlapping(list1,list2): c=0 d=0 for i in list1: c+=1 for i in list2: d+=1 for i in range(0,c): for j in range(0,d): if(list1[i]==list2[j]): return 1 return 0
[ "assert overlapping([1, 9, 4], [1, 1, 4]) == 1", "assert overlapping([5, 3, 9], [3, 7, 5]) == 1", "assert overlapping([5, 4, 4], [4, 4, 7]) == 1" ]
def check(candidate): # Check some simple cases assert overlapping([1,2,3,4,5],[6,7,8,9]) == False assert overlapping([1,2,3],[4,5,6]) == False assert overlapping([1,4,5],[1,4,5]) == True
415
Write a python function to find a pair with highest product from a given array of integers.
max_Product
def max_Product(arr): arr_len = len(arr) if (arr_len < 2): return ("No pairs exists") x = arr[0]; y = arr[1] for i in range(0,arr_len): for j in range(i + 1,arr_len): if (arr[i] * arr[j] > x * y): x = arr[i]; y = arr[j] return x,y
[ "assert max_Product([2, 6, 7]) == (6, 7)", "assert max_Product([2, 2, 8]) == (2, 8)", "assert max_Product([5, 4, 4]) == (5, 4)" ]
def check(candidate): # Check some simple cases assert max_Product([1,2,3,4,7,0,8,4]) == (7,8) assert max_Product([0,-1,-2,-4,5,0,-6]) == (-4,-6) assert max_Product([1,2,3]) == (2,3)
416
Write a function to find the maximum sum we can make by dividing number in three parts recursively and summing them up together for the given number.
breakSum
MAX = 1000000 def breakSum(n): dp = [0]*(n+1) dp[0] = 0 dp[1] = 1 for i in range(2, n+1): dp[i] = max(dp[int(i/2)] + dp[int(i/3)] + dp[int(i/4)], i); return dp[n]
[ "assert breakSum(21) == 22", "assert breakSum(20) == 21", "assert breakSum(23) == 23" ]
def check(candidate): # Check some simple cases assert breakSum(12) == 13 assert breakSum(24) == 27 assert breakSum(23) == 23
417
Write a function to find common first element in given list of tuple.
group_tuples
def group_tuples(Input): out = {} for elem in Input: try: out[elem[0]].extend(elem[1:]) except KeyError: out[elem[0]] = list(elem) return [tuple(values) for values in out.values()]
[ "assert group_tuples([('f', 'y'), ('p', 'k'), ('k', 'd')]) == [('f', 'y'), ('p', 'k'), ('k', 'd')]", "assert group_tuples([('s', 'q'), ('j', 'h'), ('p', 'c')]) == [('s', 'q'), ('j', 'h'), ('p', 'c')]", "assert group_tuples([('u', 'b'), ('u', 'f'), ('n', 'i')]) == [('u', 'b', 'f'), ('n', 'i')]" ]
def check(candidate): # Check some simple cases assert group_tuples([('x', 'y'), ('x', 'z'), ('w', 't')]) == [('x', 'y', 'z'), ('w', 't')] assert group_tuples([('a', 'b'), ('a', 'c'), ('d', 'e')]) == [('a', 'b', 'c'), ('d', 'e')] assert group_tuples([('f', 'g'), ('f', 'g'), ('h', 'i')]) == [('f', 'g', 'g'), ('h', 'i')]
418
Write a python function to find the sublist having maximum length.
Find_Max
def Find_Max(lst): maxList = max((x) for x in lst) return maxList
[ "assert Find_Max([[5, 2], [6, 6, 5], [5, 1, 11, 4]]) == [6, 6, 5]", "assert Find_Max([[1, 4], [5, 3, 2], [1, 4, 4, 2]]) == [5, 3, 2]", "assert Find_Max([[1, 6], [4, 3, 5], [5, 7, 4, 2]]) == [5, 7, 4, 2]" ]
def check(candidate): # Check some simple cases assert Find_Max([['A'],['A','B'],['A','B','C']]) == ['A','B','C'] assert Find_Max([[1],[1,2],[1,2,3]]) == [1,2,3] assert Find_Max([[1,1],[1,2,3],[1,5,6,1]]) == [1,5,6,1]
419
Write a function to round every number of a given list of numbers and print the total sum multiplied by the length of the list.
round_and_sum
def round_and_sum(list1): lenght=len(list1) round_and_sum=sum(list(map(round,list1))* lenght) return round_and_sum
[ "assert round_and_sum([22.625429111901006, 59.55040915195105, 93.63213589860239]) == 531", "assert round_and_sum([25.733849749457423, 52.19471502362164, 93.03133352325072]) == 513", "assert round_and_sum([26.31752612565648, 51.523578117715836, 88.93970700899483]) == 501" ]
def check(candidate): # Check some simple cases assert round_and_sum([22.4, 4.0, -16.22, -9.10, 11.00, -12.22, 14.20, -5.20, 17.50])==243 assert round_and_sum([5,2,9,24.3,29])==345 assert round_and_sum([25.0,56.7,89.2])==513
420
Write a python function to find the cube sum of first n even natural numbers.
cube_Sum
def cube_Sum(n): sum = 0 for i in range(1,n + 1): sum += (2*i)*(2*i)*(2*i) return sum
[ "assert cube_Sum(6) == 3528", "assert cube_Sum(7) == 6272", "assert cube_Sum(5) == 1800" ]
def check(candidate): # Check some simple cases assert cube_Sum(2) == 72 assert cube_Sum(3) == 288 assert cube_Sum(4) == 800
421
Write a function to concatenate each element of tuple by the delimiter.
concatenate_tuple
def concatenate_tuple(test_tup): delim = "-" res = ''.join([str(ele) + delim for ele in test_tup]) res = res[ : len(res) - len(delim)] return (str(res))
[ "assert concatenate_tuple(('EKMSQSLVE', 'mclwy', 2, 'ZKK')) == \"EKMSQSLVE-mclwy-2-ZKK\"", "assert concatenate_tuple(('FQRL', 'fvcq', 7, 'UVZ')) == \"FQRL-fvcq-7-UVZ\"", "assert concatenate_tuple(('ZRYQKJA', 'rkobwo', 7, 'XYGAC')) == \"ZRYQKJA-rkobwo-7-XYGAC\"" ]
def check(candidate): # Check some simple cases assert concatenate_tuple(("ID", "is", 4, "UTS") ) == 'ID-is-4-UTS' assert concatenate_tuple(("QWE", "is", 4, "RTY") ) == 'QWE-is-4-RTY' assert concatenate_tuple(("ZEN", "is", 4, "OP") ) == 'ZEN-is-4-OP'
422
Write a python function to find the average of cubes of first n natural numbers.
find_Average_Of_Cube
def find_Average_Of_Cube(n): sum = 0 for i in range(1, n + 1): sum += i * i * i return round(sum / n, 6)
[ "assert find_Average_Of_Cube(1) == 1.0", "assert find_Average_Of_Cube(1) == 1.0", "assert find_Average_Of_Cube(1) == 1.0" ]
def check(candidate): # Check some simple cases assert find_Average_Of_Cube(2) == 4.5 assert find_Average_Of_Cube(3) == 12 assert find_Average_Of_Cube(1) == 1
423
Write a function to solve gold mine problem.
get_maxgold
def get_maxgold(gold, m, n): goldTable = [[0 for i in range(n)] for j in range(m)] for col in range(n-1, -1, -1): for row in range(m): if (col == n-1): right = 0 else: right = goldTable[row][col+1] if (row == 0 or col == n-1): right_up = 0 else: right_up = goldTable[row-1][col+1] if (row == m-1 or col == n-1): right_down = 0 else: right_down = goldTable[row+1][col+1] goldTable[row][col] = gold[row][col] + max(right, right_up, right_down) res = goldTable[0][0] for i in range(1, m): res = max(res, goldTable[i][0]) return res
[ "assert get_maxgold([[5, 9], [8, 9]], 2, 2) == 17", "assert get_maxgold([[3, 10], [8, 9]], 1, 2) == 13", "assert get_maxgold([[8, 6], [7, 3]], 2, 1) == 8" ]
def check(candidate): # Check some simple cases assert get_maxgold([[1, 3, 1, 5],[2, 2, 4, 1],[5, 0, 2, 3],[0, 6, 1, 2]],4,4)==16 assert get_maxgold([[10,20],[30,40]],2,2)==70 assert get_maxgold([[4,9],[3,7]],2,2)==13
424
Write a function to extract only the rear index element of each string in the given tuple.
extract_rear
def extract_rear(test_tuple): res = list(sub[len(sub) - 1] for sub in test_tuple) return (res)
[ "assert extract_rear(('WyCrS', 'egbzmx', 'idf')) == ['S', 'x', 'f']", "assert extract_rear(('JfHMpqQR', 'zfumi', 'pfwdan')) == ['R', 'i', 'n']", "assert extract_rear(('lpsy', 'ihsjw', 'lbsk')) == ['y', 'w', 'k']" ]
def check(candidate): # Check some simple cases assert extract_rear(('Mers', 'for', 'Vers') ) == ['s', 'r', 's'] assert extract_rear(('Avenge', 'for', 'People') ) == ['e', 'r', 'e'] assert extract_rear(('Gotta', 'get', 'go') ) == ['a', 't', 'o']
425
Write a function to count the number of sublists containing a particular element.
count_element_in_list
def count_element_in_list(list1, x): ctr = 0 for i in range(len(list1)): if x in list1[i]: ctr+= 1 return ctr
[ "assert count_element_in_list([['Z', 'K'], ['M', 'T'], ['T', 'G', 'X'], ['Y', 'L', 'N']], 'Z') == 1", "assert count_element_in_list([['A', 'P'], ['J', 'P'], ['P', 'D', 'O'], ['K', 'C', 'R']], 'Q') == 0", "assert count_element_in_list([['Y', 'Y'], ['Z', 'P'], ['T', 'C', 'C'], ['Z', 'G', 'A']], 'T') == 1" ]
def check(candidate): # Check some simple cases assert count_element_in_list([[1, 3], [5, 7], [1, 11], [1, 15, 7]],1)==3 assert count_element_in_list([['A', 'B'], ['A', 'C'], ['A', 'D', 'E'], ['B', 'C', 'D']],'A')==3 assert count_element_in_list([['A', 'B'], ['A', 'C'], ['A', 'D', 'E'], ['B', 'C', 'D']],'E')==1
426
Write a function to filter odd numbers using lambda function.
filter_oddnumbers
def filter_oddnumbers(nums): odd_nums = list(filter(lambda x: x%2 != 0, nums)) return odd_nums
[ "assert filter_oddnumbers([10, 11, 8, 8, 5, 1, 3]) == [11, 5, 1, 3]", "assert filter_oddnumbers([10, 5, 6, 6, 1, 8, 1]) == [5, 1, 1]", "assert filter_oddnumbers([2, 8, 5, 13, 7, 5, 3]) == [5, 13, 7, 5, 3]" ]
def check(candidate): # Check some simple cases assert filter_oddnumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9] assert filter_oddnumbers([10,20,45,67,84,93])==[45,67,93] assert filter_oddnumbers([5,7,9,8,6,4,3])==[5,7,9,3]
427
Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format by using regex.
change_date_format
import re def change_date_format(dt): return re.sub(r'(\d{4})-(\d{1,2})-(\d{1,2})', '\\3-\\2-\\1', dt)
[ "assert change_date_format(\"~=*9020\") == \"~=*9020\"", "assert change_date_format(\"$/-_/-\") == \"$/-_/-\"", "assert change_date_format(\"57319^$4_=3\") == \"57319^$4_=3\"" ]
def check(candidate): # Check some simple cases assert change_date_format("2026-01-02") == '02-01-2026' assert change_date_format("2020-11-13") == '13-11-2020' assert change_date_format("2021-04-26") == '26-04-2021'
428
Write a function to sort the given array by using shell sort.
shell_sort
def shell_sort(my_list): gap = len(my_list) // 2 while gap > 0: for i in range(gap, len(my_list)): current_item = my_list[i] j = i while j >= gap and my_list[j - gap] > current_item: my_list[j] = my_list[j - gap] j -= gap my_list[j] = current_item gap //= 2 return my_list
[ "assert shell_sort([33, 32, 14, 92, 81, 87, 70]) == [14, 32, 33, 70, 81, 87, 92]", "assert shell_sort([29, 28, 11, 96, 87, 82, 76]) == [11, 28, 29, 76, 82, 87, 96]", "assert shell_sort([34, 30, 11, 91, 83, 85, 69]) == [11, 30, 34, 69, 83, 85, 91]" ]
def check(candidate): # Check some simple cases assert shell_sort([12, 23, 4, 5, 3, 2, 12, 81, 56, 95]) == [2, 3, 4, 5, 12, 12, 23, 56, 81, 95] assert shell_sort([24, 22, 39, 34, 87, 73, 68]) == [22, 24, 34, 39, 68, 73, 87] assert shell_sort([32, 30, 16, 96, 82, 83, 74]) == [16, 30, 32, 74, 82, 83, 96]
429
Write a function to extract the elementwise and tuples from the given two tuples.
and_tuples
def and_tuples(test_tup1, test_tup2): res = tuple(ele1 & ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res)
[ "assert and_tuples((6, 8, 6, 7), (4, 16, 15, 18)) == (4, 0, 6, 2)", "assert and_tuples((6, 10, 8, 13), (2, 16, 15, 17)) == (2, 0, 8, 1)", "assert and_tuples((10, 6, 13, 9), (9, 15, 9, 13)) == (8, 6, 9, 9)" ]
def check(candidate): # Check some simple cases assert and_tuples((10, 4, 6, 9), (5, 2, 3, 3)) == (0, 0, 2, 1) assert and_tuples((1, 2, 3, 4), (5, 6, 7, 8)) == (1, 2, 3, 0) assert and_tuples((8, 9, 11, 12), (7, 13, 14, 17)) == (0, 9, 10, 0)
430
Write a function to find the directrix of a parabola.
parabola_directrix
def parabola_directrix(a, b, c): directrix=((int)(c - ((b * b) + 1) * 4 * a )) return directrix
[ "assert parabola_directrix(2, 9, 4) == -652", "assert parabola_directrix(4, 8, 11) == -1029", "assert parabola_directrix(7, 4, 9) == -467" ]
def check(candidate): # Check some simple cases assert parabola_directrix(5,3,2)==-198 assert parabola_directrix(9,8,4)==-2336 assert parabola_directrix(2,4,6)==-130
431
Write a function that takes two lists and returns true if they have at least one common element.
common_element
def common_element(list1, list2): result = False for x in list1: for y in list2: if x == y: result = True return result
[ "assert common_element(['w', 'd', 'p'], ['s', 'c', 'v']) == None", "assert common_element(['y', 'c', 'v'], ['w', 'o', 'l']) == None", "assert common_element(['q', 'y', 'a'], ['x', 's', 's']) == None" ]
def check(candidate): # Check some simple cases assert common_element([1,2,3,4,5], [5,6,7,8,9])==True assert common_element([1,2,3,4,5], [6,7,8,9])==None assert common_element(['a','b','c'], ['d','b','e'])==True
432
Write a function to find the median of a trapezium.
median_trapezium
def median_trapezium(base1,base2,height): median = 0.5 * (base1+ base2) return median
[ "assert median_trapezium(4, 9, 9) == 6.5", "assert median_trapezium(6, 6, 6) == 6.0", "assert median_trapezium(4, 8, 4) == 6.0" ]
def check(candidate): # Check some simple cases assert median_trapezium(15,25,35)==20 assert median_trapezium(10,20,30)==15 assert median_trapezium(6,9,4)==7.5
433
Write a function to check whether the entered number is greater than the elements of the given array.
check_greater
def check_greater(arr, number): arr.sort() if number > arr[-1]: return ('Yes, the entered number is greater than those in the array') else: return ('No, entered number is less than those in the array')
[ "assert check_greater([9, 2, 9, 5, 10, 3], 12) == \"Yes, the entered number is greater than those in the array\"", "assert check_greater([7, 10, 7, 3, 6, 1], 9) == \"No, entered number is less than those in the array\"", "assert check_greater([14, 3, 9, 3, 4, 3], 15) == \"Yes, the entered number is greater than those in the array\"" ]
def check(candidate): # Check some simple cases assert check_greater([1, 2, 3, 4, 5], 4) == 'No, entered number is less than those in the array' assert check_greater([2, 3, 4, 5, 6], 8) == 'Yes, the entered number is greater than those in the array' assert check_greater([9, 7, 4, 8, 6, 1], 11) == 'Yes, the entered number is greater than those in the array'
434
Write a function that matches a string that has an a followed by one or more b's.
text_match_one
import re def text_match_one(text): patterns = 'ab+?' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
[ "assert text_match_one(\"uvxvdxvky\") == \"Not matched!\"", "assert text_match_one(\"dcijyibc\") == \"Not matched!\"", "assert text_match_one(\"jaqtpqg\") == \"Not matched!\"" ]
def check(candidate): # Check some simple cases assert text_match_one("ac")==('Not matched!') assert text_match_one("dc")==('Not matched!') assert text_match_one("abba")==('Found a match!')
435
Write a python function to find the last digit of a given number.
last_Digit
def last_Digit(n) : return (n % 10)
[ "assert last_Digit(35) == 5", "assert last_Digit(32) == 2", "assert last_Digit(34) == 4" ]
def check(candidate): # Check some simple cases assert last_Digit(123) == 3 assert last_Digit(25) == 5 assert last_Digit(30) == 0
436
Write a python function to print negative numbers in a list.
neg_nos
def neg_nos(list1): for num in list1: if num < 0: return num
[ "assert neg_nos([-12, -8, 7, 12]) == -12", "assert neg_nos([-12, -1, 11, 9]) == -12", "assert neg_nos([-5, -3, 10, 9]) == -5" ]
def check(candidate): # Check some simple cases assert neg_nos([-1,4,5,-6]) == -1,-6 assert neg_nos([-1,-2,3,4]) == -1,-2 assert neg_nos([-7,-6,8,9]) == -7,-6
437
Write a function to remove odd characters in a string.
remove_odd
def remove_odd(str1): str2 = '' for i in range(1, len(str1) + 1): if(i % 2 == 0): str2 = str2 + str1[i - 1] return str2
[ "assert remove_odd(\"vixtwnv\") == \"itn\"", "assert remove_odd(\"gpunb\") == \"pn\"", "assert remove_odd(\"xldhtm\") == \"lhm\"" ]
def check(candidate): # Check some simple cases assert remove_odd("python")==("yhn") assert remove_odd("program")==("rga") assert remove_odd("language")==("agae")
438
Write a function to count bidirectional tuple pairs.
count_bidirectional
def count_bidirectional(test_list): res = 0 for idx in range(0, len(test_list)): for iidx in range(idx + 1, len(test_list)): if test_list[iidx][0] == test_list[idx][1] and test_list[idx][1] == test_list[iidx][0]: res += 1 return (str(res))
[ "assert count_bidirectional([(8, 8), (6, 7), (10, 2), (10, 6), (6, 1), (3, 6)]) == 1", "assert count_bidirectional([(2, 1), (1, 2), (5, 9), (7, 2), (10, 6), (7, 1)]) == 1", "assert count_bidirectional([(3, 10), (1, 1), (6, 10), (6, 4), (5, 5), (5, 6)]) == 1" ]
def check(candidate): # Check some simple cases assert count_bidirectional([(5, 6), (1, 2), (6, 5), (9, 1), (6, 5), (2, 1)] ) == '3' assert count_bidirectional([(5, 6), (1, 3), (6, 5), (9, 1), (6, 5), (2, 1)] ) == '2' assert count_bidirectional([(5, 6), (1, 2), (6, 5), (9, 2), (6, 5), (2, 1)] ) == '4'
439
Write a function to convert a list of multiple integers into a single integer.
multiple_to_single
def multiple_to_single(L): x = int("".join(map(str, L))) return x
[ "assert multiple_to_single([8, 14, 25, 26]) == 8142526", "assert multiple_to_single([15, 17, 18, 22]) == 15171822", "assert multiple_to_single([8, 20, 25, 23]) == 8202523" ]
def check(candidate): # Check some simple cases assert multiple_to_single([11, 33, 50])==113350 assert multiple_to_single([-1,2,3,4,5,6])==-123456 assert multiple_to_single([10,15,20,25])==10152025
440
Write a function to find all adverbs and their positions in a given sentence.
find_adverb_position
import re def find_adverb_position(text): for m in re.finditer(r"\w+ly", text): return (m.start(), m.end(), m.group(0))
[ "assert find_adverb_position(\"i?>@|?s~v$y- kc/r^e-e_d-!v$@$c?fi\") == None", "assert find_adverb_position(\"j*o:g+p=*=av:^o&<@-av&$tkw/mza!iv|sw_f_:$g\") == None", "assert find_adverb_position(\"#-@%!wq&w&!h!ta@vo~fkr?<=hz/#c+f#uvnd#d\") == None" ]
def check(candidate): # Check some simple cases assert find_adverb_position("clearly!! we can see the sky")==(0, 7, 'clearly') assert find_adverb_position("seriously!! there are many roses")==(0, 9, 'seriously') assert find_adverb_position("unfortunately!! sita is going to home")==(0, 13, 'unfortunately')
441
Write a function to find the surface area of a cube.
surfacearea_cube
def surfacearea_cube(l): surfacearea= 6*l*l return surfacearea
[ "assert surfacearea_cube(8) == 384", "assert surfacearea_cube(8) == 384", "assert surfacearea_cube(9) == 486" ]
def check(candidate): # Check some simple cases assert surfacearea_cube(5)==150 assert surfacearea_cube(3)==54 assert surfacearea_cube(10)==600
442
Write a function to find the ration of positive numbers in an array of integers.
positive_count
from array import array def positive_count(nums): n = len(nums) n1 = 0 for x in nums: if x > 0: n1 += 1 else: None return round(n1/n,2)
[ "assert positive_count([6, 4, -9, -12, 13, -8, 15, -5, 16]) == 0.56", "assert positive_count([6, 4, -7, -7, 15, -8, 15, -2, 18]) == 0.56", "assert positive_count([5, 9, -4, -5, 13, -10, 16, -4, 15]) == 0.56" ]
def check(candidate): # Check some simple cases assert positive_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8])==0.54 assert positive_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==0.69 assert positive_count([2, 4, -6, -9, 11, -12, 14, -5, 17])==0.56
443
Write a python function to find the largest negative number from the given list.
largest_neg
def largest_neg(list1): max = list1[0] for x in list1: if x < max : max = x return max
[ "assert largest_neg([1, 3, 4, 1, -4]) == -4", "assert largest_neg([1, 1, 6, 1, -1]) == -1", "assert largest_neg([3, 7, 4, 6, -5]) == -5" ]
def check(candidate): # Check some simple cases assert largest_neg([1,2,3,-4,-6]) == -6 assert largest_neg([1,2,3,-8,-9]) == -9 assert largest_neg([1,2,3,4,-1]) == -1
444
Write a function to trim each tuple by k in the given tuple list.
trim_tuple
def trim_tuple(test_list, K): res = [] for ele in test_list: N = len(ele) res.append(tuple(list(ele)[K: N - K])) return (str(res))
[ "assert trim_tuple([(12, 8, 1, 8), (9, 3, 7, 3), (9, 5, 9, 9), (1, 6, 8, 5)], 1) == [(8, 1), (3, 7), (5, 9), (6, 8)]", "assert trim_tuple([(11, 13, 6, 14), (13, 3, 13, 5), (2, 3, 10, 5), (8, 3, 14, 12)], 4) == [(), (), (), ()]", "assert trim_tuple([(11, 11, 3, 7), (7, 9, 8, 3), (7, 6, 8, 9), (3, 4, 13, 10)], 4) == [(), (), (), ()]" ]
def check(candidate): # Check some simple cases assert trim_tuple([(5, 3, 2, 1, 4), (3, 4, 9, 2, 1),(9, 1, 2, 3, 5), (4, 8, 2, 1, 7)], 2) == '[(2,), (9,), (2,), (2,)]' assert trim_tuple([(5, 3, 2, 1, 4), (3, 4, 9, 2, 1), (9, 1, 2, 3, 5), (4, 8, 2, 1, 7)], 1) == '[(3, 2, 1), (4, 9, 2), (1, 2, 3), (8, 2, 1)]' assert trim_tuple([(7, 8, 4, 9), (11, 8, 12, 4),(4, 1, 7, 8), (3, 6, 9, 7)], 1) == '[(8, 4), (8, 12), (1, 7), (6, 9)]'
445
Write a function to perform index wise multiplication of tuple elements in the given two tuples.
index_multiplication
def index_multiplication(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 index_multiplication(((3, 3), (8, 5), (6, 9), (6, 13)), ((12, 11), (8, 13), (4, 7), (14, 5))) == ((36, 33), (64, 65), (24, 63), (84, 65))", "assert index_multiplication(((5, 5), (1, 6), (7, 7), (1, 13)), ((13, 14), (5, 8), (8, 1), (5, 2))) == ((65, 70), (5, 48), (56, 7), (5, 26))", "assert index_multiplication(((3, 2), (1, 12), (3, 10), (3, 16)), ((11, 7), (5, 6), (1, 8), (13, 8))) == ((33, 14), (5, 72), (3, 80), (39, 128))" ]
def check(candidate): # Check some simple cases assert index_multiplication(((1, 3), (4, 5), (2, 9), (1, 10)),((6, 7), (3, 9), (1, 1), (7, 3)) ) == ((6, 21), (12, 45), (2, 9), (7, 30)) assert index_multiplication(((2, 4), (5, 6), (3, 10), (2, 11)),((7, 8), (4, 10), (2, 2), (8, 4)) ) == ((14, 32), (20, 60), (6, 20), (16, 44)) assert index_multiplication(((3, 5), (6, 7), (4, 11), (3, 12)),((8, 9), (5, 11), (3, 3), (9, 5)) ) == ((24, 45), (30, 77), (12, 33), (27, 60))
446
Write a python function to count the occurence of all elements of list in a tuple.
count_Occurrence
from collections import Counter def count_Occurrence(tup, lst): count = 0 for item in tup: if item in lst: count+= 1 return count
[ "assert count_Occurrence((2, 6, 3, 9, 1, 5), [4, 3]) == 1", "assert count_Occurrence((3, 5, 7, 1, 1, 6), [1, 4]) == 2", "assert count_Occurrence((3, 7, 6, 3, 4, 4), [3, 6]) == 3" ]
def check(candidate): # Check some simple cases assert count_Occurrence(('a', 'a', 'c', 'b', 'd'),['a', 'b'] ) == 3 assert count_Occurrence((1, 2, 3, 1, 4, 6, 7, 1, 4),[1, 4, 7]) == 6 assert count_Occurrence((1,2,3,4,5,6),[1,2]) == 2
447
Write a function to find cubes of individual elements in a list using lambda function.
cube_nums
def cube_nums(nums): cube_nums = list(map(lambda x: x ** 3, nums)) return cube_nums
[ "assert cube_nums([11, 12]) == [1331, 1728]", "assert cube_nums([11, 16]) == [1331, 4096]", "assert cube_nums([13, 16]) == [2197, 4096]" ]
def check(candidate): # Check some simple cases assert cube_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000] assert cube_nums([10,20,30])==([1000, 8000, 27000]) assert cube_nums([12,15])==([1728, 3375])
448
Write a function to calculate the sum of perrin numbers.
cal_sum
def cal_sum(n): a = 3 b = 0 c = 2 if (n == 0): return 3 if (n == 1): return 3 if (n == 2): return 5 sum = 5 while (n > 2): d = a + b sum = sum + d a = b b = c c = d n = n-1 return sum
[ "assert cal_sum(15) == 275", "assert cal_sum(11) == 88", "assert cal_sum(8) == 37" ]
def check(candidate): # Check some simple cases assert cal_sum(9) == 49 assert cal_sum(10) == 66 assert cal_sum(11) == 88
449
Write a python function to check whether the triangle is valid or not if 3 points are given.
check_Triangle
def check_Triangle(x1,y1,x2,y2,x3,y3): a = (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)) if a == 0: return ('No') else: return ('Yes')
[ "assert check_Triangle(4, 4, 4, 5, 4, 6) == No", "assert check_Triangle(6, 5, 4, 1, 2, 5) == Yes", "assert check_Triangle(6, 3, 6, 4, 6, 1) == No" ]
def check(candidate): # Check some simple cases assert check_Triangle(1,5,2,5,4,6) == 'Yes' assert check_Triangle(1,1,1,4,1,5) == 'No' assert check_Triangle(1,1,1,1,1,1) == 'No'
450
Write a function to extract specified size of strings from a give list of string values.
extract_string
def extract_string(str, l): result = [e for e in str if len(e) == l] return result
[ "assert extract_string(['EoZ', 'qyfypovk', 'ourfcn', 'jwz', 'llqxtppzt'], 14) == []", "assert extract_string(['RIawmwjQdirR', 'pnhet', 'mywjfndfwl', 'nym', 'idsgtty'], 8) == []", "assert extract_string(['Eip', 'qgccnc', 'ujgeifgzrsxmuvw', 'fism', 'ifnn'], 13) == []" ]
def check(candidate): # Check some simple cases assert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,8)==['practice', 'solution'] assert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,6)==['Python'] assert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,9)==['exercises']
451
Write a function to remove all whitespaces from the given string using regex.
remove_whitespaces
import re def remove_whitespaces(text1): return (re.sub(r'\s+', '',text1))
[ "assert remove_whitespaces(\"LrsQBaLMiVnMQDw \") == \"LrsQBaLMiVnMQDw\"", "assert remove_whitespaces(\"XKDIFnyNZ\") == \"XKDIFnyNZ\"", "assert remove_whitespaces(\"peZMSACltYTzDeh\") == \"peZMSACltYTzDeh\"" ]
def check(candidate): # Check some simple cases assert remove_whitespaces(' Google Flutter ') == 'GoogleFlutter' assert remove_whitespaces(' Google Dart ') == 'GoogleDart' assert remove_whitespaces(' iOS Swift ') == 'iOSSwift'
452
Write a function that gives loss amount if the given amount has loss else return none.
loss_amount
def loss_amount(actual_cost,sale_amount): if(sale_amount > actual_cost): amount = sale_amount - actual_cost return amount else: return None
[ "assert loss_amount(2039, 4290) == 2251", "assert loss_amount(2737, 5892) == 3155", "assert loss_amount(2312, 4931) == 2619" ]
def check(candidate): # Check some simple cases assert loss_amount(1500,1200)==None assert loss_amount(100,200)==100 assert loss_amount(2000,5000)==3000
453
Write a python function to find the sum of even factors of a number.
sumofFactors
import math def sumofFactors(n) : if (n % 2 != 0) : return 0 res = 1 for i in range(2, (int)(math.sqrt(n)) + 1) : count = 0 curr_sum = 1 curr_term = 1 while (n % i == 0) : count= count + 1 n = n // i if (i == 2 and count == 1) : curr_sum = 0 curr_term = curr_term * i curr_sum = curr_sum + curr_term res = res * curr_sum if (n >= 2) : res = res * (1 + n) return res
[ "assert sumofFactors(5) == 0", "assert sumofFactors(8) == 14", "assert sumofFactors(8) == 14" ]
def check(candidate): # Check some simple cases assert sumofFactors(18) == 26 assert sumofFactors(30) == 48 assert sumofFactors(6) == 8
454
Write a function that matches a word containing 'z'.
text_match_wordz
import re def text_match_wordz(text): patterns = '\w*z.\w*' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
[ "assert text_match_wordz(\"jtwybh\") == \"Not matched!\"", "assert text_match_wordz(\"pivuxfcx..mrl.\") == \"Not matched!\"", "assert text_match_wordz(\"hzkbpyk\") == \"Found a match!\"" ]
def check(candidate): # Check some simple cases assert text_match_wordz("pythonz.")==('Found a match!') assert text_match_wordz("xyz.")==('Found a match!') assert text_match_wordz(" lang .")==('Not matched!')
455
Write a function to check whether the given month number contains 31 days or not.
check_monthnumb_number
def check_monthnumb_number(monthnum2): if(monthnum2==1 or monthnum2==3 or monthnum2==5 or monthnum2==7 or monthnum2==8 or monthnum2==10 or monthnum2==12): return True else: return False
[ "assert check_monthnumb_number(3) == True", "assert check_monthnumb_number(2) == False", "assert check_monthnumb_number(1) == True" ]
def check(candidate): # Check some simple cases assert check_monthnumb_number(5)==True assert check_monthnumb_number(2)==False assert check_monthnumb_number(6)==False
456
Write a function to reverse strings in a given list of string values.
reverse_string_list
def reverse_string_list(stringlist): result = [x[::-1] for x in stringlist] return result
[ "assert reverse_string_list(['fzco', 'vzrpmbof', 'ekyiwcd']) == ['oczf', 'fobmprzv', 'dcwiyke']", "assert reverse_string_list(['yuhgq', 'zkslxio', 'ufitwck']) == ['qghuy', 'oixlskz', 'kcwtifu']", "assert reverse_string_list(['tdqrdh', 'waf', 'ggcotcnh']) == ['hdrqdt', 'faw', 'hnctocgg']" ]
def check(candidate): # Check some simple cases assert reverse_string_list(['Red', 'Green', 'Blue', 'White', 'Black'])==['deR', 'neerG', 'eulB', 'etihW', 'kcalB'] assert reverse_string_list(['john','amal','joel','george'])==['nhoj','lama','leoj','egroeg'] assert reverse_string_list(['jack','john','mary'])==['kcaj','nhoj','yram']
457
Write a python function to find the sublist having minimum length.
Find_Min
def Find_Min(lst): minList = min((x) for x in lst) return minList
[ "assert Find_Min([['c'], ['e', 'h'], ['j', 'j', 'q']]) == ['c']", "assert Find_Min([['v'], ['s', 'w'], ['f', 'm', 'f']]) == ['f', 'm', 'f']", "assert Find_Min([['n'], ['t', 'g'], ['i', 'c', 'w']]) == ['i', 'c', 'w']" ]
def check(candidate): # Check some simple cases assert Find_Min([[1],[1,2],[1,2,3]]) == [1] assert Find_Min([[1,1],[1,1,1],[1,2,7,8]]) == [1,1] assert Find_Min([['x'],['x','y'],['x','y','z']]) == ['x']
458
Write a function to find the area of a rectangle.
rectangle_area
def rectangle_area(l,b): area=l*b return area
[ "assert rectangle_area(9, 1) == 9", "assert rectangle_area(3, 7) == 21", "assert rectangle_area(5, 4) == 20" ]
def check(candidate): # Check some simple cases assert rectangle_area(10,20)==200 assert rectangle_area(10,5)==50 assert rectangle_area(4,2)==8
459
Write a function to remove uppercase substrings from a given string by using regex.
remove_uppercase
import re def remove_uppercase(str1): remove_upper = lambda text: re.sub('[A-Z]', '', text) result = remove_upper(str1) return (result)
[ "assert remove_uppercase(\"bSatOmcokwnJGFoBMXjQHpzSkPvmFOwe\") == \"batmcokwnojpzkvmwe\"", "assert remove_uppercase(\"AKYhcjLnFPJBmRECGlnFGrxMHNxw\") == \"hcjnmlnrxxw\"", "assert remove_uppercase(\"CDfCCdKNIbxMdSBAvlTJMnLo\") == \"fdbxdvlno\"" ]
def check(candidate): # Check some simple cases assert remove_uppercase('cAstyoUrFavoRitETVshoWs') == 'cstyoravoitshos' assert remove_uppercase('wAtchTheinTernEtrAdIo') == 'wtchheinerntrdo' assert remove_uppercase('VoicESeaRchAndreComMendaTionS') == 'oiceachndreomendaion'
460
Write a python function to get the first element of each sublist.
Extract
def Extract(lst): return [item[0] for item in lst]
[ "assert Extract([[5, 5, 1], [4, 3]]) == [5, 4]", "assert Extract([[8, 13, 1], [5, 4]]) == [8, 5]", "assert Extract([[9, 3, 5], [3, 1]]) == [9, 3]" ]
def check(candidate): # Check some simple cases assert Extract([[1, 2], [3, 4, 5], [6, 7, 8, 9]]) == [1, 3, 6] assert Extract([[1,2,3],[4, 5]]) == [1,4] assert Extract([[9,8,1],[1,2]]) == [9,1]
461
Write a python function to count the upper case characters in a given string.
upper_ctr
def upper_ctr(str): upper_ctr = 0 for i in range(len(str)): if str[i] >= 'A' and str[i] <= 'Z': upper_ctr += 1 return upper_ctr
[ "assert upper_ctr(\"ftpkepgjow\") == 0", "assert upper_ctr(\"autq\") == 0", "assert upper_ctr(\"xcjrnm\") == 0" ]
def check(candidate): # Check some simple cases assert upper_ctr('PYthon') == 1 assert upper_ctr('BigData') == 1 assert upper_ctr('program') == 0
462
Write a function to find all possible combinations of the elements of a given list.
combinations_list
def combinations_list(list1): if len(list1) == 0: return [[]] result = [] for el in combinations_list(list1[1:]): result += [el, el+[list1[0]]] return result
[ "assert combinations_list(['yvioxcydk', 'glivn', 'xtjbwd', 'gcvptgrbrwf']) == [[], ['yvioxcydk'], ['glivn'], ['glivn', 'yvioxcydk'], ['xtjbwd'], ['xtjbwd', 'yvioxcydk'], ['xtjbwd', 'glivn'], ['xtjbwd', 'glivn', 'yvioxcydk'], ['gcvptgrbrwf'], ['gcvptgrbrwf', 'yvioxcydk'], ['gcvptgrbrwf', 'glivn'], ['gcvptgrbrwf', 'glivn', 'yvioxcydk'], ['gcvptgrbrwf', 'xtjbwd'], ['gcvptgrbrwf', 'xtjbwd', 'yvioxcydk'], ['gcvptgrbrwf', 'xtjbwd', 'glivn'], ['gcvptgrbrwf', 'xtjbwd', 'glivn', 'yvioxcydk']]", "assert combinations_list(['vop', 'yxbjxnxm', 'qej', 'gsl']) == [[], ['vop'], ['yxbjxnxm'], ['yxbjxnxm', 'vop'], ['qej'], ['qej', 'vop'], ['qej', 'yxbjxnxm'], ['qej', 'yxbjxnxm', 'vop'], ['gsl'], ['gsl', 'vop'], ['gsl', 'yxbjxnxm'], ['gsl', 'yxbjxnxm', 'vop'], ['gsl', 'qej'], ['gsl', 'qej', 'vop'], ['gsl', 'qej', 'yxbjxnxm'], ['gsl', 'qej', 'yxbjxnxm', 'vop']]", "assert combinations_list(['jjjxlu', 'eaa', 'eja', 'hnmrxy']) == [[], ['jjjxlu'], ['eaa'], ['eaa', 'jjjxlu'], ['eja'], ['eja', 'jjjxlu'], ['eja', 'eaa'], ['eja', 'eaa', 'jjjxlu'], ['hnmrxy'], ['hnmrxy', 'jjjxlu'], ['hnmrxy', 'eaa'], ['hnmrxy', 'eaa', 'jjjxlu'], ['hnmrxy', 'eja'], ['hnmrxy', 'eja', 'jjjxlu'], ['hnmrxy', 'eja', 'eaa'], ['hnmrxy', 'eja', 'eaa', 'jjjxlu']]" ]
def check(candidate): # Check some simple cases assert combinations_list(['orange', 'red', 'green', 'blue'])==[[], ['orange'], ['red'], ['red', 'orange'], ['green'], ['green', 'orange'], ['green', 'red'], ['green', 'red', 'orange'], ['blue'], ['blue', 'orange'], ['blue', 'red'], ['blue', 'red', 'orange'], ['blue', 'green'], ['blue', 'green', 'orange'], ['blue', 'green', 'red'], ['blue', 'green', 'red', 'orange']] assert combinations_list(['red', 'green', 'blue', 'white', 'black', 'orange'])==[[], ['red'], ['green'], ['green', 'red'], ['blue'], ['blue', 'red'], ['blue', 'green'], ['blue', 'green', 'red'], ['white'], ['white', 'red'], ['white', 'green'], ['white', 'green', 'red'], ['white', 'blue'], ['white', 'blue', 'red'], ['white', 'blue', 'green'], ['white', 'blue', 'green', 'red'], ['black'], ['black', 'red'], ['black', 'green'], ['black', 'green', 'red'], ['black', 'blue'], ['black', 'blue', 'red'], ['black', 'blue', 'green'], ['black', 'blue', 'green', 'red'], ['black', 'white'], ['black', 'white', 'red'], ['black', 'white', 'green'], ['black', 'white', 'green', 'red'], ['black', 'white', 'blue'], ['black', 'white', 'blue', 'red'], ['black', 'white', 'blue', 'green'], ['black', 'white', 'blue', 'green', 'red'], ['orange'], ['orange', 'red'], ['orange', 'green'], ['orange', 'green', 'red'], ['orange', 'blue'], ['orange', 'blue', 'red'], ['orange', 'blue', 'green'], ['orange', 'blue', 'green', 'red'], ['orange', 'white'], ['orange', 'white', 'red'], ['orange', 'white', 'green'], ['orange', 'white', 'green', 'red'], ['orange', 'white', 'blue'], ['orange', 'white', 'blue', 'red'], ['orange', 'white', 'blue', 'green'], ['orange', 'white', 'blue', 'green', 'red'], ['orange', 'black'], ['orange', 'black', 'red'], ['orange', 'black', 'green'], ['orange', 'black', 'green', 'red'], ['orange', 'black', 'blue'], ['orange', 'black', 'blue', 'red'], ['orange', 'black', 'blue', 'green'], ['orange', 'black', 'blue', 'green', 'red'], ['orange', 'black', 'white'], ['orange', 'black', 'white', 'red'], ['orange', 'black', 'white', 'green'], ['orange', 'black', 'white', 'green', 'red'], ['orange', 'black', 'white', 'blue'], ['orange', 'black', 'white', 'blue', 'red'], ['orange', 'black', 'white', 'blue', 'green'], ['orange', 'black', 'white', 'blue', 'green', 'red']] assert combinations_list(['red', 'green', 'black', 'orange'])==[[], ['red'], ['green'], ['green', 'red'], ['black'], ['black', 'red'], ['black', 'green'], ['black', 'green', 'red'], ['orange'], ['orange', 'red'], ['orange', 'green'], ['orange', 'green', 'red'], ['orange', 'black'], ['orange', 'black', 'red'], ['orange', 'black', 'green'], ['orange', 'black', 'green', 'red']]
463
Write a function to find the maximum product subarray of the given array.
max_subarray_product
def max_subarray_product(arr): n = len(arr) max_ending_here = 1 min_ending_here = 1 max_so_far = 0 flag = 0 for i in range(0, n): if arr[i] > 0: max_ending_here = max_ending_here * arr[i] min_ending_here = min (min_ending_here * arr[i], 1) flag = 1 elif arr[i] == 0: max_ending_here = 1 min_ending_here = 1 else: temp = max_ending_here max_ending_here = max (min_ending_here * arr[i], 1) min_ending_here = temp * arr[i] if (max_so_far < max_ending_here): max_so_far = max_ending_here if flag == 0 and max_so_far == 0: return 0 return max_so_far
[ "assert max_subarray_product([-5, -35, 3, -4, -1]) == 2100", "assert max_subarray_product([-1, -36, 2, -6, -2]) == 864", "assert max_subarray_product([3, -38, 4, -2, 2]) == 1824" ]
def check(candidate): # Check some simple cases assert max_subarray_product([1, -2, -3, 0, 7, -8, -2]) == 112 assert max_subarray_product([6, -3, -10, 0, 2]) == 180 assert max_subarray_product([-2, -40, 0, -2, -3]) == 80
464
Write a function to check if all values are same in a dictionary.
check_value
def check_value(dict, n): result = all(x == n for x in dict.values()) return result
[ "assert check_value({'nBhGWwRLepobafw': 8, 'KcrnHAAIvWfupi': 9, 'NiUiFZ yPjmDVhaQJ': 17, 'QoZPUQfLfJap': 16}, 10) == False", "assert check_value({'BGiCtwSnuWlz': 15, 'ywWCGiJOfFNYECm': 17, 'VnGMiIILSmJaP': 15, 'jskekS': 15}, 9) == False", "assert check_value({'nxVOJn PjrFZkxw': 15, 'cJhPETnpIGjgJ': 15, 'jPkewyESCF': 11, 'yWfgzMQVnTIkyt': 14}, 4) == False" ]
def check(candidate): # Check some simple cases assert check_value({'Cierra Vega': 12, 'Alden Cantrell': 12, 'Kierra Gentry': 12, 'Pierre Cox': 12},10)==False assert check_value({'Cierra Vega': 12, 'Alden Cantrell': 12, 'Kierra Gentry': 12, 'Pierre Cox': 12},12)==True assert check_value({'Cierra Vega': 12, 'Alden Cantrell': 12, 'Kierra Gentry': 12, 'Pierre Cox': 12},5)==False
465
Write a function to drop empty items from a given dictionary.
drop_empty
def drop_empty(dict1): dict1 = {key:value for (key, value) in dict1.items() if value is not None} return dict1
[ "assert drop_empty({'7zvv': None, 'bbk2b': 'nKapd', 'am3wm': None}) == {'bbk2b': 'nKapd'}", "assert drop_empty({'ac7f': None, 'pnswq': 'dvqtDq', 'ct6': None}) == {'pnswq': 'dvqtDq'}", "assert drop_empty({'qks3': None, '10kmil': 'qcJwPG', '53r1': None}) == {'10kmil': 'qcJwPG'}" ]
def check(candidate): # Check some simple cases assert drop_empty({'c1': 'Red', 'c2': 'Green', 'c3':None})=={'c1': 'Red', 'c2': 'Green'} assert drop_empty({'c1': 'Red', 'c2': None, 'c3':None})=={'c1': 'Red'} assert drop_empty({'c1': None, 'c2': 'Green', 'c3':None})=={ 'c2': 'Green'}
466
Write a function to find the peak element in the given array.
find_peak
def find_peak_util(arr, low, high, n): mid = low + (high - low)/2 mid = int(mid) if ((mid == 0 or arr[mid - 1] <= arr[mid]) and (mid == n - 1 or arr[mid + 1] <= arr[mid])): return mid elif (mid > 0 and arr[mid - 1] > arr[mid]): return find_peak_util(arr, low, (mid - 1), n) else: return find_peak_util(arr, (mid + 1), high, n) def find_peak(arr, n): return find_peak_util(arr, 0, n - 1, n)
[ "assert find_peak([13, 6, 10, 7, 13, 15], 8) == 0", "assert find_peak([9, 10, 16, 17, 11, 12], 8) == 3", "assert find_peak([3, 8, 8, 10, 16, 17], 2) == 1" ]
def check(candidate): # Check some simple cases assert find_peak([1, 3, 20, 4, 1, 0], 6) == 2 assert find_peak([2, 3, 4, 5, 6], 5) == 4 assert find_peak([8, 9, 11, 12, 14, 15], 6) == 5
467
Write a python function to convert decimal number to octal number.
decimal_to_Octal
def decimal_to_Octal(deciNum): octalNum = 0 countval = 1; dNo = deciNum; while (deciNum!= 0): remainder= deciNum % 8; octalNum+= remainder*countval; countval= countval*10; deciNum //= 8; return (octalNum)
[ "assert decimal_to_Octal(30) == 36", "assert decimal_to_Octal(32) == 40", "assert decimal_to_Octal(31) == 37" ]
def check(candidate): # Check some simple cases assert decimal_to_Octal(10) == 12 assert decimal_to_Octal(2) == 2 assert decimal_to_Octal(33) == 41
468
Write a function to find the maximum product formed by multiplying numbers of an increasing subsequence of that array.
max_product
def max_product(arr, n ): mpis =[0] * (n) for i in range(n): mpis[i] = arr[i] for i in range(1, n): for j in range(i): if (arr[i] > arr[j] and mpis[i] < (mpis[j] * arr[i])): mpis[i] = mpis[j] * arr[i] return max(mpis)
[ "assert max_product([11, 21, 9, 38, 22, 47, 44, 57], 6) == 412566", "assert max_product([8, 22, 8, 28, 26, 50, 39, 63], 3) == 176", "assert max_product([10, 22, 12, 29, 25, 46, 45, 62], 8) == 18195760" ]
def check(candidate): # Check some simple cases assert max_product([3, 100, 4, 5, 150, 6], 6) == 45000 assert max_product([4, 42, 55, 68, 80], 5) == 50265600 assert max_product([10, 22, 9, 33, 21, 50, 41, 60], 8) == 21780000
469
Write a function to find the maximum profit earned from a maximum of k stock transactions
max_profit
def max_profit(price, k): n = len(price) final_profit = [[None for x in range(n)] for y in range(k + 1)] for i in range(k + 1): for j in range(n): if i == 0 or j == 0: final_profit[i][j] = 0 else: max_so_far = 0 for x in range(j): curr_price = price[j] - price[x] + final_profit[i-1][x] if max_so_far < curr_price: max_so_far = curr_price final_profit[i][j] = max(final_profit[i][j-1], max_so_far) return final_profit[k][n-1]
[ "assert max_profit([6, 1, 6, 6, 4], 3) == 5", "assert max_profit([6, 3, 12, 8, 4], 2) == 9", "assert max_profit([15, 8, 13, 2, 6], 6) == 9" ]
def check(candidate): # Check some simple cases assert max_profit([1, 5, 2, 3, 7, 6, 4, 5], 3) == 10 assert max_profit([2, 4, 7, 5, 4, 3, 5], 2) == 7 assert max_profit([10, 6, 8, 4, 2], 2) == 2
470
Write a function to find the pairwise addition of the elements of the given tuples.
add_pairwise
def add_pairwise(test_tup): res = tuple(i + j for i, j in zip(test_tup, test_tup[1:])) return (res)
[ "assert add_pairwise((8, 11, 13, 15, 14)) == (19, 24, 28, 29)", "assert add_pairwise((8, 11, 4, 7, 12)) == (19, 15, 11, 19)", "assert add_pairwise((5, 2, 12, 13, 7)) == (7, 14, 25, 20)" ]
def check(candidate): # Check some simple cases assert add_pairwise((1, 5, 7, 8, 10)) == (6, 12, 15, 18) assert add_pairwise((2, 6, 8, 9, 11)) == (8, 14, 17, 20) assert add_pairwise((3, 7, 9, 10, 12)) == (10, 16, 19, 22)
471
Write a python function to find remainder of array multiplication divided by n.
find_remainder
def find_remainder(arr, lens, n): mul = 1 for i in range(lens): mul = (mul * (arr[i] % n)) % n return mul % n
[ "assert find_remainder([5, 4, 2], 1, 4) == 1", "assert find_remainder([1, 4, 4], 3, 1) == 0", "assert find_remainder([3, 4, 3], 3, 2) == 0" ]
def check(candidate): # Check some simple cases assert find_remainder([ 100, 10, 5, 25, 35, 14 ],6,11) ==9 assert find_remainder([1,1,1],3,1) == 0 assert find_remainder([1,2,1],3,2) == 0
472
Write a python function to check whether the given list contains consecutive numbers or not.
check_Consecutive
def check_Consecutive(l): return sorted(l) == list(range(min(l),max(l)+1))
[ "assert check_Consecutive([5, 7, 1]) == False", "assert check_Consecutive([5, 7, 3]) == False", "assert check_Consecutive([2, 1, 4]) == False" ]
def check(candidate): # Check some simple cases assert check_Consecutive([1,2,3,4,5]) == True assert check_Consecutive([1,2,3,5,6]) == False assert check_Consecutive([1,2,1]) == False
473
Write a function to find the tuple intersection of elements in the given tuple list irrespective of their order.
tuple_intersection
def tuple_intersection(test_list1, test_list2): res = set([tuple(sorted(ele)) for ele in test_list1]) & set([tuple(sorted(ele)) for ele in test_list2]) return (res)
[ "assert tuple_intersection([(4, 4), (4, 7), (3, 6), (4, 5)], [(14, 1), (7, 1), (3, 5), (2, 3)]) == set()", "assert tuple_intersection([(1, 1), (4, 3), (4, 4), (1, 9)], [(8, 1), (7, 2), (2, 1), (6, 7)]) == set()", "assert tuple_intersection([(7, 6), (2, 4), (3, 2), (3, 7)], [(6, 5), (4, 8), (3, 7), (3, 5)]) == {(3, 7)}" ]
def check(candidate): # Check some simple cases assert tuple_intersection([(3, 4), (5, 6), (9, 10), (4, 5)] , [(5, 4), (3, 4), (6, 5), (9, 11)]) == {(4, 5), (3, 4), (5, 6)} assert tuple_intersection([(4, 1), (7, 4), (11, 13), (17, 14)] , [(1, 4), (7, 4), (16, 12), (10, 13)]) == {(4, 7), (1, 4)} assert tuple_intersection([(2, 1), (3, 2), (1, 3), (1, 4)] , [(11, 2), (2, 3), (6, 2), (1, 3)]) == {(1, 3), (2, 3)}
474
Write a function to replace characters in a string.
replace_char
def replace_char(str1,ch,newch): str2 = str1.replace(ch, newch) return str2
[ "assert replace_char('zkc', 'f', 'a') == \"zkc\"", "assert replace_char('ivm', 'a', 'v') == \"ivm\"", "assert replace_char('hvox', 'b', 'o') == \"hvox\"" ]
def check(candidate): # Check some simple cases assert replace_char("polygon",'y','l')==("pollgon") assert replace_char("character",'c','a')==("aharaater") assert replace_char("python",'l','a')==("python")
475
Write a function to sort counter by value.
sort_counter
from collections import Counter def sort_counter(dict1): x = Counter(dict1) sort_counter=x.most_common() return sort_counter
[ "assert sort_counter({'wByeBL': 897, 'MERWmhgOVKW': 996, 'eUxEWwQBh': 351}) == [('MERWmhgOVKW', 996), ('wByeBL', 897), ('eUxEWwQBh', 351)]", "assert sort_counter({'qbZERPqZ': 895, 'LVjCBBZmbiMh': 1003, 'fAwNDh': 742}) == [('LVjCBBZmbiMh', 1003), ('qbZERPqZ', 895), ('fAwNDh', 742)]", "assert sort_counter({'uAkxvYJG': 899, 'MLd': 1000, 'chYCKOzFknpqVEk': 1645}) == [('chYCKOzFknpqVEk', 1645), ('MLd', 1000), ('uAkxvYJG', 899)]" ]
def check(candidate): # Check some simple cases assert sort_counter({'Math':81, 'Physics':83, 'Chemistry':87})==[('Chemistry', 87), ('Physics', 83), ('Math', 81)] assert sort_counter({'Math':400, 'Physics':300, 'Chemistry':250})==[('Math', 400), ('Physics', 300), ('Chemistry', 250)] assert sort_counter({'Math':900, 'Physics':1000, 'Chemistry':1250})==[('Chemistry', 1250), ('Physics', 1000), ('Math', 900)]
476
Write a python function to find the sum of the largest and smallest value in a given array.
big_sum
def big_sum(nums): sum= max(nums)+min(nums) return sum
[ "assert big_sum([6, 2, 8]) == 10", "assert big_sum([1, 3, 2]) == 4", "assert big_sum([6, 1, 10]) == 11" ]
def check(candidate): # Check some simple cases assert big_sum([1,2,3]) == 4 assert big_sum([-1,2,3,4]) == 3 assert big_sum([2,3,6]) == 8
477
Write a python function to convert the given string to lower case.
is_lower
def is_lower(string): return (string.lower())
[ "assert is_lower(\"xvcff\") == \"xvcff\"", "assert is_lower(\"UQkdVQcQv\") == \"uqkdvqcqv\"", "assert is_lower(\"sLxBJ\") == \"slxbj\"" ]
def check(candidate): # Check some simple cases assert is_lower("InValid") == "invalid" assert is_lower("TruE") == "true" assert is_lower("SenTenCE") == "sentence"
478
Write a function to remove lowercase substrings from a given string.
remove_lowercase
import re def remove_lowercase(str1): remove_lower = lambda text: re.sub('[a-z]', '', text) result = remove_lower(str1) return result
[ "assert remove_lowercase(\"UbGvHPFjikuE\") == \"UGHPFE\"", "assert remove_lowercase(\"eijlhqjIa\") == \"I\"", "assert remove_lowercase(\"cclGeHTXUK\") == \"GHTXUK\"" ]
def check(candidate): # Check some simple cases assert remove_lowercase("PYTHon")==('PYTH') assert remove_lowercase("FInD")==('FID') assert remove_lowercase("STRinG")==('STRG')
479
Write a python function to find the first digit of a given number.
first_Digit
def first_Digit(n) : while n >= 10: n = n / 10; return int(n)
[ "assert first_Digit(8) == 8", "assert first_Digit(17) == 1", "assert first_Digit(12) == 1" ]
def check(candidate): # Check some simple cases assert first_Digit(123) == 1 assert first_Digit(456) == 4 assert first_Digit(12) == 1
480
Write a python function to find the maximum occurring character in a given string.
get_max_occuring_char
def get_max_occuring_char(str1): ASCII_SIZE = 256 ctr = [0] * ASCII_SIZE max = -1 ch = '' for i in str1: ctr[ord(i)]+=1; for i in str1: if max < ctr[ord(i)]: max = ctr[ord(i)] ch = i return ch
[ "assert get_max_occuring_char(\"qwniuwqdld\") == q", "assert get_max_occuring_char(\"czwjkjojkoznde\") == j", "assert get_max_occuring_char(\"jsk qrdblfgeheetet\") == e" ]
def check(candidate): # Check some simple cases assert get_max_occuring_char("data") == "a" assert get_max_occuring_char("create") == "e" assert get_max_occuring_char("brilliant girl") == "i"
481
Write a function to determine if there is a subset of the given set with sum equal to the given sum.
is_subset_sum
def is_subset_sum(set, n, sum): if (sum == 0): return True if (n == 0): return False if (set[n - 1] > sum): return is_subset_sum(set, n - 1, sum) return is_subset_sum(set, n-1, sum) or is_subset_sum(set, n-1, sum-set[n-1])
[ "assert is_subset_sum([8, 33, 6, 8, 5, 7], 1, 11) == False", "assert is_subset_sum([5, 29, 5, 16, 3, 6], 2, 11) == False", "assert is_subset_sum([4, 34, 9, 8, 5, 7], 3, 13) == True" ]
def check(candidate): # Check some simple cases assert is_subset_sum([3, 34, 4, 12, 5, 2], 6, 9) == True assert is_subset_sum([3, 34, 4, 12, 5, 2], 6, 30) == False assert is_subset_sum([3, 34, 4, 12, 5, 2], 6, 15) == True
482
Write a function to find sequences of one upper case letter followed by lower case letters in the given string by using regex.
match
import re def match(text): pattern = '[A-Z]+[a-z]+$' if re.search(pattern, text): return('Yes') else: return('No')
[ "assert match(\"uwb\") == No", "assert match(\"orupanxey\") == No", "assert match(\"heguj\") == No" ]
def check(candidate): # Check some simple cases assert match("Geeks") == 'Yes' assert match("geeksforGeeks") == 'Yes' assert match("geeks") == 'No'
483
Write a python function to find the first natural number whose factorial is divisible by x.
first_Factorial_Divisible_Number
def first_Factorial_Divisible_Number(x): i = 1; fact = 1; for i in range(1,x): fact = fact * i if (fact % x == 0): break return i
[ "assert first_Factorial_Divisible_Number(6) == 3", "assert first_Factorial_Divisible_Number(6) == 3", "assert first_Factorial_Divisible_Number(9) == 6" ]
def check(candidate): # Check some simple cases assert first_Factorial_Divisible_Number(10) == 5 assert first_Factorial_Divisible_Number(15) == 5 assert first_Factorial_Divisible_Number(5) == 4
484
Write a function to remove the matching tuples from the given two tuples.
remove_matching_tuple
def remove_matching_tuple(test_list1, test_list2): res = [sub for sub in test_list1 if sub not in test_list2] return (res)
[ "assert remove_matching_tuple([('Uzotw', 'msclbi'), ('y', 'oofjryzn'), ('hhvkflw', 'jgmjecgcz')], [('u', 'mqpxojwp'), ('hnul', 'aqensmfprsoi')]) == [('Uzotw', 'msclbi'), ('y', 'oofjryzn'), ('hhvkflw', 'jgmjecgcz')]", "assert remove_matching_tuple([('TPKXdAo', 'fywv'), ('g', 'tdnspbgb'), ('afkxp', 'hlbk')], [('j', 'lorkaxzmo'), ('dlurx', 'paesgikk')]) == [('TPKXdAo', 'fywv'), ('g', 'tdnspbgb'), ('afkxp', 'hlbk')]", "assert remove_matching_tuple([('HmnPt', 'wsakm'), ('s', 'floztfugy'), ('buasddno', 'fdvtvgbnzgj')], [('l', 'pjsmivr'), ('oru', 'xpspgg')]) == [('HmnPt', 'wsakm'), ('s', 'floztfugy'), ('buasddno', 'fdvtvgbnzgj')]" ]
def check(candidate): # Check some simple cases assert remove_matching_tuple([('Hello', 'dude'), ('How', 'are'), ('you', '?')], [('Hello', 'dude'), ('How', 'are')]) == [('you', '?')] assert remove_matching_tuple([('Part', 'of'), ('the', 'journey'), ('is ', 'end')], [('Journey', 'the'), ('is', 'end')]) == [('Part', 'of'), ('the', 'journey'), ('is ', 'end')] assert remove_matching_tuple([('Its', 'been'), ('a', 'long'), ('day', 'without')], [('a', 'long'), ('my', 'friend')]) == [('Its', 'been'), ('day', 'without')]
485
Write a function to find the largest palindromic number in the given array.
largest_palindrome
def is_palindrome(n) : divisor = 1 while (n / divisor >= 10) : divisor *= 10 while (n != 0) : leading = n // divisor trailing = n % 10 if (leading != trailing) : return False n = (n % divisor) // 10 divisor = divisor // 100 return True def largest_palindrome(A, n) : A.sort() for i in range(n - 1, -1, -1) : if (is_palindrome(A[i])) : return A[i] return -1
[ "assert largest_palindrome([6, 2, 2, 11, 45], 1) == 2", "assert largest_palindrome([1, 3, 7, 12, 44], 1) == 1", "assert largest_palindrome([4, 4, 12, 13, 50], 2) == 4" ]
def check(candidate): # Check some simple cases assert largest_palindrome([1, 232, 54545, 999991], 4) == 54545 assert largest_palindrome([1, 2, 3, 4, 5, 50], 6) == 5 assert largest_palindrome([1, 3, 7, 9, 45], 5) == 9
486
Write a function to compute binomial probability for the given number.
binomial_probability
def nCr(n, r): if (r > n / 2): r = n - r answer = 1 for i in range(1, r + 1): answer *= (n - r + i) answer /= i return answer def binomial_probability(n, k, p): return (nCr(n, k) * pow(p, k) * pow(1 - p, n - k))
[ "assert binomial_probability(7, 11, 2.8752752771382184) == 8978.703263233458", "assert binomial_probability(10, 9, 5.413294840870316) == -176164372.3934158", "assert binomial_probability(14, 10, 3.9927968017481144) == 82701824682.39813" ]
def check(candidate): # Check some simple cases assert binomial_probability(10, 5, 1.0/3) == 0.13656454808718185 assert binomial_probability(11, 6, 2.0/4) == 0.2255859375 assert binomial_probability(12, 7, 3.0/5) == 0.227030335488
487
Write a function to sort a list of tuples in increasing order by the last element in each tuple.
sort_tuple
def sort_tuple(tup): lst = len(tup) for i in range(0, lst): for j in range(0, lst-i-1): if (tup[j][-1] > tup[j + 1][-1]): temp = tup[j] tup[j]= tup[j + 1] tup[j + 1]= temp return tup
[ "assert sort_tuple([(4, 12), (11, 4), (3, 2)]) == [(3, 2), (11, 4), (4, 12)]", "assert sort_tuple([(6, 11), (4, 11), (7, 6)]) == [(7, 6), (6, 11), (4, 11)]", "assert sort_tuple([(1, 12), (8, 4), (2, 8)]) == [(8, 4), (2, 8), (1, 12)]" ]
def check(candidate): # Check some simple cases assert sort_tuple([(1, 3), (3, 2), (2, 1)] ) == [(2, 1), (3, 2), (1, 3)] assert sort_tuple([(2, 4), (3, 3), (1, 1)] ) == [(1, 1), (3, 3), (2, 4)] assert sort_tuple([(3, 9), (6, 7), (4, 3)] ) == [(4, 3), (6, 7), (3, 9)]
488
Write a function to find the area of a pentagon.
area_pentagon
import math def area_pentagon(a): area=(math.sqrt(5*(5+2*math.sqrt(5)))*pow(a,2))/4.0 return area
[ "assert area_pentagon(19) == 621.092341612617", "assert area_pentagon(14) == 337.21357051543754", "assert area_pentagon(17) == 497.2179687702114" ]
def check(candidate): # Check some simple cases assert area_pentagon(5)==43.01193501472417 assert area_pentagon(10)==172.0477400588967 assert area_pentagon(15)==387.10741513251753
489
Write a python function to find the frequency of the largest value in a given array.
frequency_Of_Largest
def frequency_Of_Largest(n,arr): mn = arr[0] freq = 1 for i in range(1,n): if (arr[i] >mn): mn = arr[i] freq = 1 elif (arr[i] == mn): freq += 1 return freq
[ "assert frequency_Of_Largest(4, [4, 2, 7, 9]) == 1", "assert frequency_Of_Largest(3, [7, 3, 2, 2]) == 1", "assert frequency_Of_Largest(3, [6, 2, 11, 7]) == 1" ]
def check(candidate): # Check some simple cases assert frequency_Of_Largest(5,[1,2,3,4,4]) == 2 assert frequency_Of_Largest(3,[5,6,5]) == 1 assert frequency_Of_Largest(4,[2,7,7,7]) == 3
490
Write a function to extract all the pairs which are symmetric in the given tuple list.
extract_symmetric
def extract_symmetric(test_list): temp = set(test_list) & {(b, a) for a, b in test_list} res = {(a, b) for a, b in temp if a < b} return (res)
[ "assert extract_symmetric([(8, 12), (9, 2), (4, 10), (10, 15), (10, 3), (11, 14)]) == set()", "assert extract_symmetric([(3, 11), (9, 2), (10, 3), (12, 14), (12, 8), (7, 15)]) == set()", "assert extract_symmetric([(13, 10), (5, 6), (5, 5), (6, 7), (16, 4), (7, 16)]) == set()" ]
def check(candidate): # Check some simple cases assert extract_symmetric([(6, 7), (2, 3), (7, 6), (9, 8), (10, 2), (8, 9)] ) == {(8, 9), (6, 7)} assert extract_symmetric([(7, 8), (3, 4), (8, 7), (10, 9), (11, 3), (9, 10)] ) == {(9, 10), (7, 8)} assert extract_symmetric([(8, 9), (4, 5), (9, 8), (11, 10), (12, 4), (10, 11)] ) == {(8, 9), (10, 11)}
491
Write a function to find the sum of geometric progression series.
sum_gp
import math def sum_gp(a,n,r): total = (a * (1 - math.pow(r, n ))) / (1- r) return total
[ "assert sum_gp(6, 6, 7) == 117648.0", "assert sum_gp(6, 8, 8) == 14380470.0", "assert sum_gp(2, 11, 3) == 177146.0" ]
def check(candidate): # Check some simple cases assert sum_gp(1,5,2)==31 assert sum_gp(1,5,4)==341 assert sum_gp(2,6,3)==728
492
Write a function to search an element in the given array by using binary search.
binary_search
def binary_search(item_list,item): first = 0 last = len(item_list)-1 found = False while( first<=last and not found): mid = (first + last)//2 if item_list[mid] == item : found = True else: if item < item_list[mid]: last = mid - 1 else: first = mid + 1 return found
[ "assert binary_search([8, 18, 16, 20, 24, 33], 26) == False", "assert binary_search([12, 16, 12, 20, 21, 41], 28) == False", "assert binary_search([6, 18, 17, 17, 27, 36], 24) == False" ]
def check(candidate): # Check some simple cases assert binary_search([1,2,3,5,8], 6) == False assert binary_search([7, 8, 9, 10, 13], 10) == True assert binary_search([11, 13, 14, 19, 22, 36], 23) == False
493
Write a function to calculate a grid of hexagon coordinates where function returns a list of lists containing 6 tuples of x, y point coordinates.
calculate_polygons
import math def calculate_polygons(startx, starty, endx, endy, radius): sl = (2 * radius) * math.tan(math.pi / 6) p = sl * 0.5 b = sl * math.cos(math.radians(30)) w = b * 2 h = 2 * sl startx = startx - w starty = starty - h endx = endx + w endy = endy + h origx = startx origy = starty xoffset = b yoffset = 3 * p polygons = [] row = 1 counter = 0 while starty < endy: if row % 2 == 0: startx = origx + xoffset else: startx = origx while startx < endx: p1x = startx p1y = starty + p p2x = startx p2y = starty + (3 * p) p3x = startx + b p3y = starty + h p4x = startx + w p4y = starty + (3 * p) p5x = startx + w p5y = starty + p p6x = startx + b p6y = starty poly = [ (p1x, p1y), (p2x, p2y), (p3x, p3y), (p4x, p4y), (p5x, p5y), (p6x, p6y), (p1x, p1y)] polygons.append(poly) counter += 1 startx += w starty += yoffset row += 1 return polygons
[ "assert calculate_polygons(5, 9, 5, 2, 6) == [[(-7.0, -1.3923048454132632), (-7.0, 5.5358983848622465), (-1.0, 9.0), (5.0, 5.5358983848622465), (5.0, -1.3923048454132632), (-1.0, -4.8564064605510175), (-7.0, -1.3923048454132632)], [(5.0, -1.3923048454132632), (5.0, 5.5358983848622465), (11.0, 9.0), (17.0, 5.5358983848622465), (17.0, -1.3923048454132632), (11.0, -4.8564064605510175), (5.0, -1.3923048454132632)], [(-1.0, 9.0), (-1.0, 15.92820323027551), (5.0, 19.392304845413264), (11.0, 15.92820323027551), (11.0, 9.0), (5.0, 5.5358983848622465), (-1.0, 9.0)], [(11.0, 9.0), (11.0, 15.92820323027551), (17.0, 19.392304845413264), (23.0, 15.92820323027551), (23.0, 9.0), (17.0, 5.5358983848622465), (11.0, 9.0)]]", "assert calculate_polygons(9, 1, 3, 8, 4) == [[(1.0, -5.928203230275509), (1.0, -1.309401076758503), (5.0, 1.0), (9.0, -1.309401076758503), (9.0, -5.928203230275509), (5.0, -8.237604307034012), (1.0, -5.928203230275509)], [(9.0, -5.928203230275509), (9.0, -1.309401076758503), (13.0, 1.0), (17.0, -1.309401076758503), (17.0, -5.928203230275509), (13.0, -8.237604307034012), (9.0, -5.928203230275509)], [(5.0, 1.0), (5.0, 5.618802153517006), (9.0, 7.928203230275509), (13.0, 5.618802153517006), (13.0, 1.0), (9.0, -1.309401076758503), (5.0, 1.0)], [(1.0, 7.928203230275509), (1.0, 12.547005383792515), (5.0, 14.856406460551018), (9.0, 12.547005383792515), (9.0, 7.928203230275509), (5.0, 5.618802153517006), (1.0, 7.928203230275509)], [(9.0, 7.928203230275509), (9.0, 12.547005383792515), (13.0, 14.856406460551018), (17.0, 12.547005383792515), (17.0, 7.928203230275509), (13.0, 5.618802153517006), (9.0, 7.928203230275509)], [(5.0, 14.856406460551018), (5.0, 19.475208614068023), (9.0, 21.784609690826528), (13.0, 19.475208614068023), (13.0, 14.856406460551018), (9.0, 12.547005383792515), (5.0, 14.856406460551018)]]", "assert calculate_polygons(13, 3, 5, 7, 6) == [[(1.0, -7.392304845413263), (1.0, -0.4641016151377535), (7.0, 3.0), (13.0, -0.4641016151377535), (13.0, -7.392304845413263), (7.0, -10.856406460551018), (1.0, -7.392304845413263)], [(13.0, -7.392304845413263), (13.0, -0.4641016151377535), (19.0, 3.0), (25.0, -0.4641016151377535), (25.0, -7.392304845413263), (19.0, -10.856406460551018), (13.0, -7.392304845413263)], [(7.0, 3.000000000000001), (7.0, 9.92820323027551), (13.0, 13.392304845413264), (19.0, 9.92820323027551), (19.0, 3.000000000000001), (13.0, -0.4641016151377535), (7.0, 3.000000000000001)], [(1.0, 13.392304845413264), (1.0, 20.320508075688775), (7.0, 23.784609690826528), (13.0, 20.320508075688775), (13.0, 13.392304845413264), (7.0, 9.92820323027551), (1.0, 13.392304845413264)], [(13.0, 13.392304845413264), (13.0, 20.320508075688775), (19.0, 23.784609690826528), (25.0, 20.320508075688775), (25.0, 13.392304845413264), (19.0, 9.92820323027551), (13.0, 13.392304845413264)], [(7.0, 23.784609690826528), (7.0, 30.71281292110204), (13.0, 34.17691453623979), (19.0, 30.71281292110204), (19.0, 23.784609690826528), (13.0, 20.320508075688775), (7.0, 23.784609690826528)]]" ]
def check(candidate): # Check some simple cases assert calculate_polygons(1,1, 4, 4, 3)==[[(-5.0, -4.196152422706632), (-5.0, -0.7320508075688767), (-2.0, 1.0), (1.0, -0.7320508075688767), (1.0, -4.196152422706632), (-2.0, -5.928203230275509), (-5.0, -4.196152422706632)], [(1.0, -4.196152422706632), (1.0, -0.7320508075688767), (4.0, 1.0), (7.0, -0.7320508075688767), (7.0, -4.196152422706632), (4.0, -5.928203230275509), (1.0, -4.196152422706632)], [(7.0, -4.196152422706632), (7.0, -0.7320508075688767), (10.0, 1.0), (13.0, -0.7320508075688767), (13.0, -4.196152422706632), (10.0, -5.928203230275509), (7.0, -4.196152422706632)], [(-2.0, 1.0000000000000004), (-2.0, 4.464101615137755), (1.0, 6.196152422706632), (4.0, 4.464101615137755), (4.0, 1.0000000000000004), (1.0, -0.7320508075688767), (-2.0, 1.0000000000000004)], [(4.0, 1.0000000000000004), (4.0, 4.464101615137755), (7.0, 6.196152422706632), (10.0, 4.464101615137755), (10.0, 1.0000000000000004), (7.0, -0.7320508075688767), (4.0, 1.0000000000000004)], [(-5.0, 6.196152422706632), (-5.0, 9.660254037844387), (-2.0, 11.392304845413264), (1.0, 9.660254037844387), (1.0, 6.196152422706632), (-2.0, 4.464101615137755), (-5.0, 6.196152422706632)], [(1.0, 6.196152422706632), (1.0, 9.660254037844387), (4.0, 11.392304845413264), (7.0, 9.660254037844387), (7.0, 6.196152422706632), (4.0, 4.464101615137755), (1.0, 6.196152422706632)], [(7.0, 6.196152422706632), (7.0, 9.660254037844387), (10.0, 11.392304845413264), (13.0, 9.660254037844387), (13.0, 6.196152422706632), (10.0, 4.464101615137755), (7.0, 6.196152422706632)], [(-2.0, 11.392304845413264), (-2.0, 14.85640646055102), (1.0, 16.588457268119896), (4.0, 14.85640646055102), (4.0, 11.392304845413264), (1.0, 9.660254037844387), (-2.0, 11.392304845413264)], [(4.0, 11.392304845413264), (4.0, 14.85640646055102), (7.0, 16.588457268119896), (10.0, 14.85640646055102), (10.0, 11.392304845413264), (7.0, 9.660254037844387), (4.0, 11.392304845413264)]] assert calculate_polygons(5,4,7,9,8)==[[(-11.0, -9.856406460551018), (-11.0, -0.6188021535170058), (-3.0, 4.0), (5.0, -0.6188021535170058), (5.0, -9.856406460551018), (-3.0, -14.475208614068023), (-11.0, -9.856406460551018)], [(5.0, -9.856406460551018), (5.0, -0.6188021535170058), (13.0, 4.0), (21.0, -0.6188021535170058), (21.0, -9.856406460551018), (13.0, -14.475208614068023), (5.0, -9.856406460551018)], [(21.0, -9.856406460551018), (21.0, -0.6188021535170058), (29.0, 4.0), (37.0, -0.6188021535170058), (37.0, -9.856406460551018), (29.0, -14.475208614068023), (21.0, -9.856406460551018)], [(-3.0, 4.0), (-3.0, 13.237604307034012), (5.0, 17.856406460551018), (13.0, 13.237604307034012), (13.0, 4.0), (5.0, -0.6188021535170058), (-3.0, 4.0)], [(13.0, 4.0), (13.0, 13.237604307034012), (21.0, 17.856406460551018), (29.0, 13.237604307034012), (29.0, 4.0), (21.0, -0.6188021535170058), (13.0, 4.0)], [(-11.0, 17.856406460551018), (-11.0, 27.09401076758503), (-3.0, 31.712812921102035), (5.0, 27.09401076758503), (5.0, 17.856406460551018), (-3.0, 13.237604307034012), (-11.0, 17.856406460551018)], [(5.0, 17.856406460551018), (5.0, 27.09401076758503), (13.0, 31.712812921102035), (21.0, 27.09401076758503), (21.0, 17.856406460551018), (13.0, 13.237604307034012), (5.0, 17.856406460551018)], [(21.0, 17.856406460551018), (21.0, 27.09401076758503), (29.0, 31.712812921102035), (37.0, 27.09401076758503), (37.0, 17.856406460551018), (29.0, 13.237604307034012), (21.0, 17.856406460551018)], [(-3.0, 31.712812921102035), (-3.0, 40.95041722813605), (5.0, 45.569219381653056), (13.0, 40.95041722813605), (13.0, 31.712812921102035), (5.0, 27.09401076758503), (-3.0, 31.712812921102035)], [(13.0, 31.712812921102035), (13.0, 40.95041722813605), (21.0, 45.569219381653056), (29.0, 40.95041722813605), (29.0, 31.712812921102035), (21.0, 27.09401076758503), (13.0, 31.712812921102035)]] assert calculate_polygons(9,6,4,3,2)==[[(5.0, 2.5358983848622456), (5.0, 4.8452994616207485), (7.0, 6.0), (9.0, 4.8452994616207485), (9.0, 2.5358983848622456), (7.0, 1.3811978464829942), (5.0, 2.5358983848622456)], [(7.0, 6.0), (7.0, 8.309401076758503), (9.0, 9.464101615137753), (11.0, 8.309401076758503), (11.0, 6.0), (9.0, 4.8452994616207485), (7.0, 6.0)]]
494
Write a function to convert the given binary tuple to integer.
binary_to_integer
def binary_to_integer(test_tup): res = int("".join(str(ele) for ele in test_tup), 2) return (str(res))
[ "assert binary_to_integer((1, 0, 1, 1, 1, 1, 0)) == 94", "assert binary_to_integer((0, 0, 0, 1)) == 1", "assert binary_to_integer((1, 1, 0, 0, 1, 0)) == 50" ]
def check(candidate): # Check some simple cases assert binary_to_integer((1, 1, 0, 1, 0, 0, 1)) == '105' assert binary_to_integer((0, 1, 1, 0, 0, 1, 0, 1)) == '101' assert binary_to_integer((1, 1, 0, 1, 0, 1)) == '53'
495
Write a function to remove lowercase substrings from a given string by using regex.
remove_lowercase
import re def remove_lowercase(str1): remove_lower = lambda text: re.sub('[a-z]', '', text) result = remove_lower(str1) return (result)
[ "assert remove_lowercase(\"YGnHkJXwVsGIgMMHRfHluwLStZd\") == \"YGHJXVGIMMHRHLSZ\"", "assert remove_lowercase(\"fuAnihdMNCzNJYzFPfKcypHIArMM\") == \"AMNCNJYFPKHIAMM\"", "assert remove_lowercase(\"TKKnfIYwTPSvxfyRcOUJwssnsOYki\") == \"TKKIYTPSROUJOY\"" ]
def check(candidate): # Check some simple cases assert remove_lowercase('KDeoALOklOOHserfLoAJSIskdsf') == 'KDALOOOHLAJSI' assert remove_lowercase('ProducTnamEstreAmIngMediAplAYer') == 'PTEAIMAAY' assert remove_lowercase('maNufacTuredbYSheZenTechNolOGIes') == 'NTYSZTNOGI'
496
Write a function to find the smallest integers from a given list of numbers using heap queue algorithm.
heap_queue_smallest
import heapq as hq def heap_queue_smallest(nums,n): smallest_nums = hq.nsmallest(n, nums) return smallest_nums
[ "assert heap_queue_smallest([29, 32, 18, 81, 16, 64, 79, 17, 53], 10) == [16, 17, 18, 29, 32, 53, 64, 79, 81]", "assert heap_queue_smallest([29, 35, 18, 86, 17, 61, 79, 27, 59], 5) == [17, 18, 27, 29, 35]", "assert heap_queue_smallest([28, 38, 24, 84, 17, 64, 74, 22, 57], 4) == [17, 22, 24, 28]" ]
def check(candidate): # Check some simple cases assert heap_queue_smallest( [25, 35, 22, 85, 14, 65, 75, 25, 58],3)==[14, 22, 25] assert heap_queue_smallest( [25, 35, 22, 85, 14, 65, 75, 25, 58],2)==[14, 22] assert heap_queue_smallest( [25, 35, 22, 85, 14, 65, 75, 22, 58],5)==[14, 22, 22, 25, 35]
497
Write a function to find the surface area of a cone.
surfacearea_cone
import math def surfacearea_cone(r,h): l = math.sqrt(r * r + h * h) SA = math.pi * r * (r + l) return SA
[ "assert surfacearea_cone(15, 20) == 1884.9555921538758", "assert surfacearea_cone(17, 16) == 2154.7209992138287", "assert surfacearea_cone(23, 21) == 3912.3224981810135" ]
def check(candidate): # Check some simple cases assert surfacearea_cone(5,12)==282.7433388230814 assert surfacearea_cone(10,15)==880.5179353159282 assert surfacearea_cone(19,17)==2655.923961165254
498
Write a python function to find gcd of two positive integers.
gcd
def gcd(x, y): gcd = 1 if x % y == 0: return y for k in range(int(y / 2), 0, -1): if x % k == 0 and y % k == 0: gcd = k break return gcd
[ "assert gcd(4, 5) == 1", "assert gcd(6, 7) == 1", "assert gcd(2, 13) == 1" ]
def check(candidate): # Check some simple cases assert gcd(12, 17) == 1 assert gcd(4,6) == 2 assert gcd(2,9) == 1
499
Write a function to find the diameter of a circle.
diameter_circle
def diameter_circle(r): diameter=2*r return diameter
[ "assert diameter_circle(13) == 26", "assert diameter_circle(19) == 38", "assert diameter_circle(11) == 22" ]
def check(candidate): # Check some simple cases assert diameter_circle(10)==20 assert diameter_circle(40)==80 assert diameter_circle(15)==30
500
Write a function to concatenate all elements of the given list into a string.
concatenate_elements
def concatenate_elements(list): ans = ' ' for i in list: ans = ans+ ' '+i return (ans)
[ "assert concatenate_elements(['nWyywgzc', 'iqt', 'dnyjy', 'hlegxrebes', 'fflhzs', 'gwvueprw']) == \"nWyywgzc iqt dnyjy hlegxrebes fflhzs gwvueprw\"", "assert concatenate_elements(['UGSqQQki', 'apq', 'jmq', 'aixwptpzs', 'yuvb', 'svzmhun']) == \"UGSqQQki apq jmq aixwptpzs yuvb svzmhun\"", "assert concatenate_elements(['hnUWBd', 'egn', 'kkmkxsq', 'qfzkfxboy', 'uycola', 'qzefmm']) == \"hnUWBd egn kkmkxsq qfzkfxboy uycola qzefmm\"" ]
def check(candidate): # Check some simple cases assert concatenate_elements(['hello','there','have','a','rocky','day'] ) == ' hello there have a rocky day' assert concatenate_elements([ 'Hi', 'there', 'How','are', 'you'] ) == ' Hi there How are you' assert concatenate_elements([ 'Part', 'of', 'the','journey', 'is', 'end'] ) == ' Part of the journey is end'