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
|
---|---|---|---|---|---|---|
701 | Write a function to find the equilibrium index of the given array. | equilibrium_index | def equilibrium_index(arr):
total_sum = sum(arr)
left_sum=0
for i, num in enumerate(arr):
total_sum -= num
if left_sum == total_sum:
return i
left_sum += num
return -1 | [
"assert equilibrium_index([1, 2, 8]) == -1",
"assert equilibrium_index([3, 1, 6]) == -1",
"assert equilibrium_index([2, 2, 1]) == -1"
] | def check(candidate):
# Check some simple cases
assert equilibrium_index([1, 2, 3, 4, 1, 2, 3]) == 3
assert equilibrium_index([-7, 1, 5, 2, -4, 3, 0]) == 3
assert equilibrium_index([1, 2, 3]) == -1
|
|
702 | Write a function to find the minimum number of elements that should be removed such that amax-amin<=k. | removals | def find_ind(key, i, n,
k, arr):
ind = -1
start = i + 1
end = n - 1;
while (start < end):
mid = int(start +
(end - start) / 2)
if (arr[mid] - key <= k):
ind = mid
start = mid + 1
else:
end = mid
return ind
def removals(arr, n, k):
ans = n - 1
arr.sort()
for i in range(0, n):
j = find_ind(arr[i], i,
n, k, arr)
if (j != -1):
ans = min(ans, n -
(j - i + 1))
return ans | [
"assert removals([6, 7, 1, 5, 3, 2], 5, 2) == 2",
"assert removals([6, 5, 6, 1, 10, 11], 4, 6) == 1",
"assert removals([6, 3, 8, 2, 6, 5], 1, 3) == 0"
] | def check(candidate):
# Check some simple cases
assert removals([1, 3, 4, 9, 10,11, 12, 17, 20], 9, 4) == 5
assert removals([1, 5, 6, 2, 8], 5, 2) == 3
assert removals([1, 2, 3 ,4, 5, 6], 6, 3) == 2
|
|
703 | Write a function to check whether the given key is present in the dictionary or not. | is_key_present | def is_key_present(d,x):
if x in d:
return True
else:
return False | [
"assert is_key_present({6: 65, 2: 23, 8: 30, 3: 42, 9: 55}, 5) == False",
"assert is_key_present({2: 14, 4: 46, 7: 28, 8: 61}, 10) == False",
"assert is_key_present({3: 8, 6: 34, 5: 42, 7: 49, 2: 62}, 10) == False"
] | def check(candidate):
# Check some simple cases
assert is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60},5)==True
assert is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60},6)==True
assert is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60},10)==False
|
|
704 | Write a function to calculate the harmonic sum of n-1. | harmonic_sum | def harmonic_sum(n):
if n < 2:
return 1
else:
return 1 / n + (harmonic_sum(n - 1)) | [
"assert harmonic_sum(5) == 2.283333333333333",
"assert harmonic_sum(8) == 2.7178571428571425",
"assert harmonic_sum(3) == 1.8333333333333333"
] | def check(candidate):
# Check some simple cases
assert harmonic_sum(10)==2.9289682539682538
assert harmonic_sum(4)==2.083333333333333
assert harmonic_sum(7)==2.5928571428571425
|
|
705 | Write a function to sort a list of lists by length and value. | sort_sublists | def sort_sublists(list1):
list1.sort()
list1.sort(key=len)
return list1 | [
"assert sort_sublists([['kuibndwhdm'], ['tcbxeb', 'R', '?#D^I/'], ['ZVQMFATTJ'], ['GUVS', 'IPPNCOL']]) == [['ZVQMFATTJ'], ['kuibndwhdm'], ['GUVS', 'IPPNCOL'], ['tcbxeb', 'R', '?#D^I/']]",
"assert sort_sublists([['gpqazdnk'], ['zqvzfm', 'H', '|<KAT<QWR'], ['WQRE'], ['DLURZTEDK', 'ZMB']]) == [['WQRE'], ['gpqazdnk'], ['DLURZTEDK', 'ZMB'], ['zqvzfm', 'H', '|<KAT<QWR']]",
"assert sort_sublists([['eoloafv'], ['qyixgii', 'M', '!:*L@~:V'], ['BEYLVB'], ['YACVQCJF', 'RGIWMVFO']]) == [['BEYLVB'], ['eoloafv'], ['YACVQCJF', 'RGIWMVFO'], ['qyixgii', 'M', '!:*L@~:V']]"
] | def check(candidate):
# Check some simple cases
assert sort_sublists([[2], [0], [1, 3], [0, 7], [9, 11], [13, 15, 17]])==[[0], [2], [0, 7], [1, 3], [9, 11], [13, 15, 17]]
assert sort_sublists([[1], [2, 3], [4, 5, 6], [7], [10, 11]])==[[1], [7], [2, 3], [10, 11], [4, 5, 6]]
assert sort_sublists([["python"],["java","C","C++"],["DBMS"],["SQL","HTML"]])==[['DBMS'], ['python'], ['SQL', 'HTML'], ['java', 'C', 'C++']]
|
|
706 | Write a function to find whether an array is subset of another array. | is_subset | def is_subset(arr1, m, arr2, n):
hashset = set()
for i in range(0, m):
hashset.add(arr1[i])
for i in range(0, n):
if arr2[i] in hashset:
continue
else:
return False
return True | [
"assert is_subset([13, 3, 1, 26, 14], 4, [21, 9, 6], 8) == False",
"assert is_subset([14, 4, 1, 24, 17], 5, [24, 2, 4], 6) == False",
"assert is_subset([12, 5, 7, 24, 20], 5, [18, 1, 1], 6) == False"
] | def check(candidate):
# Check some simple cases
assert is_subset([11, 1, 13, 21, 3, 7], 6, [11, 3, 7, 1], 4) == True
assert is_subset([1, 2, 3, 4, 5, 6], 6, [1, 2, 4], 3) == True
assert is_subset([10, 5, 2, 23, 19], 5, [19, 5, 3], 3) == False
|
|
707 | Write a python function to count the total set bits from 1 to n. | count_Set_Bits | def count_Set_Bits(n) :
n += 1;
powerOf2 = 2;
cnt = n // 2;
while (powerOf2 <= n) :
totalPairs = n // powerOf2;
cnt += (totalPairs // 2) * powerOf2;
if (totalPairs & 1) :
cnt += (n % powerOf2)
else :
cnt += 0
powerOf2 <<= 1;
return cnt; | [
"assert count_Set_Bits(16) == 33",
"assert count_Set_Bits(14) == 28",
"assert count_Set_Bits(19) == 40"
] | def check(candidate):
# Check some simple cases
assert count_Set_Bits(16) == 33
assert count_Set_Bits(2) == 2
assert count_Set_Bits(14) == 28
|
|
708 | Write a python function to convert a string to a list. | Convert | def Convert(string):
li = list(string.split(" "))
return li | [
"assert Convert(\"YSLkHGFKwHCJs\") == ['YSLkHGFKwHCJs']",
"assert Convert(\"TvoCqLjQiipx\") == ['TvoCqLjQiipx']",
"assert Convert(\"uIkILmRpxbxMgFA\") == ['uIkILmRpxbxMgFA']"
] | def check(candidate):
# Check some simple cases
assert Convert('python program') == ['python','program']
assert Convert('Data Analysis') ==['Data','Analysis']
assert Convert('Hadoop Training') == ['Hadoop','Training']
|
|
709 | Write a function to count unique keys for each value present in the tuple. | get_unique | from collections import defaultdict
def get_unique(test_list):
res = defaultdict(list)
for sub in test_list:
res[sub[1]].append(sub[0])
res = dict(res)
res_dict = dict()
for key in res:
res_dict[key] = len(list(set(res[key])))
return (str(res_dict)) | [
"assert get_unique([(10, 2), (2, 6), (6, 1), (6, 5), (7, 18), (13, 12), (8, 6), (13, 6), (14, 3)]) == {2: 1, 6: 3, 1: 1, 5: 1, 18: 1, 12: 1, 3: 1}",
"assert get_unique([(6, 10), (8, 3), (6, 4), (8, 5), (4, 26), (9, 16), (4, 7), (15, 1), (11, 7)]) == {10: 1, 3: 1, 4: 1, 5: 1, 26: 1, 16: 1, 7: 2, 1: 1}",
"assert get_unique([(2, 8), (1, 6), (7, 11), (10, 5), (6, 25), (13, 9), (1, 8), (14, 3), (6, 1)]) == {8: 2, 6: 1, 11: 1, 5: 1, 25: 1, 9: 1, 3: 1, 1: 1}"
] | def check(candidate):
# Check some simple cases
assert get_unique([(3, 4), (1, 2), (2, 4), (8, 2), (7, 2), (8, 1), (9, 1), (8, 4), (10, 4)] ) == '{4: 4, 2: 3, 1: 2}'
assert get_unique([(4, 5), (2, 3), (3, 5), (9, 3), (8, 3), (9, 2), (10, 2), (9, 5), (11, 5)] ) == '{5: 4, 3: 3, 2: 2}'
assert get_unique([(6, 5), (3, 4), (2, 6), (11, 1), (8, 22), (8, 11), (4, 3), (14, 3), (11, 6)] ) == '{5: 1, 4: 1, 6: 2, 1: 1, 22: 1, 11: 1, 3: 2}'
|
|
710 | Write a function to access the initial and last data of the given tuple record. | front_and_rear | def front_and_rear(test_tup):
res = (test_tup[0], test_tup[-1])
return (res) | [
"assert front_and_rear((6, 5, 5, 10, 7)) == (6, 7)",
"assert front_and_rear((8, 9, 3, 14, 15)) == (8, 15)",
"assert front_and_rear((7, 7, 4, 11, 15)) == (7, 15)"
] | def check(candidate):
# Check some simple cases
assert front_and_rear((10, 4, 5, 6, 7)) == (10, 7)
assert front_and_rear((1, 2, 3, 4, 5)) == (1, 5)
assert front_and_rear((6, 7, 8, 9, 10)) == (6, 10)
|
|
711 | Write a python function to check whether the product of digits of a number at even and odd places is equal or not. | product_Equal | def product_Equal(n):
if n < 10:
return False
prodOdd = 1; prodEven = 1
while n > 0:
digit = n % 10
prodOdd *= digit
n = n//10
if n == 0:
break;
digit = n % 10
prodEven *= digit
n = n//10
if prodOdd == prodEven:
return True
return False | [
"assert product_Equal(280) == False",
"assert product_Equal(1313) == False",
"assert product_Equal(1477) == False"
] | def check(candidate):
# Check some simple cases
assert product_Equal(2841) == True
assert product_Equal(1234) == False
assert product_Equal(1212) == False
|
|
712 | Write a function to remove duplicates from a list of lists. | remove_duplicate | import itertools
def remove_duplicate(list1):
list.sort(list1)
remove_duplicate = list(list1 for list1,_ in itertools.groupby(list1))
return remove_duplicate | [
"assert remove_duplicate([5, 3, 8, 7, 1, 9, 4, 2]) == [1, 2, 3, 4, 5, 7, 8, 9]",
"assert remove_duplicate([1, 8, 2, 9, 4, 5, 10, 3]) == [1, 2, 3, 4, 5, 8, 9, 10]",
"assert remove_duplicate([3, 7, 2, 4, 4, 4, 5, 5]) == [2, 3, 4, 5, 7]"
] | def check(candidate):
# Check some simple cases
assert remove_duplicate([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])==[[10, 20], [30, 56, 25], [33], [40]]
assert remove_duplicate(["a", "b", "a", "c", "c"] )==["a", "b", "c"]
assert remove_duplicate([1, 3, 5, 6, 3, 5, 6, 1] )==[1, 3, 5, 6]
|
|
713 | Write a function to check if the given tuple contains all valid values or not. | check_valid | def check_valid(test_tup):
res = not any(map(lambda ele: not ele, test_tup))
return (res) | [
"assert check_valid((2, 4, 2, 1)) == True",
"assert check_valid((3, 5, 4, 2)) == True",
"assert check_valid((5, 4, 6, 6)) == True"
] | def check(candidate):
# Check some simple cases
assert check_valid((True, True, True, True) ) == True
assert check_valid((True, False, True, True) ) == False
assert check_valid((True, True, True, True) ) == True
|
|
714 | Write a python function to count the number of distinct power of prime factor of given number. | count_Fac | def count_Fac(n):
m = n
count = 0
i = 2
while((i * i) <= m):
total = 0
while (n % i == 0):
n /= i
total += 1
temp = 0
j = 1
while((temp + j) <= total):
temp += j
count += 1
j += 1
i += 1
if (n != 1):
count += 1
return count | [
"assert count_Fac(7) == 1",
"assert count_Fac(2) == 1",
"assert count_Fac(4) == 1"
] | def check(candidate):
# Check some simple cases
assert count_Fac(24) == 3
assert count_Fac(12) == 2
assert count_Fac(4) == 1
|
|
715 | Write a function to convert the given string of integers into a tuple. | str_to_tuple | def str_to_tuple(test_str):
res = tuple(map(int, test_str.split(', ')))
return (res) | [
"assert str_to_tuple(\"(10, 1, 5, -8, -7, 6, -5, 17, -1, -17)\") == (10, 1, 5, -8, -7, 6, -5, 17, -1, -17)",
"assert str_to_tuple(\"(-7, 4, -9, -17, -1, 6, 5, -8, -5)\") == (-7, 4, -9, -17, -1, 6, 5, -8, -5)",
"assert str_to_tuple(\"(17, 10, 17, -18, -10, 16, -12, 15, -16, -14)\") == (17, 10, 17, -18, -10, 16, -12, 15, -16, -14)"
] | def check(candidate):
# Check some simple cases
assert str_to_tuple("1, -5, 4, 6, 7") == (1, -5, 4, 6, 7)
assert str_to_tuple("1, 2, 3, 4, 5") == (1, 2, 3, 4, 5)
assert str_to_tuple("4, 6, 9, 11, 13, 14") == (4, 6, 9, 11, 13, 14)
|
|
716 | Write a function to find the perimeter of a rombus. | rombus_perimeter | def rombus_perimeter(a):
perimeter=4*a
return perimeter | [
"assert rombus_perimeter(3) == 12",
"assert rombus_perimeter(7) == 28",
"assert rombus_perimeter(4) == 16"
] | def check(candidate):
# Check some simple cases
assert rombus_perimeter(10)==40
assert rombus_perimeter(5)==20
assert rombus_perimeter(4)==16
|
|
717 | Write a function to calculate the standard deviation. | sd_calc | import math
import sys
def sd_calc(data):
n = len(data)
if n <= 1:
return 0.0
mean, sd = avg_calc(data), 0.0
for el in data:
sd += (float(el) - mean)**2
sd = math.sqrt(sd / float(n-1))
return sd
def avg_calc(ls):
n, mean = len(ls), 0.0
if n <= 1:
return ls[0]
for el in ls:
mean = mean + float(el)
mean = mean / float(n)
return mean | [
"assert sd_calc([7, 11, 15, 12, 4, 2]) == 5.0099900199501395",
"assert sd_calc([5, 10, 11, 18, 2, 9]) == 5.49241901776136",
"assert sd_calc([7, 14, 6, 10, 10, 1]) == 4.427188724235731"
] | def check(candidate):
# Check some simple cases
assert sd_calc([4, 2, 5, 8, 6])== 2.23606797749979
assert sd_calc([1,2,3,4,5,6,7])==2.160246899469287
assert sd_calc([5,9,10,15,6,4])==4.070217029430577
|
|
718 | Write a function to create a list taking alternate elements from another given list. | alternate_elements | def alternate_elements(list1):
result=[]
for item in list1[::2]:
result.append(item)
return result | [
"assert alternate_elements([6, 5, 4, 3, 1, 11, 8, 8, 8, 13]) == [6, 4, 1, 8, 8]",
"assert alternate_elements([2, 3, 2, 8, 10, 10, 4, 9, 9, 5]) == [2, 2, 10, 4, 9]",
"assert alternate_elements([2, 4, 2, 2, 7, 11, 11, 9, 4, 11]) == [2, 2, 7, 11, 4]"
] | def check(candidate):
# Check some simple cases
assert alternate_elements(["red", "black", "white", "green", "orange"])==['red', 'white', 'orange']
assert alternate_elements([2, 0, 3, 4, 0, 2, 8, 3, 4, 2])==[2, 3, 0, 8, 4]
assert alternate_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9]
|
|
719 | Write a function that matches a string that has an a followed by zero or more b's. | text_match | import re
def text_match(text):
patterns = 'ab*?'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | [
"assert text_match(\"mkpumjrun\") == \"Not matched!\"",
"assert text_match(\"yydi\") == \"Not matched!\"",
"assert text_match(\"mohol\") == \"Not matched!\""
] | def check(candidate):
# Check some simple cases
assert text_match("ac")==('Found a match!')
assert text_match("dc")==('Not matched!')
assert text_match("abba")==('Found a match!')
|
|
720 | Write a function to add a dictionary to the tuple. | add_dict_to_tuple | def add_dict_to_tuple(test_tup, test_dict):
test_tup = list(test_tup)
test_tup.append(test_dict)
test_tup = tuple(test_tup)
return (test_tup) | [
"assert add_dict_to_tuple((9, 5, 6), {'ALCTMRJ': 8, 'qidyz': 4, 'EzDCxP': 5}) == (9, 5, 6, {'ALCTMRJ': 8, 'qidyz': 4, 'EzDCxP': 5})",
"assert add_dict_to_tuple((6, 14, 7), {'HLDBTSOJ': 7, 'ere': 2, 'WaIaT': 6}) == (6, 14, 7, {'HLDBTSOJ': 7, 'ere': 2, 'WaIaT': 6})",
"assert add_dict_to_tuple((8, 12, 5), {'EFMSUUP': 3, 'umilo': 7, 'GCPGlM': 9}) == (8, 12, 5, {'EFMSUUP': 3, 'umilo': 7, 'GCPGlM': 9})"
] | def check(candidate):
# Check some simple cases
assert add_dict_to_tuple((4, 5, 6), {"MSAM" : 1, "is" : 2, "best" : 3} ) == (4, 5, 6, {'MSAM': 1, 'is': 2, 'best': 3})
assert add_dict_to_tuple((1, 2, 3), {"UTS" : 2, "is" : 3, "Worst" : 4} ) == (1, 2, 3, {'UTS': 2, 'is': 3, 'Worst': 4})
assert add_dict_to_tuple((8, 9, 10), {"POS" : 3, "is" : 4, "Okay" : 5} ) == (8, 9, 10, {'POS': 3, 'is': 4, 'Okay': 5})
|
|
721 | Write a function to find a path with the maximum average over all existing paths for the given square matrix of size n*n. | maxAverageOfPath | M = 100
def maxAverageOfPath(cost, N):
dp = [[0 for i in range(N + 1)] for j in range(N + 1)]
dp[0][0] = cost[0][0]
for i in range(1, N):
dp[i][0] = dp[i - 1][0] + cost[i][0]
for j in range(1, N):
dp[0][j] = dp[0][j - 1] + cost[0][j]
for i in range(1, N):
for j in range(1, N):
dp[i][j] = max(dp[i - 1][j],
dp[i][j - 1]) + cost[i][j]
return dp[N - 1][N - 1] / (2 * N - 1) | [
"assert maxAverageOfPath([[8, 7, 8], [9, 11, 1], [4, 7, 8]], 2) == 9.333333333333334",
"assert maxAverageOfPath([[2, 7, 8], [6, 2, 9], [8, 8, 9]], 3) == 7.0",
"assert maxAverageOfPath([[6, 5, 2], [13, 8, 8], [12, 2, 7]], 3) == 8.4"
] | def check(candidate):
# Check some simple cases
assert maxAverageOfPath([[1, 2, 3], [6, 5, 4], [7, 3, 9]], 3) == 5.2
assert maxAverageOfPath([[2, 3, 4], [7, 6, 5], [8, 4, 10]], 3) == 6.2
assert maxAverageOfPath([[3, 4, 5], [8, 7, 6], [9, 5, 11]], 3) == 7.2
|
|
722 | Write a function to filter the height and width of students which are stored in a dictionary. | filter_data | def filter_data(students,h,w):
result = {k: s for k, s in students.items() if s[0] >=h and s[1] >=w}
return result | [
"assert filter_data({'BRHfEyUjdx ': (5.457458146114651, 66), 'fzrrYNSdDxUheeU': (10.92405363155631, 69), 'JdnPIAKuAfv': (4.357091687688858, 65), 'aQheXW': (3.952194537773692, 65)}, 4.223505312604639, 64) == {'BRHfEyUjdx ': (5.457458146114651, 66), 'fzrrYNSdDxUheeU': (10.92405363155631, 69), 'JdnPIAKuAfv': (4.357091687688858, 65)}",
"assert filter_data({'wZELryCRs': (8.668537083392351, 73), 'bqbKlQDpJatXAhUOAX': (10.249461209697555, 64), 'APMCWYXXH': (11.121756378595776, 65), 'Gtq jwM Q': (5.566088523638032, 62)}, 2.10363139390391, 66) == {'wZELryCRs': (8.668537083392351, 73)}",
"assert filter_data({'QRHxQxhLYL': (3.176839565846304, 69), 'p ZVcGOQWUPJXCGWb': (2.974046304837316, 66), 'CxQe OyxCt': (10.593866014566412, 67), 'SEIHtz KMJ ': (9.070785608461383, 69)}, 3.7436979657999854, 69) == {'SEIHtz KMJ ': (9.070785608461383, 69)}"
] | def check(candidate):
# Check some simple cases
assert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},6.0,70)=={'Cierra Vega': (6.2, 70)}
assert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},5.9,67)=={'Cierra Vega': (6.2, 70),'Kierra Gentry': (6.0, 68)}
assert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},5.7,64)=={'Cierra Vega': (6.2, 70),'Alden Cantrell': (5.9, 65),'Kierra Gentry': (6.0, 68),'Pierre Cox': (5.8, 66)}
|
|
723 | Write a function to count the same pair in two given lists using map function. | count_same_pair | from operator import eq
def count_same_pair(nums1, nums2):
result = sum(map(eq, nums1, nums2))
return result | [
"assert count_same_pair([2, 4, -1, -8, 11, -7, 11, -1, 18], [2, 5, 2, -4, -2, 1, 7, -3, 1, 8, 7, 7, 4]) == 1",
"assert count_same_pair([2, 3, -7, -14, 11, -14, 17, -5, 17], [2, 1, 6, 1, -3, 8, 9, -6, 0, 8, 4, 7, 9]) == 1",
"assert count_same_pair([2, 1, -5, -8, 9, -15, 16, -3, 17], [2, 1, 6, 1, -1, 6, 7, -3, -5, 5, 6, 9, 5]) == 3"
] | def check(candidate):
# Check some simple cases
assert count_same_pair([1, 2, 3, 4, 5, 6, 7, 8],[2, 2, 3, 1, 2, 6, 7, 9])==4
assert count_same_pair([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==11
assert count_same_pair([2, 4, -6, -9, 11, -12, 14, -5, 17],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==1
|
|
724 | Write a function to calculate the sum of all digits of the base to the specified power. | power_base_sum | def power_base_sum(base, power):
return sum([int(i) for i in str(pow(base, power))]) | [
"assert power_base_sum(8, 17) == 80",
"assert power_base_sum(5, 12) == 28",
"assert power_base_sum(9, 17) == 99"
] | def check(candidate):
# Check some simple cases
assert power_base_sum(2,100)==115
assert power_base_sum(8,10)==37
assert power_base_sum(8,15)==62
|
|
725 | Write a function to extract values between quotation marks of the given string by using regex. | extract_quotation | import re
def extract_quotation(text1):
return (re.findall(r'"(.*?)"', text1)) | [
"assert extract_quotation(\"VRa H7Qyv6Co6dl3OithtTv0sIZrapRuYBrlsWfUJzyc4Afg5XcXuGOn2Wlha\") == []",
"assert extract_quotation(\"JpzWHgkYPTkaE9VlGNvyKm7qVobRRv8jsiKf3P87X3zXqhwUUvT6bD7aGON8g0\") == []",
"assert extract_quotation(\"lkjXysUOk BOD407sYW6T 5WKJcGcvndgUYGarnVBVrqEefHHd6j5FNxDzH5c5GM\") == []"
] | def check(candidate):
# Check some simple cases
assert extract_quotation('Cortex "A53" Based "multi" tasking "Processor"') == ['A53', 'multi', 'Processor']
assert extract_quotation('Cast your "favorite" entertainment "apps"') == ['favorite', 'apps']
assert extract_quotation('Watch content "4k Ultra HD" resolution with "HDR 10" Support') == ['4k Ultra HD', 'HDR 10']
|
|
726 | Write a function to multiply the adjacent elements of the given tuple. | multiply_elements | def multiply_elements(test_tup):
res = tuple(i * j for i, j in zip(test_tup, test_tup[1:]))
return (res) | [
"assert multiply_elements((14, 14, 13, 11, 10)) == (196, 182, 143, 110)",
"assert multiply_elements((17, 10, 18, 4, 20)) == (170, 180, 72, 80)",
"assert multiply_elements((7, 10, 19, 12, 18)) == (70, 190, 228, 216)"
] | def check(candidate):
# Check some simple cases
assert multiply_elements((1, 5, 7, 8, 10)) == (5, 35, 56, 80)
assert multiply_elements((2, 4, 5, 6, 7)) == (8, 20, 30, 42)
assert multiply_elements((12, 13, 14, 9, 15)) == (156, 182, 126, 135)
|
|
727 | Write a function to remove all characters except letters and numbers using regex | remove_char | import re
def remove_char(S):
result = re.sub('[\W_]+', '', S)
return result | [
"assert remove_char(\"$n,M*q9sz&el2|7/bshK6Sj?ig_\") == \"nMq9szel27bshK6Sjig\"",
"assert remove_char(\"NMtbC>U&DU8=xCi0WgcnP0>K0*loK-\") == \"NMtbCUDU8xCi0WgcnP0K0loK\"",
"assert remove_char(\"1tc*N|T a4rn~KX62cxegof^\") == \"1tcNTa4rnKX62cxegof\""
] | def check(candidate):
# Check some simple cases
assert remove_char("123abcjw:, .@! eiw") == '123abcjweiw'
assert remove_char("Hello1234:, ! Howare33u") == 'Hello1234Howare33u'
assert remove_char("Cool543Triks@:, Make@987Trips") == 'Cool543TriksMake987Trips'
|
|
728 | Write a function to sum elements in two lists. | sum_list | def sum_list(lst1,lst2):
res_list = [lst1[i] + lst2[i] for i in range(len(lst1))]
return res_list | [
"assert sum_list([13, 18, 25], [16, 45, 75]) == [29, 63, 100]",
"assert sum_list([18, 25, 35], [19, 47, 79]) == [37, 72, 114]",
"assert sum_list([18, 25, 29], [16, 48, 73]) == [34, 73, 102]"
] | def check(candidate):
# Check some simple cases
assert sum_list([10,20,30],[15,25,35])==[25,45,65]
assert sum_list([1,2,3],[5,6,7])==[6,8,10]
assert sum_list([15,20,30],[15,45,75])==[30,65,105]
|
|
729 | Write a function to add two lists using map and lambda function. | add_list | def add_list(nums1,nums2):
result = map(lambda x, y: x + y, nums1, nums2)
return list(result) | [
"assert add_list([7, 24], [47, 65]) == [54, 89]",
"assert add_list([14, 16], [52, 74]) == [66, 90]",
"assert add_list([15, 19], [51, 69]) == [66, 88]"
] | def check(candidate):
# Check some simple cases
assert add_list([1, 2, 3],[4,5,6])==[5, 7, 9]
assert add_list([1,2],[3,4])==[4,6]
assert add_list([10,20],[50,70])==[60,90]
|
|
730 | Write a function to remove consecutive duplicates of a given list. | consecutive_duplicates | from itertools import groupby
def consecutive_duplicates(nums):
return [key for key, group in groupby(nums)] | [
"assert consecutive_duplicates(['w', 'w', 'k', 'l', 'i', 'l']) == ['w', 'k', 'l', 'i', 'l']",
"assert consecutive_duplicates(['o', 'm', 's', 'f', 'c', 't']) == ['o', 'm', 's', 'f', 'c', 't']",
"assert consecutive_duplicates(['u', 'v', 'b', 'h', 'u', 's']) == ['u', 'v', 'b', 'h', 'u', 's']"
] | def check(candidate):
# Check some simple cases
assert consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4 ])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4]
assert consecutive_duplicates([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10])==[10, 15, 19, 18, 17, 26, 17, 18, 10]
assert consecutive_duplicates(['a', 'a', 'b', 'c', 'd', 'd'])==['a', 'b', 'c', 'd']
|
|
731 | Write a function to find the lateral surface area of a cone. | lateralsurface_cone | import math
def lateralsurface_cone(r,h):
l = math.sqrt(r * r + h * h)
LSA = math.pi * r * l
return LSA | [
"assert lateralsurface_cone(17, 21) == 1442.9797089695412",
"assert lateralsurface_cone(24, 13) == 2057.9710009121764",
"assert lateralsurface_cone(15, 16) == 1033.5075888970994"
] | def check(candidate):
# Check some simple cases
assert lateralsurface_cone(5,12)==204.20352248333654
assert lateralsurface_cone(10,15)==566.3586699569488
assert lateralsurface_cone(19,17)==1521.8090132193388
|
|
732 | Write a function to replace all occurrences of spaces, commas, or dots with a colon. | replace_specialchar | import re
def replace_specialchar(text):
return (re.sub("[ ,.]", ":", text))
| [
"assert replace_specialchar(\"z ncvpxmtpacwuyp,b,x\") == \"z:ncvpxmtpacwuyp:b:x\"",
"assert replace_specialchar(\"dsssro,lvxxljhs\") == \"dsssro:lvxxljhs\"",
"assert replace_specialchar(\"yamk igpnjiwsnjbpd fk\") == \"yamk::igpnjiwsnjbpd:fk\""
] | def check(candidate):
# Check some simple cases
assert replace_specialchar('Python language, Programming language.')==('Python:language::Programming:language:')
assert replace_specialchar('a b c,d e f')==('a:b:c:d:e:f')
assert replace_specialchar('ram reshma,ram rahim')==('ram:reshma:ram:rahim')
|
|
733 | Write a function to find the index of the first occurrence of a given number in a sorted array. | find_first_occurrence | def find_first_occurrence(A, x):
(left, right) = (0, len(A) - 1)
result = -1
while left <= right:
mid = (left + right) // 2
if x == A[mid]:
result = mid
right = mid - 1
elif x < A[mid]:
right = mid - 1
else:
left = mid + 1
return result | [
"assert find_first_occurrence([1, 6, 3, 10, 9, 6, 10, 9, 5, 4], 1) == 0",
"assert find_first_occurrence([4, 2, 4, 1, 9, 3, 12, 13, 5, 7], 8) == -1",
"assert find_first_occurrence([7, 6, 1, 5, 9, 5, 9, 12, 13, 11], 5) == -1"
] | def check(candidate):
# Check some simple cases
assert find_first_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 1
assert find_first_occurrence([2, 3, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 2
assert find_first_occurrence([2, 4, 1, 5, 6, 6, 8, 9, 9, 9], 6) == 4
|
|
734 | Write a python function to find sum of products of all possible subarrays. | sum_Of_Subarray_Prod | def sum_Of_Subarray_Prod(arr,n):
ans = 0
res = 0
i = n - 1
while (i >= 0):
incr = arr[i]*(1 + res)
ans += incr
res = incr
i -= 1
return (ans) | [
"assert sum_Of_Subarray_Prod([6, 6, 4, 7], 2) == 48",
"assert sum_Of_Subarray_Prod([2, 4, 7, 3], 4) == 381",
"assert sum_Of_Subarray_Prod([3, 4, 1, 3], 2) == 19"
] | def check(candidate):
# Check some simple cases
assert sum_Of_Subarray_Prod([1,2,3],3) == 20
assert sum_Of_Subarray_Prod([1,2],2) == 5
assert sum_Of_Subarray_Prod([1,2,3,4],4) == 84
|
|
735 | Write a python function to toggle bits of the number except the first and the last bit. | toggle_middle_bits | def set_middle_bits(n):
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
return (n >> 1) ^ 1
def toggle_middle_bits(n):
if (n == 1):
return 1
return n ^ set_middle_bits(n) | [
"assert toggle_middle_bits(16) == 30",
"assert toggle_middle_bits(12) == 10",
"assert toggle_middle_bits(16) == 30"
] | def check(candidate):
# Check some simple cases
assert toggle_middle_bits(9) == 15
assert toggle_middle_bits(10) == 12
assert toggle_middle_bits(11) == 13
|
|
736 | Write a function to locate the left insertion point for a specified value in sorted order. | left_insertion | import bisect
def left_insertion(a, x):
i = bisect.bisect_left(a, x)
return i | [
"assert left_insertion([2, 3, 1, 5], 10) == 4",
"assert left_insertion([3, 4, 9, 7], 2) == 0",
"assert left_insertion([3, 3, 2, 2], 8) == 4"
] | def check(candidate):
# Check some simple cases
assert left_insertion([1,2,4,5],6)==4
assert left_insertion([1,2,4,5],3)==2
assert left_insertion([1,2,4,5],7)==4
|
|
737 | Write a function to check whether the given string is starting with a vowel or not using regex. | check_str | import re
regex = '^[aeiouAEIOU][A-Za-z0-9_]*'
def check_str(string):
if(re.search(regex, string)):
return ("Valid")
else:
return ("Invalid") | [
"assert check_str(\"VUbwmby\") == \"Invalid\"",
"assert check_str(\"tqOMgj\") == \"Invalid\"",
"assert check_str(\"lred\") == \"Invalid\""
] | def check(candidate):
# Check some simple cases
assert check_str("annie") == 'Valid'
assert check_str("dawood") == 'Invalid'
assert check_str("Else") == 'Valid'
|
|
738 | Write a function to calculate the geometric sum of n-1. | geometric_sum | def geometric_sum(n):
if n < 0:
return 0
else:
return 1 / (pow(2, n)) + geometric_sum(n - 1) | [
"assert geometric_sum(13) == 1.9998779296875",
"assert geometric_sum(12) == 1.999755859375",
"assert geometric_sum(12) == 1.999755859375"
] | def check(candidate):
# Check some simple cases
assert geometric_sum(7) == 1.9921875
assert geometric_sum(4) == 1.9375
assert geometric_sum(8) == 1.99609375
|
|
739 | Write a python function to find the index of smallest triangular number with n digits. | find_Index | import math
def find_Index(n):
x = math.sqrt(2 * math.pow(10,(n - 1)));
return round(x); | [
"assert find_Index(2) == 4",
"assert find_Index(3) == 14",
"assert find_Index(4) == 45"
] | def check(candidate):
# Check some simple cases
assert find_Index(2) == 4
assert find_Index(3) == 14
assert find_Index(4) == 45
|
|
740 | Write a function to convert the given tuple to a key-value dictionary using adjacent elements. | tuple_to_dict | def tuple_to_dict(test_tup):
res = dict(test_tup[idx : idx + 2] for idx in range(0, len(test_tup), 2))
return (res) | [
"assert tuple_to_dict((2, 13, 4, 15, 15, 14)) == {2: 13, 4: 15, 15: 14}",
"assert tuple_to_dict((9, 9, 8, 8, 13, 14)) == {9: 9, 8: 8, 13: 14}",
"assert tuple_to_dict((5, 4, 13, 8, 7, 7)) == {5: 4, 13: 8, 7: 7}"
] | def check(candidate):
# Check some simple cases
assert tuple_to_dict((1, 5, 7, 10, 13, 5)) == {1: 5, 7: 10, 13: 5}
assert tuple_to_dict((1, 2, 3, 4, 5, 6)) == {1: 2, 3: 4, 5: 6}
assert tuple_to_dict((7, 8, 9, 10, 11, 12)) == {7: 8, 9: 10, 11: 12}
|
|
741 | Write a python function to check whether all the characters are same or not. | all_Characters_Same | def all_Characters_Same(s) :
n = len(s)
for i in range(1,n) :
if s[i] != s[0] :
return False
return True | [
"assert all_Characters_Same(\"fiz\") == False",
"assert all_Characters_Same(\"ufghjrdqa\") == False",
"assert all_Characters_Same(\"lzytv\") == False"
] | def check(candidate):
# Check some simple cases
assert all_Characters_Same("python") == False
assert all_Characters_Same("aaa") == True
assert all_Characters_Same("data") == False
|
|
742 | Write a function to caluclate the area of a tetrahedron. | area_tetrahedron | import math
def area_tetrahedron(side):
area = math.sqrt(3)*(side*side)
return area | [
"assert area_tetrahedron(8) == 110.85125168440814",
"assert area_tetrahedron(11) == 209.57814771583415",
"assert area_tetrahedron(7) == 84.87048957087498"
] | def check(candidate):
# Check some simple cases
assert area_tetrahedron(3)==15.588457268119894
assert area_tetrahedron(20)==692.8203230275509
assert area_tetrahedron(10)==173.20508075688772
|
|
743 | Write a function to rotate a given list by specified number of items to the right direction. | rotate_right | def rotate_right(list1,m,n):
result = list1[-(m):]+list1[:-(n)]
return result | [
"assert rotate_right([6, 2, 1, 2, 3, 5, 10, 13, 12, 15], 4, 6) == [10, 13, 12, 15, 6, 2, 1, 2]",
"assert rotate_right([4, 2, 3, 5, 8, 7, 4, 13, 5, 10], 9, 3) == [2, 3, 5, 8, 7, 4, 13, 5, 10, 4, 2, 3, 5, 8, 7, 4]",
"assert rotate_right([3, 1, 6, 5, 2, 3, 8, 7, 7, 6], 2, 6) == [7, 6, 3, 1, 6, 5]"
] | def check(candidate):
# Check some simple cases
assert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],3,4)==[8, 9, 10, 1, 2, 3, 4, 5, 6]
assert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2,2)==[9, 10, 1, 2, 3, 4, 5, 6, 7, 8]
assert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],5,2)==[6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8]
|
|
744 | Write a function to check if the given tuple has any none value or not. | check_none | def check_none(test_tup):
res = any(map(lambda ele: ele is None, test_tup))
return (res) | [
"assert check_none((3, 6, 5, 4, None)) == True",
"assert check_none((5, 1, 8, 2, None)) == True",
"assert check_none((1, 5, 3, 2, None)) == True"
] | def check(candidate):
# Check some simple cases
assert check_none((10, 4, 5, 6, None)) == True
assert check_none((7, 8, 9, 11, 14)) == False
assert check_none((1, 2, 3, 4, None)) == True
|
|
745 | Write a function to find numbers within a given range where every number is divisible by every digit it contains. | divisible_by_digits | def divisible_by_digits(startnum, endnum):
return [n for n in range(startnum, endnum+1) \
if not any(map(lambda x: int(x) == 0 or n%int(x) != 0, str(n)))] | [
"assert divisible_by_digits(18, 22) == [22]",
"assert divisible_by_digits(22, 22) == [22]",
"assert divisible_by_digits(21, 21) == []"
] | def check(candidate):
# Check some simple cases
assert divisible_by_digits(1,22)==[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
assert divisible_by_digits(1,15)==[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15]
assert divisible_by_digits(20,25)==[22, 24]
|
|
746 | Write a function to find area of a sector. | sector_area | def sector_area(r,a):
pi=22/7
if a >= 360:
return None
sectorarea = (pi*r**2) * (a/360)
return sectorarea | [
"assert sector_area(7, 358) == 153.14444444444445",
"assert sector_area(11, 363) == None",
"assert sector_area(8, 362) == None"
] | def check(candidate):
# Check some simple cases
assert sector_area(4,45)==6.285714285714286
assert sector_area(9,45)==31.82142857142857
assert sector_area(9,360)==None
|
|
747 | Write a function to find the longest common subsequence for the given three string sequence. | lcs_of_three | def lcs_of_three(X, Y, Z, m, n, o):
L = [[[0 for i in range(o+1)] for j in range(n+1)]
for k in range(m+1)]
for i in range(m+1):
for j in range(n+1):
for k in range(o+1):
if (i == 0 or j == 0 or k == 0):
L[i][j][k] = 0
elif (X[i-1] == Y[j-1] and
X[i-1] == Z[k-1]):
L[i][j][k] = L[i-1][j-1][k-1] + 1
else:
L[i][j][k] = max(max(L[i-1][j][k],
L[i][j-1][k]),
L[i][j][k-1])
return L[m][n][o] | [
"assert lcs_of_three('eat8lhe0t3ux', 'wowee44d4i3', 'iotecuuz', 7, 5, 5) == 1",
"assert lcs_of_three('11b8pg541', 'heia1dvei', 'gjw506b7z', 4, 8, 7) == 0",
"assert lcs_of_three('h9nzbxk1ebwu', 'wvmb', 'o57', 2, 4, 8) == 0"
] | def check(candidate):
# Check some simple cases
assert lcs_of_three('AGGT12', '12TXAYB', '12XBA', 6, 7, 5) == 2
assert lcs_of_three('Reels', 'Reelsfor', 'ReelsforReels', 5, 8, 13) == 5
assert lcs_of_three('abcd1e2', 'bc12ea', 'bd1ea', 7, 6, 5) == 3
|
|
748 | Write a function to put spaces between words starting with capital letters in a given string by using regex. | capital_words_spaces | import re
def capital_words_spaces(str1):
return re.sub(r"(\w)([A-Z])", r"\1 \2", str1) | [
"assert capital_words_spaces(\"jBJtoJLDMlxySGREVOgmEIf\") == \"j BJto JL DMlxy SG RE VOgm EIf\"",
"assert capital_words_spaces(\"IVLeWrUoATPynvjVajWytFgVX\") == \"I VLe Wr Uo AT Pynvj Vaj Wyt Fg VX\"",
"assert capital_words_spaces(\"RYJxkvVUkefDyfpUwWaIYgNH\") == \"R YJxkv VUkef Dyfp Uw Wa IYg NH\""
] | def check(candidate):
# Check some simple cases
assert capital_words_spaces("Python") == 'Python'
assert capital_words_spaces("PythonProgrammingExamples") == 'Python Programming Examples'
assert capital_words_spaces("GetReadyToBeCodingFreak") == 'Get Ready To Be Coding Freak'
|
|
749 | Write a function to sort a given list of strings of numbers numerically. | sort_numeric_strings | def sort_numeric_strings(nums_str):
result = [int(x) for x in nums_str]
result.sort()
return result | [
"assert sort_numeric_strings(['9', '9', '9', '3', '0', '4', '7123', '195755', '20841', '0', '895563', '5', '4', '784200']) == [0, 0, 3, 4, 4, 5, 9, 9, 9, 7123, 20841, 195755, 784200, 895563]",
"assert sort_numeric_strings(['2', '6', '1', '3', '1', '9', '953', '1873', '9553', '8', '90081', '5', '1', '234353']) == [1, 1, 1, 2, 3, 5, 6, 8, 9, 953, 1873, 9553, 90081, 234353]",
"assert sort_numeric_strings(['1', '5', '6', '2', '3', '4', '4656', '885', '94432', '4', '60059', '1', '2', '749104']) == [1, 1, 2, 2, 3, 4, 4, 5, 6, 885, 4656, 60059, 94432, 749104]"
] | def check(candidate):
# Check some simple cases
assert sort_numeric_strings( ['4','12','45','7','0','100','200','-12','-500'])==[-500, -12, 0, 4, 7, 12, 45, 100, 200]
assert sort_numeric_strings(['2','3','8','4','7','9','8','2','6','5','1','6','1','2','3','4','6','9','1','2'])==[1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8, 9, 9]
assert sort_numeric_strings(['1','3','5','7','1', '3','13', '15', '17','5', '7 ','9','1', '11'])==[1, 1, 1, 3, 3, 5, 5, 7, 7, 9, 11, 13, 15, 17]
|
|
750 | Write a function to add the given tuple to the given list. | add_tuple | def add_tuple(test_list, test_tup):
test_list += test_tup
return (test_list) | [
"assert add_tuple([12, 6, 14], (9, 15)) == [12, 6, 14, 9, 15]",
"assert add_tuple([6, 3, 11], (8, 11)) == [6, 3, 11, 8, 11]",
"assert add_tuple([7, 5, 7], (12, 15)) == [7, 5, 7, 12, 15]"
] | def check(candidate):
# Check some simple cases
assert add_tuple([5, 6, 7], (9, 10)) == [5, 6, 7, 9, 10]
assert add_tuple([6, 7, 8], (10, 11)) == [6, 7, 8, 10, 11]
assert add_tuple([7, 8, 9], (11, 12)) == [7, 8, 9, 11, 12]
|
|
751 | Write a function to check if the given array represents min heap or not. | check_min_heap | def check_min_heap(arr, i):
if 2 * i + 2 > len(arr):
return True
left_child = (arr[i] <= arr[2 * i + 1]) and check_min_heap(arr, 2 * i + 1)
right_child = (2 * i + 2 == len(arr)) or (arr[i] <= arr[2 * i + 2]
and check_min_heap(arr, 2 * i + 2))
return left_child and right_child | [
"assert check_min_heap([1, 13, 8, 6, 7, 14], 2) == True",
"assert check_min_heap([3, 15, 6, 2, 7, 20], 2) == True",
"assert check_min_heap([7, 7, 4, 8, 8, 18], 1) == True"
] | def check(candidate):
# Check some simple cases
assert check_min_heap([1, 2, 3, 4, 5, 6], 0) == True
assert check_min_heap([2, 3, 4, 5, 10, 15], 0) == True
assert check_min_heap([2, 10, 4, 5, 3, 15], 0) == False
|
|
752 | Write a function to find the nth jacobsthal number. | jacobsthal_num | def jacobsthal_num(n):
dp = [0] * (n + 1)
dp[0] = 0
dp[1] = 1
for i in range(2, n+1):
dp[i] = dp[i - 1] + 2 * dp[i - 2]
return dp[n] | [
"assert jacobsthal_num(1) == 1",
"assert jacobsthal_num(5) == 11",
"assert jacobsthal_num(1) == 1"
] | def check(candidate):
# Check some simple cases
assert jacobsthal_num(5) == 11
assert jacobsthal_num(2) == 1
assert jacobsthal_num(4) == 5
|
|
753 | Write a function to find minimum k records from tuple list. | min_k | def min_k(test_list, K):
res = sorted(test_list, key = lambda x: x[1])[:K]
return (res) | [
"assert min_k([('mue', 14), ('rdcJG', 11), ('SEsTqJfwEbPp', 7), ('JRXGHL', 15)], 3) == [('SEsTqJfwEbPp', 7), ('rdcJG', 11), ('mue', 14)]",
"assert min_k([('iruqm', 13), ('yLZmPXRPF', 8), ('ZeeP', 7), ('MHTJOGU', 21)], 5) == [('ZeeP', 7), ('yLZmPXRPF', 8), ('iruqm', 13), ('MHTJOGU', 21)]",
"assert min_k([('vsuy', 15), ('Jbe', 10), ('dZzaolVaAa', 6), ('VORSC', 18)], 3) == [('dZzaolVaAa', 6), ('Jbe', 10), ('vsuy', 15)]"
] | def check(candidate):
# Check some simple cases
assert min_k([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2) == [('Akash', 2), ('Akshat', 4)]
assert min_k([('Sanjeev', 11), ('Angat', 5), ('Akash', 3), ('Nepin', 9)], 3) == [('Akash', 3), ('Angat', 5), ('Nepin', 9)]
assert min_k([('tanmay', 14), ('Amer', 11), ('Ayesha', 9), ('SKD', 16)], 1) == [('Ayesha', 9)]
|
|
754 | Write a function to find common index elements from three lists. | extract_index_list | def extract_index_list(l1, l2, l3):
result = []
for m, n, o in zip(l1, l2, l3):
if (m == n == o):
result.append(m)
return result | [
"assert extract_index_list([4, 1, 2, 7, 3, 9, 7], [2, 6, 4, 2, 4, 8, 2], [4, 1, 1, 5, 6, 2, 9]) == []",
"assert extract_index_list([6, 5, 3, 8, 9, 10, 11], [4, 1, 2, 4, 3, 7, 9], [3, 6, 4, 1, 5, 4, 12]) == []",
"assert extract_index_list([2, 6, 6, 4, 11, 1, 8], [3, 4, 7, 5, 8, 8, 9], [5, 4, 6, 7, 5, 4, 11]) == []"
] | def check(candidate):
# Check some simple cases
assert extract_index_list([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7])==[1, 7]
assert extract_index_list([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 6, 5],[0, 1, 2, 3, 4, 6, 7])==[1, 6]
assert extract_index_list([1, 1, 3, 4, 6, 5, 6],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7])==[1, 5]
|
|
755 | Write a function to find the second smallest number in a list. | second_smallest | def second_smallest(numbers):
if (len(numbers)<2):
return
if ((len(numbers)==2) and (numbers[0] == numbers[1]) ):
return
dup_items = set()
uniq_items = []
for x in numbers:
if x not in dup_items:
uniq_items.append(x)
dup_items.add(x)
uniq_items.sort()
return uniq_items[1] | [
"assert second_smallest([4, 4]) == None",
"assert second_smallest([6, 1]) == 6",
"assert second_smallest([5, 2]) == 5"
] | def check(candidate):
# Check some simple cases
assert second_smallest([1, 2, -8, -2, 0, -2])==-2
assert second_smallest([1, 1, -0.5, 0, 2, -2, -2])==-0.5
assert second_smallest([2,2])==None
|
|
756 | Write a function that matches a string that has an a followed by zero or one 'b'. | text_match_zero_one | import re
def text_match_zero_one(text):
patterns = 'ab?'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | [
"assert text_match_zero_one(\"nztfocxrm\") == \"Not matched!\"",
"assert text_match_zero_one(\"ochdfl\") == \"Not matched!\"",
"assert text_match_zero_one(\"sanq\") == \"Found a match!\""
] | def check(candidate):
# Check some simple cases
assert text_match_zero_one("ac")==('Found a match!')
assert text_match_zero_one("dc")==('Not matched!')
assert text_match_zero_one("abbbba")==('Found a match!')
|
|
757 | Write a function to count the pairs of reverse strings in the given string list. | count_reverse_pairs | def count_reverse_pairs(test_list):
res = sum([1 for idx in range(0, len(test_list)) for idxn in range(idx, len(
test_list)) if test_list[idxn] == str(''.join(list(reversed(test_list[idx]))))])
return str(res) | [
"assert count_reverse_pairs(['kongjqx', 'fhmdu', 'zcymainum', 'bxif', 'yrvgjv']) == 0",
"assert count_reverse_pairs(['trvfp', 'isyyjv', 'mwpa', 'xvtphpycj', 'eal']) == 0",
"assert count_reverse_pairs(['cdqmkicau', 'yzaxkrezr', 'chmbzl', 'bvez', 'xogpifgj']) == 0"
] | def check(candidate):
# Check some simple cases
assert count_reverse_pairs(["julia", "best", "tseb", "for", "ailuj"])== '2'
assert count_reverse_pairs(["geeks", "best", "for", "skeeg"]) == '1'
assert count_reverse_pairs(["makes", "best", "sekam", "for", "rof"]) == '2'
|
|
758 | Write a function to count number of unique lists within a list. | unique_sublists | def unique_sublists(list1):
result ={}
for l in list1:
result.setdefault(tuple(l), list()).append(1)
for a, b in result.items():
result[a] = sum(b)
return result | [
"assert unique_sublists([[7, 22, 26, 43], [63, 74, 48, 53], [91, 103, 200]]) == {(7, 22, 26, 43): 1, (63, 74, 48, 53): 1, (91, 103, 200): 1}",
"assert unique_sublists([[13, 25, 26, 43], [65, 67, 46, 50], [89, 100, 204]]) == {(13, 25, 26, 43): 1, (65, 67, 46, 50): 1, (89, 100, 204): 1}",
"assert unique_sublists([[14, 17, 33, 41], [63, 70, 50, 47], [95, 99, 203]]) == {(14, 17, 33, 41): 1, (63, 70, 50, 47): 1, (95, 99, 203): 1}"
] | def check(candidate):
# Check some simple cases
assert unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]] )=={(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1}
assert unique_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']])=={('green', 'orange'): 2, ('black',): 1, ('white',): 1}
assert unique_sublists([[10, 20, 30, 40], [60, 70, 50, 50], [90, 100, 200]])=={(10, 20, 30, 40): 1, (60, 70, 50, 50): 1, (90, 100, 200): 1}
|
|
759 | Write a function to check a decimal with a precision of 2. | is_decimal | def is_decimal(num):
import re
dnumre = re.compile(r"""^[0-9]+(\.[0-9]{1,2})?$""")
result = dnumre.search(num)
return bool(result) | [
"assert is_decimal(\"9985...4\") == False",
"assert is_decimal(\"218\") == True",
"assert is_decimal(\"5056386\") == True"
] | def check(candidate):
# Check some simple cases
assert is_decimal('123.11')==True
assert is_decimal('e666.86')==False
assert is_decimal('3.124587')==False
|
|
760 | Write a python function to check whether an array contains only one distinct element or not. | unique_Element | def unique_Element(arr,n):
s = set(arr)
if (len(s) == 1):
return ('YES')
else:
return ('NO') | [
"assert unique_Element([3, 2, 3, 2, 4], 1) == \"NO\"",
"assert unique_Element([3, 6, 7, 8, 1], 3) == \"NO\"",
"assert unique_Element([1, 7, 5, 2, 3], 8) == \"NO\""
] | def check(candidate):
# Check some simple cases
assert unique_Element([1,1,1],3) == 'YES'
assert unique_Element([1,2,1,2],4) == 'NO'
assert unique_Element([1,2,3,4,5],5) == 'NO'
|
|
761 | Write a function to caluclate arc length of an angle. | arc_length | def arc_length(d,a):
pi=22/7
if a >= 360:
return None
arclength = (pi*d) * (a/360)
return arclength | [
"assert arc_length(6, 269) == 14.09047619047619",
"assert arc_length(6, 274) == 14.352380952380953",
"assert arc_length(2, 268) == 4.67936507936508"
] | def check(candidate):
# Check some simple cases
assert arc_length(9,45)==3.5357142857142856
assert arc_length(9,480)==None
assert arc_length(5,270)==11.785714285714285
|
|
762 | Write a function to check whether the given month number contains 30 days or not. | check_monthnumber_number | def check_monthnumber_number(monthnum3):
if(monthnum3==4 or monthnum3==6 or monthnum3==9 or monthnum3==11):
return True
else:
return False | [
"assert check_monthnumber_number(8) == False",
"assert check_monthnumber_number(17) == False",
"assert check_monthnumber_number(15) == False"
] | def check(candidate):
# Check some simple cases
assert check_monthnumber_number(6)==True
assert check_monthnumber_number(2)==False
assert check_monthnumber_number(12)==False
|
|
763 | Write a python function to find the minimum difference between any two elements in a given array. | find_Min_Diff | def find_Min_Diff(arr,n):
arr = sorted(arr)
diff = 10**20
for i in range(n-1):
if arr[i+1] - arr[i] < diff:
diff = arr[i+1] - arr[i]
return diff | [
"assert find_Min_Diff((30, 6, 15, 10), 3) == 4",
"assert find_Min_Diff((31, 9, 20, 8), 2) == 1",
"assert find_Min_Diff((31, 7, 24, 8), 3) == 1"
] | def check(candidate):
# Check some simple cases
assert find_Min_Diff((1,5,3,19,18,25),6) == 1
assert find_Min_Diff((4,3,2,6),4) == 1
assert find_Min_Diff((30,5,20,9),4) == 4
|
|
764 | Write a python function to count numeric values in a given string. | number_ctr | def number_ctr(str):
number_ctr= 0
for i in range(len(str)):
if str[i] >= '0' and str[i] <= '9': number_ctr += 1
return number_ctr | [
"assert number_ctr(\"360\") == 3",
"assert number_ctr(\"181\") == 3",
"assert number_ctr(\"5906695\") == 7"
] | def check(candidate):
# Check some simple cases
assert number_ctr('program2bedone') == 1
assert number_ctr('3wonders') ==1
assert number_ctr('123') == 3
|
|
765 | Write a function to find nth polite number. | is_polite | import math
def is_polite(n):
n = n + 1
return (int)(n+(math.log((n + math.log(n, 2)), 2))) | [
"assert is_polite(12) == 17",
"assert is_polite(14) == 19",
"assert is_polite(5) == 9"
] | def check(candidate):
# Check some simple cases
assert is_polite(7) == 11
assert is_polite(4) == 7
assert is_polite(9) == 13
|
|
766 | Write a function to iterate over all pairs of consecutive items in a given list. | pair_wise | def pair_wise(l1):
temp = []
for i in range(len(l1) - 1):
current_element, next_element = l1[i], l1[i + 1]
x = (current_element, next_element)
temp.append(x)
return temp | [
"assert pair_wise([4, 3, 1, 5, 7, 6, 6, 13, 10, 13]) == [(4, 3), (3, 1), (1, 5), (5, 7), (7, 6), (6, 6), (6, 13), (13, 10), (10, 13)]",
"assert pair_wise([3, 6, 6, 6, 7, 11, 5, 3, 13, 9]) == [(3, 6), (6, 6), (6, 6), (6, 7), (7, 11), (11, 5), (5, 3), (3, 13), (13, 9)]",
"assert pair_wise([6, 2, 6, 5, 1, 11, 6, 13, 10, 13]) == [(6, 2), (2, 6), (6, 5), (5, 1), (1, 11), (11, 6), (6, 13), (13, 10), (10, 13)]"
] | def check(candidate):
# Check some simple cases
assert pair_wise([1,1,2,3,3,4,4,5])==[(1, 1), (1, 2), (2, 3), (3, 3), (3, 4), (4, 4), (4, 5)]
assert pair_wise([1,5,7,9,10])==[(1, 5), (5, 7), (7, 9), (9, 10)]
assert pair_wise([1,2,3,4,5,6,7,8,9,10])==[(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9), (9, 10)]
|
|
767 | Write a python function to count the number of pairs whose sum is equal to ‘sum’. | get_Pairs_Count | def get_Pairs_Count(arr,n,sum):
count = 0
for i in range(0,n):
for j in range(i + 1,n):
if arr[i] + arr[j] == sum:
count += 1
return count | [
"assert get_Pairs_Count([2, -6, 2], 2, 5) == 0",
"assert get_Pairs_Count([2, -6, 4], 3, 1) == 0",
"assert get_Pairs_Count([5, -3, 3], 3, 5) == 0"
] | def check(candidate):
# Check some simple cases
assert get_Pairs_Count([1,1,1,1],4,2) == 6
assert get_Pairs_Count([1,5,7,-1,5],5,6) == 3
assert get_Pairs_Count([1,-2,3],3,1) == 1
|
|
768 | Write a python function to check for odd parity of a given number. | check_Odd_Parity | def check_Odd_Parity(x):
parity = 0
while (x != 0):
x = x & (x - 1)
parity += 1
if (parity % 2 == 1):
return True
else:
return False | [
"assert check_Odd_Parity(23) == False",
"assert check_Odd_Parity(18) == False",
"assert check_Odd_Parity(23) == False"
] | def check(candidate):
# Check some simple cases
assert check_Odd_Parity(13) == True
assert check_Odd_Parity(21) == True
assert check_Odd_Parity(18) == False
|
|
769 | Write a python function to get the difference between two lists. | null | def Diff(li1,li2):
return (list(list(set(li1)-set(li2)) + list(set(li2)-set(li1))))
| [
"assert Diff([4, 4, 6], [8, 7, 3]) == [4, 6, 8, 3, 7]",
"assert Diff([2, 2, 2], [6, 6, 2]) == [6]",
"assert Diff([1, 2, 8], [2, 9, 1]) == [8, 9]"
] | def check(candidate):
# Check some simple cases
assert (Diff([10, 15, 20, 25, 30, 35, 40], [25, 40, 35])) == [10, 20, 30, 15]
assert (Diff([1,2,3,4,5], [6,7,1])) == [2,3,4,5,6,7]
assert (Diff([1,2,3], [6,7,1])) == [2,3,6,7]
|
|
770 | Write a python function to find the sum of fourth power of first n odd natural numbers. | odd_Num_Sum | def odd_Num_Sum(n) :
j = 0
sm = 0
for i in range(1,n + 1) :
j = (2*i-1)
sm = sm + (j*j*j*j)
return sm | [
"assert odd_Num_Sum(6) == 24310",
"assert odd_Num_Sum(2) == 82",
"assert odd_Num_Sum(2) == 82"
] | def check(candidate):
# Check some simple cases
assert odd_Num_Sum(2) == 82
assert odd_Num_Sum(3) == 707
assert odd_Num_Sum(4) == 3108
|
|
771 | Write a function to check if the given expression is balanced or not. | check_expression | from collections import deque
def check_expression(exp):
if len(exp) & 1:
return False
stack = deque()
for ch in exp:
if ch == '(' or ch == '{' or ch == '[':
stack.append(ch)
if ch == ')' or ch == '}' or ch == ']':
if not stack:
return False
top = stack.pop()
if (top == '(' and ch != ')') or (top == '{' and ch != '}' or (top == '[' and ch != ']')):
return False
return not stack | [
"assert check_expression(\">)>[[<[[}{>{\") == False",
"assert check_expression(\"[[)<{>]<<(>>])){}[\") == False",
"assert check_expression(\"<[}){}}}]>]\") == False"
] | def check(candidate):
# Check some simple cases
assert check_expression("{()}[{}]") == True
assert check_expression("{()}[{]") == False
assert check_expression("{()}[{}][]({})") == True
|
|
772 | Write a function to remove all the words with k length in the given string. | remove_length | def remove_length(test_str, K):
temp = test_str.split()
res = [ele for ele in temp if len(ele) != K]
res = ' '.join(res)
return (res) | [
"assert remove_length('AGEsoWBRruk EiWkWPXIUnWDmYODJkbjfTn AZdOdi', 5) == \"AGEsoWBRruk EiWkWPXIUnWDmYODJkbjfTn AZdOdi\"",
"assert remove_length('IjrMMlCqQLKR BcusnFqtBCzoiKR kkPEnk qMCyIBwR', 3) == \"IjrMMlCqQLKR BcusnFqtBCzoiKR kkPEnk qMCyIBwR\"",
"assert remove_length('aDiDHfwikjFpphJGyRDrJOJoajc wT ocvbHY', 5) == \"aDiDHfwikjFpphJGyRDrJOJoajc wT ocvbHY\""
] | def check(candidate):
# Check some simple cases
assert remove_length('The person is most value tet', 3) == 'person is most value'
assert remove_length('If you told me about this ok', 4) == 'If you me about ok'
assert remove_length('Forces of darkeness is come into the play', 4) == 'Forces of darkeness is the'
|
|
773 | Write a function to find the occurrence and position of the substrings within a string. | occurance_substring | import re
def occurance_substring(text,pattern):
for match in re.finditer(pattern, text):
s = match.start()
e = match.end()
return (text[s:e], s, e) | [
"assert occurance_substring('nb,epqozhdpfzmrpyhtawsbbhrda qcycuq,u n', 'aamiwozs') == None",
"assert occurance_substring('mlfnrguwwfdqovqncpbnygmjr,izmemmdbrhh', 'vnyfdz') == None",
"assert occurance_substring('zvwehasiv fy umoqzkptzrgk,j,mnyagfzbrjwrds', 'fszwkww') == None"
] | def check(candidate):
# Check some simple cases
assert occurance_substring('python programming, python language','python')==('python', 0, 6)
assert occurance_substring('python programming,programming language','programming')==('programming', 7, 18)
assert occurance_substring('python programming,programming language','language')==('language', 31, 39)
|
|
774 | Write a function to check if the string is a valid email address or not using regex. | check_email | import re
regex = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
def check_email(email):
if(re.search(regex,email)):
return ("Valid Email")
else:
return ("Invalid Email") | [
"assert check_email(\"pv412my9xwi2kdm2\") == \"Invalid Email\"",
"assert check_email(\"dw30d42kgvp.\") == \"Invalid Email\"",
"assert check_email(\"21s31fatgwe3ebkfni\") == \"Invalid Email\""
] | def check(candidate):
# Check some simple cases
assert check_email("[email protected]") == 'Valid Email'
assert check_email("[email protected]") == 'Valid Email'
assert check_email("ankitaoie326.com") == 'Invalid Email'
|
|
775 | Write a python function to check whether every odd index contains odd numbers of a given list. | odd_position | def odd_position(nums):
return all(nums[i]%2==i%2 for i in range(len(nums))) | [
"assert odd_position([3, 6, 2]) == False",
"assert odd_position([3, 7, 5]) == False",
"assert odd_position([3, 7, 8]) == False"
] | def check(candidate):
# Check some simple cases
assert odd_position([2,1,4,3,6,7,6,3]) == True
assert odd_position([4,1,2]) == True
assert odd_position([1,2,3]) == False
|
|
776 | Write a function to count those characters which have vowels as their neighbors in the given string. | count_vowels | def count_vowels(test_str):
res = 0
vow_list = ['a', 'e', 'i', 'o', 'u']
for idx in range(1, len(test_str) - 1):
if test_str[idx] not in vow_list and (test_str[idx - 1] in vow_list or test_str[idx + 1] in vow_list):
res += 1
if test_str[0] not in vow_list and test_str[1] in vow_list:
res += 1
if test_str[-1] not in vow_list and test_str[-2] in vow_list:
res += 1
return (res) | [
"assert count_vowels(\"tdduoy\") == 2",
"assert count_vowels(\"zhqddoqnbrc\") == 2",
"assert count_vowels(\"ftfqbfzscpzwa\") == 1"
] | def check(candidate):
# Check some simple cases
assert count_vowels('bestinstareels') == 7
assert count_vowels('partofthejourneyistheend') == 12
assert count_vowels('amazonprime') == 5
|
|
777 | Write a python function to find the sum of non-repeated elements in a given array. | find_Sum | def find_Sum(arr,n):
arr.sort()
sum = arr[0]
for i in range(0,n-1):
if (arr[i] != arr[i+1]):
sum = sum + arr[i+1]
return sum | [
"assert find_Sum([17, 5, 6, 50, 3, 11, 5, 42, 13], 9) == 147",
"assert find_Sum([8, 7, 10, 40, 4, 11, 12, 46, 15], 8) == 107",
"assert find_Sum([15, 14, 10, 48, 7, 13, 8, 47, 11], 7) == 78"
] | def check(candidate):
# Check some simple cases
assert find_Sum([1,2,3,1,1,4,5,6],8) == 21
assert find_Sum([1,10,9,4,2,10,10,45,4],9) == 71
assert find_Sum([12,10,9,45,2,10,10,45,10],9) == 78
|
|
778 | Write a function to pack consecutive duplicates of a given list elements into sublists. | pack_consecutive_duplicates | from itertools import groupby
def pack_consecutive_duplicates(list1):
return [list(group) for key, group in groupby(list1)] | [
"assert pack_consecutive_duplicates(['c', 'g', 'z', 'f', 'g', 'a']) == [['c'], ['g'], ['z'], ['f'], ['g'], ['a']]",
"assert pack_consecutive_duplicates(['j', 'r', 's', 'f', 'g', 'u']) == [['j'], ['r'], ['s'], ['f'], ['g'], ['u']]",
"assert pack_consecutive_duplicates(['w', 'g', 'o', 'b', 'i', 'f']) == [['w'], ['g'], ['o'], ['b'], ['i'], ['f']]"
] | def check(candidate):
# Check some simple cases
assert pack_consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4])==[[0, 0], [1], [2], [3], [4, 4], [5], [6, 6, 6], [7], [8], [9], [4, 4]]
assert pack_consecutive_duplicates([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10])==[[10, 10], [15], [19], [18, 18], [17], [26, 26], [17], [18], [10]]
assert pack_consecutive_duplicates(['a', 'a', 'b', 'c', 'd', 'd'])==[['a', 'a'], ['b'], ['c'], ['d', 'd']]
|
|
779 | Write a function to count the number of unique lists within a list. | unique_sublists | def unique_sublists(list1):
result ={}
for l in list1:
result.setdefault(tuple(l), list()).append(1)
for a, b in result.items():
result[a] = sum(b)
return result | [
"assert unique_sublists([[3, 2], [8, 4], [3, 7], [3, 2]]) == {(3, 2): 2, (8, 4): 1, (3, 7): 1}",
"assert unique_sublists([[6, 7], [3, 6], [6, 4], [9, 2]]) == {(6, 7): 1, (3, 6): 1, (6, 4): 1, (9, 2): 1}",
"assert unique_sublists([[5, 7], [7, 1], [7, 10], [8, 11]]) == {(5, 7): 1, (7, 1): 1, (7, 10): 1, (8, 11): 1}"
] | def check(candidate):
# Check some simple cases
assert unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]])=={(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1}
assert unique_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']])=={('green', 'orange'): 2, ('black',): 1, ('white',): 1}
assert unique_sublists([[1, 2], [3, 4], [4, 5], [6, 7]])=={(1, 2): 1, (3, 4): 1, (4, 5): 1, (6, 7): 1}
|
|
780 | Write a function to find the combinations of sums with tuples in the given tuple list. | find_combinations | from itertools import combinations
def find_combinations(test_list):
res = [(b1 + a1, b2 + a2) for (a1, a2), (b1, b2) in combinations(test_list, 2)]
return (res) | [
"assert find_combinations([(6, 10), (9, 4), (2, 6), (12, 17)]) == [(15, 14), (8, 16), (18, 27), (11, 10), (21, 21), (14, 23)]",
"assert find_combinations([(3, 8), (11, 6), (3, 8), (7, 8)]) == [(14, 14), (6, 16), (10, 16), (14, 14), (18, 14), (10, 16)]",
"assert find_combinations([(9, 6), (7, 13), (5, 3), (4, 13)]) == [(16, 19), (14, 9), (13, 19), (12, 16), (11, 26), (9, 16)]"
] | def check(candidate):
# Check some simple cases
assert find_combinations([(2, 4), (6, 7), (5, 1), (6, 10)]) == [(8, 11), (7, 5), (8, 14), (11, 8), (12, 17), (11, 11)]
assert find_combinations([(3, 5), (7, 8), (6, 2), (7, 11)]) == [(10, 13), (9, 7), (10, 16), (13, 10), (14, 19), (13, 13)]
assert find_combinations([(4, 6), (8, 9), (7, 3), (8, 12)]) == [(12, 15), (11, 9), (12, 18), (15, 12), (16, 21), (15, 15)]
|
|
781 | Write a python function to check whether the count of divisors is even or odd. | count_Divisors | import math
def count_Divisors(n) :
count = 0
for i in range(1, (int)(math.sqrt(n)) + 2) :
if (n % i == 0) :
if( n // i == i) :
count = count + 1
else :
count = count + 2
if (count % 2 == 0) :
return ("Even")
else :
return ("Odd") | [
"assert count_Divisors(125) == \"Even\"",
"assert count_Divisors(130) == \"Even\"",
"assert count_Divisors(122) == \"Even\""
] | def check(candidate):
# Check some simple cases
assert count_Divisors(10) == "Even"
assert count_Divisors(100) == "Odd"
assert count_Divisors(125) == "Even"
|
|
782 | Write a python function to find the sum of all odd length subarrays. | Odd_Length_Sum | def Odd_Length_Sum(arr):
Sum = 0
l = len(arr)
for i in range(l):
Sum += ((((i + 1) *(l - i) + 1) // 2) * arr[i])
return Sum | [
"assert Odd_Length_Sum([1, 10]) == 11",
"assert Odd_Length_Sum([2, 5]) == 7",
"assert Odd_Length_Sum([4, 4]) == 8"
] | def check(candidate):
# Check some simple cases
assert Odd_Length_Sum([1,2,4]) == 14
assert Odd_Length_Sum([1,2,1,2]) == 15
assert Odd_Length_Sum([1,7]) == 8
|
|
783 | Write a function to convert rgb color to hsv color. | rgb_to_hsv | def rgb_to_hsv(r, g, b):
r, g, b = r/255.0, g/255.0, b/255.0
mx = max(r, g, b)
mn = min(r, g, b)
df = mx-mn
if mx == mn:
h = 0
elif mx == r:
h = (60 * ((g-b)/df) + 360) % 360
elif mx == g:
h = (60 * ((b-r)/df) + 120) % 360
elif mx == b:
h = (60 * ((r-g)/df) + 240) % 360
if mx == 0:
s = 0
else:
s = (df/mx)*100
v = mx*100
return h, s, v | [
"assert rgb_to_hsv(6, 214, 105) == (148.55769230769232, 97.19626168224299, 83.92156862745098)",
"assert rgb_to_hsv(8, 214, 107) == (148.83495145631068, 96.26168224299066, 83.92156862745098)",
"assert rgb_to_hsv(11, 220, 111) == (148.70813397129186, 95.0, 86.27450980392157)"
] | def check(candidate):
# Check some simple cases
assert rgb_to_hsv(255, 255, 255)==(0, 0.0, 100.0)
assert rgb_to_hsv(0, 215, 0)==(120.0, 100.0, 84.31372549019608)
assert rgb_to_hsv(10, 215, 110)==(149.26829268292684, 95.34883720930233, 84.31372549019608)
|
|
784 | Write a function to find the product of first even and odd number of a given list. | mul_even_odd | def mul_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 mul_even_odd([4, 10, 2, 7, 8]) == 28",
"assert mul_even_odd([3, 4, 11, 13, 11]) == 12",
"assert mul_even_odd([4, 10, 2, 6, 12]) == -4"
] | def check(candidate):
# Check some simple cases
assert mul_even_odd([1,3,5,7,4,1,6,8])==4
assert mul_even_odd([1,2,3,4,5,6,7,8,9,10])==2
assert mul_even_odd([1,5,7,9,10])==10
|
|
785 | Write a function to convert tuple string to integer tuple. | tuple_str_int | def tuple_str_int(test_str):
res = tuple(int(num) for num in test_str.replace('(', '').replace(')', '').replace('...', '').split(', '))
return (res) | [
"assert tuple_str_int(\")50314\") == (50314,)",
"assert tuple_str_int(\"8008)21\") == (800821,)",
"assert tuple_str_int(\")5()297))\") == (5297,)"
] | def check(candidate):
# Check some simple cases
assert tuple_str_int("(7, 8, 9)") == (7, 8, 9)
assert tuple_str_int("(1, 2, 3)") == (1, 2, 3)
assert tuple_str_int("(4, 5, 6)") == (4, 5, 6)
|
|
786 | Write a function to locate the right insertion point for a specified value in sorted order. | right_insertion | import bisect
def right_insertion(a, x):
i = bisect.bisect_right(a, x)
return i | [
"assert right_insertion([3, 5, 2, 7], 7) == 4",
"assert right_insertion([2, 7, 4, 8], 3) == 1",
"assert right_insertion([2, 5, 8, 6], 2) == 1"
] | def check(candidate):
# Check some simple cases
assert right_insertion([1,2,4,5],6)==4
assert right_insertion([1,2,4,5],3)==2
assert right_insertion([1,2,4,5],7)==4
|
|
787 | Write a function that matches a string that has an a followed by three 'b'. | text_match_three | import re
def text_match_three(text):
patterns = 'ab{3}?'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | [
"assert text_match_three(\"gwftzvmcw\") == \"Not matched!\"",
"assert text_match_three(\"kxdvtzebrmo\") == \"Not matched!\"",
"assert text_match_three(\"irgtsyeimz\") == \"Not matched!\""
] | def check(candidate):
# Check some simple cases
assert text_match_three("ac")==('Not matched!')
assert text_match_three("dc")==('Not matched!')
assert text_match_three("abbbba")==('Found a match!')
|
|
788 | Write a function to create a new tuple from the given string and list. | new_tuple | def new_tuple(test_list, test_str):
res = tuple(test_list + [test_str])
return (res) | [
"assert new_tuple(['bzwROBO', 'kohs'], 'jPCwtqg') == ('bzwROBO', 'kohs', 'jPCwtqg')",
"assert new_tuple(['UtAhccGi', 'dvdcb'], 'Pwvb') == ('UtAhccGi', 'dvdcb', 'Pwvb')",
"assert new_tuple(['hxa', 'mvsa'], 'nPxZCZea') == ('hxa', 'mvsa', 'nPxZCZea')"
] | def check(candidate):
# Check some simple cases
assert new_tuple(["WEB", "is"], "best") == ('WEB', 'is', 'best')
assert new_tuple(["We", "are"], "Developers") == ('We', 'are', 'Developers')
assert new_tuple(["Part", "is"], "Wrong") == ('Part', 'is', 'Wrong')
|
|
789 | Write a function to calculate the perimeter of a regular polygon. | perimeter_polygon | from math import tan, pi
def perimeter_polygon(s,l):
perimeter = s*l
return perimeter | [
"assert perimeter_polygon(14, 6) == 84",
"assert perimeter_polygon(7, 4) == 28",
"assert perimeter_polygon(6, 12) == 72"
] | def check(candidate):
# Check some simple cases
assert perimeter_polygon(4,20)==80
assert perimeter_polygon(10,15)==150
assert perimeter_polygon(9,7)==63
|
|
790 | Write a python function to check whether every even index contains even numbers of a given list. | even_position | def even_position(nums):
return all(nums[i]%2==i%2 for i in range(len(nums))) | [
"assert even_position([7, 5, 6]) == False",
"assert even_position([4, 5, 1]) == False",
"assert even_position([4, 5, 8]) == True"
] | def check(candidate):
# Check some simple cases
assert even_position([3,2,1]) == False
assert even_position([1,2,3]) == False
assert even_position([2,1,4]) == True
|
|
791 | Write a function to remove the nested record from the given tuple. | remove_nested | def remove_nested(test_tup):
res = tuple()
for count, ele in enumerate(test_tup):
if not isinstance(ele, tuple):
res = res + (ele, )
return (res) | [
"assert remove_nested((5, 6, 6, (4, 11), 11)) == (5, 6, 6, 11)",
"assert remove_nested((5, 12, 4, (6, 10), 7)) == (5, 12, 4, 7)",
"assert remove_nested((7, 12, 14, (6, 10), 8)) == (7, 12, 14, 8)"
] | def check(candidate):
# Check some simple cases
assert remove_nested((1, 5, 7, (4, 6), 10)) == (1, 5, 7, 10)
assert remove_nested((2, 6, 8, (5, 7), 11)) == (2, 6, 8, 11)
assert remove_nested((3, 7, 9, (6, 8), 12)) == (3, 7, 9, 12)
|
|
792 | Write a python function to count the number of lists in a given number of lists. | count_list | def count_list(input_list):
return len(input_list) | [
"assert count_list([[4, 3], [7, 3]]) == 2",
"assert count_list([[1, 3], [3, 2]]) == 2",
"assert count_list([[6, 1], [1, 2]]) == 2"
] | def check(candidate):
# Check some simple cases
assert count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]]) == 4
assert count_list([[1,2],[2,3],[4,5]]) == 3
assert count_list([[1,0],[2,0]]) == 2
|
|
793 | Write a python function to find the last position of an element in a sorted array. | last | def last(arr,x,n):
low = 0
high = n - 1
res = -1
while (low <= high):
mid = (low + high) // 2
if arr[mid] > x:
high = mid - 1
elif arr[mid] < x:
low = mid + 1
else:
res = mid
low = mid + 1
return res | [
"assert last([6, 1, 5, 2, 6, 13, 8], 7, 6) == -1",
"assert last([1, 4, 3, 8, 8, 13, 13], 6, 8) == -1",
"assert last([2, 1, 7, 8, 4, 5, 7], 1, 4) == 1"
] | def check(candidate):
# Check some simple cases
assert last([1,2,3],1,3) == 0
assert last([1,1,1,2,3,4],1,6) == 2
assert last([2,3,2,3,6,8,9],3,8) == 3
|
|
794 | Write a function that matches a string that has an 'a' followed by anything, ending in 'b'. | text_starta_endb | import re
def text_starta_endb(text):
patterns = 'a.*?b$'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | [
"assert text_starta_endb(\"gcugvjrzyg\") == \"Not matched!\"",
"assert text_starta_endb(\"wqmsutwmveg\") == \"Not matched!\"",
"assert text_starta_endb(\"usjhbxj\") == \"Not matched!\""
] | def check(candidate):
# Check some simple cases
assert text_starta_endb("aabbbb")==('Found a match!')
assert text_starta_endb("aabAbbbc")==('Not matched!')
assert text_starta_endb("accddbbjjj")==('Not matched!')
|
|
795 | Write a function to find the n - cheap price items from a given dataset using heap queue algorithm. | cheap_items | import heapq
def cheap_items(items,n):
cheap_items = heapq.nsmallest(n, items, key=lambda s: s['price'])
return cheap_items | [
"assert cheap_items([{\"name\": \"Item-1\", \"price\": 1049.07}, {\"name\": \"Item-2\", \"price\": 417.45}, {\"name\": \"Item-3\", \"price\": 1540.3}, {\"name\": \"Item-4\", \"price\": 2816.5}, {\"name\": \"Item-5\", \"price\": 11.68}, {\"name\": \"Item-6\", \"price\": 129.92}, {\"name\": \"Item-7\", \"price\": 3265.6}, {\"name\": \"Item-8\", \"price\": 894.4499999999999}, {\"name\": \"Item-9\", \"price\": 2302.3199999999997}, {\"name\": \"Item-10\", \"price\": 1450.36}, {\"name\": \"Item-11\", \"price\": 8031.55}, {\"name\": \"Item-12\", \"price\": 5486.780000000001}, {\"name\": \"Item-13\", \"price\": 1369.45}, {\"name\": \"Item-14\", \"price\": 181.76999999999998}, {\"name\": \"Item-15\", \"price\": 3281.52}, {\"name\": \"Item-16\", \"price\": 1094.08}, {\"name\": \"Item-17\", \"price\": 3306.81}, {\"name\": \"Item-18\", \"price\": 2850.4800000000005}, {\"name\": \"Item-19\", \"price\": 6733.51}, {\"name\": \"Item-20\", \"price\": 5177.070000000001}, {\"name\": \"Item-21\", \"price\": 866.7}, {\"name\": \"Item-22\", \"price\": 374.96}, {\"name\": \"Item-23\", \"price\": 464.31000000000006}, {\"name\": \"Item-24\", \"price\": 2570.04}, {\"name\": \"Item-25\", \"price\": 3769.92}, {\"name\": \"Item-26\", \"price\": 604.9399999999999}, {\"name\": \"Item-27\", \"price\": 560.0699999999999}, {\"name\": \"Item-28\", \"price\": 264.44}, {\"name\": \"Item-29\", \"price\": 3234.0599999999995}, {\"name\": \"Item-30\", \"price\": 1699.05}, {\"name\": \"Item-31\", \"price\": 641.5899999999999}, {\"name\": \"Item-32\", \"price\": 1226.16}, {\"name\": \"Item-33\", \"price\": 124.74000000000001}, {\"name\": \"Item-34\", \"price\": 896.35}, {\"name\": \"Item-35\", \"price\": 2791.8}, {\"name\": \"Item-36\", \"price\": 3844.98}, {\"name\": \"Item-37\", \"price\": 4188.16}, {\"name\": \"Item-38\", \"price\": 1690.92}, {\"name\": \"Item-39\", \"price\": 759.85}, {\"name\": \"Item-40\", \"price\": 306.71999999999997}, {\"name\": \"Item-41\", \"price\": 6807.93}], 17) == [{'name': 'Item-5', 'price': 11.68}, {'name': 'Item-33', 'price': 124.74000000000001}, {'name': 'Item-6', 'price': 129.92}, {'name': 'Item-14', 'price': 181.76999999999998}, {'name': 'Item-28', 'price': 264.44}, {'name': 'Item-40', 'price': 306.71999999999997}, {'name': 'Item-22', 'price': 374.96}, {'name': 'Item-2', 'price': 417.45}, {'name': 'Item-23', 'price': 464.31000000000006}, {'name': 'Item-27', 'price': 560.0699999999999}, {'name': 'Item-26', 'price': 604.9399999999999}, {'name': 'Item-31', 'price': 641.5899999999999}, {'name': 'Item-39', 'price': 759.85}, {'name': 'Item-21', 'price': 866.7}, {'name': 'Item-8', 'price': 894.4499999999999}, {'name': 'Item-34', 'price': 896.35}, {'name': 'Item-1', 'price': 1049.07}]",
"assert cheap_items([{\"name\": \"Item-1\", \"price\": 2082.54}, {\"name\": \"Item-2\", \"price\": 4371.45}, {\"name\": \"Item-3\", \"price\": 2528.64}, {\"name\": \"Item-4\", \"price\": 5393.54}, {\"name\": \"Item-5\", \"price\": 7410.32}, {\"name\": \"Item-6\", \"price\": 232.56}, {\"name\": \"Item-7\", \"price\": 4186.79}, {\"name\": \"Item-8\", \"price\": 1751.2300000000002}, {\"name\": \"Item-9\", \"price\": 898.6999999999999}, {\"name\": \"Item-10\", \"price\": 1079.06}, {\"name\": \"Item-11\", \"price\": 37.5}, {\"name\": \"Item-12\", \"price\": 7697.3}, {\"name\": \"Item-13\", \"price\": 505.53000000000003}, {\"name\": \"Item-14\", \"price\": 4002.83}, {\"name\": \"Item-15\", \"price\": 3695.3799999999997}, {\"name\": \"Item-16\", \"price\": 2906.28}, {\"name\": \"Item-17\", \"price\": 2264.64}, {\"name\": \"Item-18\", \"price\": 2274.47}, {\"name\": \"Item-19\", \"price\": 5019.03}, {\"name\": \"Item-20\", \"price\": 2380.73}, {\"name\": \"Item-21\", \"price\": 2736.0899999999997}], 3) == [{'name': 'Item-11', 'price': 37.5}, {'name': 'Item-6', 'price': 232.56}, {'name': 'Item-13', 'price': 505.53000000000003}]",
"assert cheap_items([{\"name\": \"Item-1\", \"price\": 103.88}, {\"name\": \"Item-2\", \"price\": 1069.2}, {\"name\": \"Item-3\", \"price\": 2816.73}, {\"name\": \"Item-4\", \"price\": 328.75}, {\"name\": \"Item-5\", \"price\": 1466.6399999999999}, {\"name\": \"Item-6\", \"price\": 2134.2599999999998}, {\"name\": \"Item-7\", \"price\": 5606.65}, {\"name\": \"Item-8\", \"price\": 509.08}, {\"name\": \"Item-9\", \"price\": 1019.2}, {\"name\": \"Item-10\", \"price\": 873.2700000000001}, {\"name\": \"Item-11\", \"price\": 2657.8}, {\"name\": \"Item-12\", \"price\": 5384.7}, {\"name\": \"Item-13\", \"price\": 130.68}, {\"name\": \"Item-14\", \"price\": 4580.0}, {\"name\": \"Item-15\", \"price\": 5564.82}, {\"name\": \"Item-16\", \"price\": 789.9399999999999}, {\"name\": \"Item-17\", \"price\": 132.60999999999999}, {\"name\": \"Item-18\", \"price\": 123.75999999999999}, {\"name\": \"Item-19\", \"price\": 4015.7999999999997}, {\"name\": \"Item-20\", \"price\": 16.1}, {\"name\": \"Item-21\", \"price\": 3588.0}, {\"name\": \"Item-22\", \"price\": 6142.400000000001}, {\"name\": \"Item-23\", \"price\": 4987.799999999999}, {\"name\": \"Item-24\", \"price\": 6656.6}, {\"name\": \"Item-25\", \"price\": 493.68}, {\"name\": \"Item-26\", \"price\": 14.600000000000001}, {\"name\": \"Item-27\", \"price\": 2069.08}, {\"name\": \"Item-28\", \"price\": 10.46}, {\"name\": \"Item-29\", \"price\": 455.7}, {\"name\": \"Item-30\", \"price\": 478.89}, {\"name\": \"Item-31\", \"price\": 1752.24}, {\"name\": \"Item-32\", \"price\": 2688.0}, {\"name\": \"Item-33\", \"price\": 1332.8}, {\"name\": \"Item-34\", \"price\": 1680.84}, {\"name\": \"Item-35\", \"price\": 3416.96}, {\"name\": \"Item-36\", \"price\": 963.8399999999999}, {\"name\": \"Item-37\", \"price\": 946.88}, {\"name\": \"Item-38\", \"price\": 6739.48}, {\"name\": \"Item-39\", \"price\": 5065.5}, {\"name\": \"Item-40\", \"price\": 1382.1}, {\"name\": \"Item-41\", \"price\": 134.55}, {\"name\": \"Item-42\", \"price\": 2914.9399999999996}, {\"name\": \"Item-43\", \"price\": 5946.96}, {\"name\": \"Item-44\", \"price\": 3255.6299999999997}, {\"name\": \"Item-45\", \"price\": 2584.45}, {\"name\": \"Item-46\", \"price\": 4596.200000000001}, {\"name\": \"Item-47\", \"price\": 1218.82}, {\"name\": \"Item-48\", \"price\": 685.02}, {\"name\": \"Item-49\", \"price\": 4173.84}, {\"name\": \"Item-50\", \"price\": 2248.25}, {\"name\": \"Item-51\", \"price\": 3258.9}, {\"name\": \"Item-52\", \"price\": 4464.3}, {\"name\": \"Item-53\", \"price\": 3069.44}, {\"name\": \"Item-54\", \"price\": 745.0799999999999}, {\"name\": \"Item-55\", \"price\": 2081.46}, {\"name\": \"Item-56\", \"price\": 1380.73}, {\"name\": \"Item-57\", \"price\": 690.54}, {\"name\": \"Item-58\", \"price\": 610.05}, {\"name\": \"Item-59\", \"price\": 1834.3000000000002}, {\"name\": \"Item-60\", \"price\": 616.94}, {\"name\": \"Item-61\", \"price\": 2603.6}, {\"name\": \"Item-62\", \"price\": 3521.82}, {\"name\": \"Item-63\", \"price\": 1603.6200000000001}, {\"name\": \"Item-64\", \"price\": 3794.7}, {\"name\": \"Item-65\", \"price\": 1813.05}, {\"name\": \"Item-66\", \"price\": 6197.36}, {\"name\": \"Item-67\", \"price\": 2951.3599999999997}, {\"name\": \"Item-68\", \"price\": 7248.639999999999}, {\"name\": \"Item-69\", \"price\": 2473.87}, {\"name\": \"Item-70\", \"price\": 3289.4999999999995}, {\"name\": \"Item-71\", \"price\": 408.72}, {\"name\": \"Item-72\", \"price\": 3849.6}, {\"name\": \"Item-73\", \"price\": 484.34}, {\"name\": \"Item-74\", \"price\": 652.81}, {\"name\": \"Item-75\", \"price\": 1534.1}, {\"name\": \"Item-76\", \"price\": 876.3}, {\"name\": \"Item-77\", \"price\": 1731.4800000000002}, {\"name\": \"Item-78\", \"price\": 1881.3899999999999}, {\"name\": \"Item-79\", \"price\": 118.34}, {\"name\": \"Item-80\", \"price\": 276.94}, {\"name\": \"Item-81\", \"price\": 6634.759999999999}, {\"name\": \"Item-82\", \"price\": 1527.6}, {\"name\": \"Item-83\", \"price\": 414.0}, {\"name\": \"Item-84\", \"price\": 4662.24}, {\"name\": \"Item-85\", \"price\": 933.24}, {\"name\": \"Item-86\", \"price\": 1455.0}, {\"name\": \"Item-87\", \"price\": 1686.74}, {\"name\": \"Item-88\", \"price\": 1002.84}], 6) == [{'name': 'Item-28', 'price': 10.46}, {'name': 'Item-26', 'price': 14.600000000000001}, {'name': 'Item-20', 'price': 16.1}, {'name': 'Item-1', 'price': 103.88}, {'name': 'Item-79', 'price': 118.34}, {'name': 'Item-18', 'price': 123.75999999999999}]"
] | def check(candidate):
# Check some simple cases
assert cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],1)==[{'name': 'Item-1', 'price': 101.1}]
assert cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],2)==[{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}]
assert cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}, {'name': 'Item-3', 'price': 45.09},{'name': 'Item-4', 'price': 22.75}],1)==[{'name': 'Item-4', 'price': 22.75}]
|
|
796 | Write function to find the sum of all items in the given dictionary. | return_sum | def return_sum(dict):
sum = 0
for i in dict.values():
sum = sum + i
return sum | [
"assert return_sum({'c': 32, 'h': 38, 'i': 47}) == 117",
"assert return_sum({'u': 34, 'l': 44, 'z': 51}) == 129",
"assert return_sum({'p': 36, 't': 44, 'q': 52}) == 132"
] | def check(candidate):
# Check some simple cases
assert return_sum({'a': 100, 'b':200, 'c':300}) == 600
assert return_sum({'a': 25, 'b':18, 'c':45}) == 88
assert return_sum({'a': 36, 'b':39, 'c':49}) == 124
|
|
797 | Write a python function to find the sum of all odd natural numbers within the range l and r. | sum_in_Range | def sum_Odd(n):
terms = (n + 1)//2
sum1 = terms * terms
return sum1
def sum_in_Range(l,r):
return sum_Odd(r) - sum_Odd(l - 1) | [
"assert sum_in_Range(10, 18) == 56",
"assert sum_in_Range(9, 9) == 9",
"assert sum_in_Range(2, 8) == 15"
] | def check(candidate):
# Check some simple cases
assert sum_in_Range(2,5) == 8
assert sum_in_Range(5,7) == 12
assert sum_in_Range(7,13) == 40
|
|
798 | Write a python function to find the sum of an array. | _sum | def _sum(arr):
sum=0
for i in arr:
sum = sum + i
return(sum) | [
"assert _sum([5, 6, 5]) == 16",
"assert _sum([4, 2, 1]) == 7",
"assert _sum([4, 3, 1]) == 8"
] | def check(candidate):
# Check some simple cases
assert _sum([1, 2, 3]) == 6
assert _sum([15, 12, 13, 10]) == 50
assert _sum([0, 1, 2]) == 3
|
|
799 | Write a python function to left rotate the bits of a given number. | left_Rotate | INT_BITS = 32
def left_Rotate(n,d):
return (n << d)|(n >> (INT_BITS - d)) | [
"assert left_Rotate(103, 4) == 1648",
"assert left_Rotate(102, 2) == 408",
"assert left_Rotate(96, 6) == 6144"
] | def check(candidate):
# Check some simple cases
assert left_Rotate(16,2) == 64
assert left_Rotate(10,2) == 40
assert left_Rotate(99,3) == 792
|
|
800 | Write a function to remove all whitespaces from a string. | remove_all_spaces | import re
def remove_all_spaces(text):
return (re.sub(r'\s+', '',text)) | [
"assert remove_all_spaces(\"jrshx kctozlkmfchugsichntf cvvefnmhuz\") == \"jrshxkctozlkmfchugsichntfcvvefnmhuz\"",
"assert remove_all_spaces(\"bmieldqdbjjnznrfdskrlvvesycilc\") == \"bmieldqdbjjnznrfdskrlvvesycilc\"",
"assert remove_all_spaces(\"xecokwlwyvmvofbvqcfjju dpydkusjunzuh\") == \"xecokwlwyvmvofbvqcfjjudpydkusjunzuh\""
] | def check(candidate):
# Check some simple cases
assert remove_all_spaces('python program')==('pythonprogram')
assert remove_all_spaces('python programming language')==('pythonprogramminglanguage')
assert remove_all_spaces('python program')==('pythonprogram')
|
Subsets and Splits