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
|
---|---|---|---|---|---|---|
901 | Write a function to find the smallest multiple of the first n numbers. | smallest_multiple | def smallest_multiple(n):
if (n<=2):
return n
i = n * 2
factors = [number for number in range(n, 1, -1) if number * 2 > n]
while True:
for a in factors:
if i % a != 0:
i += n
break
if (a == factors[-1] and i % a == 0):
return i | [
"assert smallest_multiple(2) == 2",
"assert smallest_multiple(3) == 6",
"assert smallest_multiple(1) == 1"
] | def check(candidate):
# Check some simple cases
assert smallest_multiple(13)==360360
assert smallest_multiple(2)==2
assert smallest_multiple(1)==1
|
|
902 | Write a function to combine two dictionaries by adding values for common keys. | add_dict | from collections import Counter
def add_dict(d1,d2):
add_dict = Counter(d1) + Counter(d2)
return add_dict | [
"assert add_dict({'c': 895, 'q': 903}, {'x': 896, 'w': 897, 'b': 902}) == Counter({'q': 903, 'b': 902, 'w': 897, 'x': 896, 'c': 895})",
"assert add_dict({'i': 905, 'c': 905, 'n': 895}, {'q': 905, 'i': 905, 't': 895}) == Counter({'i': 1810, 'c': 905, 'q': 905, 'n': 895, 't': 895})",
"assert add_dict({'a': 902, 'i': 902, 'n': 902}, {'u': 898, 'g': 897, 's': 897}) == Counter({'a': 902, 'i': 902, 'n': 902, 'u': 898, 'g': 897, 's': 897})"
] | def check(candidate):
# Check some simple cases
assert add_dict({'a': 100, 'b': 200, 'c':300},{'a': 300, 'b': 200, 'd':400})==({'b': 400, 'd': 400, 'a': 400, 'c': 300})
assert add_dict({'a': 500, 'b': 700, 'c':900},{'a': 500, 'b': 600, 'd':900})==({'b': 1300, 'd': 900, 'a': 1000, 'c': 900})
assert add_dict({'a':900,'b':900,'d':900},{'a':900,'b':900,'d':900})==({'b': 1800, 'd': 1800, 'a': 1800})
|
|
903 | Write a python function to count the total unset bits from 1 to n. | count_Unset_Bits | def count_Unset_Bits(n) :
cnt = 0;
for i in range(1,n + 1) :
temp = i;
while (temp) :
if (temp % 2 == 0) :
cnt += 1;
temp = temp // 2;
return cnt; | [
"assert count_Unset_Bits(15) == 17",
"assert count_Unset_Bits(13) == 16",
"assert count_Unset_Bits(15) == 17"
] | def check(candidate):
# Check some simple cases
assert count_Unset_Bits(2) == 1
assert count_Unset_Bits(5) == 4
assert count_Unset_Bits(14) == 17
|
|
904 | Write a function to return true if the given number is even else return false. | even_num | def even_num(x):
if x%2==0:
return True
else:
return False | [
"assert even_num(-5) == False",
"assert even_num(-14) == True",
"assert even_num(-9) == False"
] | def check(candidate):
# Check some simple cases
assert even_num(13.5)==False
assert even_num(0)==True
assert even_num(-9)==False
|
|
905 | Write a python function to find the sum of squares of binomial co-efficients. | sum_of_square | def factorial(start,end):
res = 1
for i in range(start,end + 1):
res *= i
return res
def sum_of_square(n):
return int(factorial(n + 1, 2 * n) /factorial(1, n)) | [
"assert sum_of_square(7) == 3432",
"assert sum_of_square(3) == 20",
"assert sum_of_square(3) == 20"
] | def check(candidate):
# Check some simple cases
assert sum_of_square(4) == 70
assert sum_of_square(5) == 252
assert sum_of_square(2) == 6
|
|
906 | Write a function to extract year, month and date from a url by using regex. | extract_date | import re
def extract_date(url):
return re.findall(r'/(\d{4})/(\d{1,2})/(\d{1,2})/', url) | [
"assert extract_date(\"-csv/5mm87k6cf>e>kc180mti/>w2va-:+yxz#8hbcv!0&3g1=1e9njau@bl/!*7h!9*#:ecmd#1%f@l&p0q/<2#ipnd.j^f<eo8sd.^%/zycb7@s+^b&3sj08?7-4_=%p/~1o&+=sd.d^yd*9rx\") == []",
"assert extract_date(\"i38=3?:>m_8g$u3c=jum3qdwfc+&!6s&~v:k?:myop>ql<>!g-klwifb@rhu:po$|fm36-vtp@$t2z^d|omvx&k#-$ifh0:30br$&h+v//sorc|#8~yyl!6458#qnwk9nicr7h-75k00#!<oq1\") == []",
"assert extract_date(\"nf$s+1j7~15^f+>wi9j_leh|x_1-@%8^qtz/ue58h>~s$8us<>4:-h*h9/sw|>>s.:$-3t=b*2f_gk2ea#w?9o5g<uo1#fp~&30i5%$ki4:-lbvv|9d59.ev&j#yh40hm$6vky9|taw|47l\") == []"
] | def check(candidate):
# Check some simple cases
assert extract_date("https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-norman-tells-author/") == [('2016', '09', '02')]
assert extract_date("https://www.indiatoday.in/movies/celebrities/story/wp/2020/11/03/odeof-sushant-singh-rajput-s-death-his-brother-in-law-shares-advice-for-fans-1749646/") == [('2020', '11', '03')]
assert extract_date("https://economictimes.indiatimes.com/news/economy/2020/12/29/finance/pension-assets-under-pfrda-touch-rs-5-32-lakh-crore/articleshow/79736619.cms") == [('2020', '12', '29')]
|
|
907 | Write a function to print the first n lucky numbers. | lucky_num | def lucky_num(n):
List=range(-1,n*n+9,2)
i=2
while List[i:]:List=sorted(set(List)-set(List[List[i]::List[i]]));i+=1
return List[1:n+1] | [
"assert lucky_num(3) == [1, 3, 7]",
"assert lucky_num(12) == [1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43]",
"assert lucky_num(3) == [1, 3, 7]"
] | def check(candidate):
# Check some simple cases
assert lucky_num(10)==[1, 3, 7, 9, 13, 15, 21, 25, 31, 33]
assert lucky_num(5)==[1, 3, 7, 9, 13]
assert lucky_num(8)==[1, 3, 7, 9, 13, 15, 21, 25]
|
|
908 | Write a function to find the fixed point in the given array. | find_fixed_point | def find_fixed_point(arr, n):
for i in range(n):
if arr[i] is i:
return i
return -1 | [
"assert find_fixed_point([5, 2, 6, 5, 21], 2) == -1",
"assert find_fixed_point([1, 1, 9, 4, 21], 10) == 1",
"assert find_fixed_point([3, 5, 6, 4, 14], 2) == -1"
] | def check(candidate):
# Check some simple cases
assert find_fixed_point([-10, -1, 0, 3, 10, 11, 30, 50, 100],9) == 3
assert find_fixed_point([1, 2, 3, 4, 5, 6, 7, 8],8) == -1
assert find_fixed_point([0, 2, 5, 8, 17],5) == 0
|
|
909 | Write a function to find the previous palindrome of a specified number. | previous_palindrome | def previous_palindrome(num):
for x in range(num-1,0,-1):
if str(x) == str(x)[::-1]:
return x | [
"assert previous_palindrome(124) == 121",
"assert previous_palindrome(124) == 121",
"assert previous_palindrome(120) == 111"
] | def check(candidate):
# Check some simple cases
assert previous_palindrome(99)==88
assert previous_palindrome(1221)==1111
assert previous_palindrome(120)==111
|
|
910 | Write a function to validate a gregorian date. | check_date | import datetime
def check_date(m, d, y):
try:
m, d, y = map(int, (m, d, y))
datetime.date(y, m, d)
return True
except ValueError:
return False | [
"assert check_date('3072', '45076', '1970463') == False",
"assert check_date('9431', '681461', '812861296') == False",
"assert check_date('99830', '8952', '619323038') == False"
] | def check(candidate):
# Check some simple cases
assert check_date(11,11,2002)==True
assert check_date(13,11,2002)==False
assert check_date('11','11','2002')==True
|
|
911 | Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm. | maximum_product | def maximum_product(nums):
import heapq
a, b = heapq.nlargest(3, nums), heapq.nsmallest(2, nums)
return max(a[0] * a[1] * a[2], a[0] * b[0] * b[1]) | [
"assert maximum_product([15, 15, 15, 4, 10, 8, 4, 3, 4, 4, 2]) == 3375",
"assert maximum_product([16, 10, 15, 10, 4, 4, 4, 2, 4, 3, 6]) == 2400",
"assert maximum_product([20, 12, 10, 5, 13, 7, 13, 4, 7, 4, 6]) == 3380"
] | def check(candidate):
# Check some simple cases
assert maximum_product( [12, 74, 9, 50, 61, 41])==225700
assert maximum_product([25, 35, 22, 85, 14, 65, 75, 25, 58])==414375
assert maximum_product([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1])==2520
|
|
912 | Write a function to find ln, m lobb number. | int | def binomial_coeff(n, k):
C = [[0 for j in range(k + 1)]
for i in range(n + 1)]
for i in range(0, n + 1):
for j in range(0, min(i, k) + 1):
if (j == 0 or j == i):
C[i][j] = 1
else:
C[i][j] = (C[i - 1][j - 1]
+ C[i - 1][j])
return C[n][k]
def lobb_num(n, m):
return (((2 * m + 1) *
binomial_coeff(2 * n, m + n))
/ (m + n + 1)) | [
"assert lobb_num(2, 1) == 3.0",
"assert lobb_num(9, 7) == 135.0",
"assert lobb_num(6, 6) == 1.0"
] | def check(candidate):
# Check some simple cases
assert int(lobb_num(5, 3)) == 35
assert int(lobb_num(3, 2)) == 5
assert int(lobb_num(4, 2)) == 20
|
|
913 | Write a function to check for a number at the end of a string. | end_num | import re
def end_num(string):
text = re.compile(r".*[0-9]$")
if text.match(string):
return True
else:
return False | [
"assert end_num(\"zggtplz\") == False",
"assert end_num(\"xlyv\") == False",
"assert end_num(\"oeuffzqh\") == False"
] | def check(candidate):
# Check some simple cases
assert end_num('abcdef')==False
assert end_num('abcdef7')==True
assert end_num('abc')==False
|
|
914 | Write a python function to check whether the given string is made up of two alternating characters or not. | is_Two_Alter | def is_Two_Alter(s):
for i in range (len( s) - 2) :
if (s[i] != s[i + 2]) :
return False
if (s[0] == s[1]):
return False
return True | [
"assert is_Two_Alter(\"qpowpjbp\") == False",
"assert is_Two_Alter(\"mso\") == False",
"assert is_Two_Alter(\"iaiyfrbq\") == False"
] | def check(candidate):
# Check some simple cases
assert is_Two_Alter("abab") == True
assert is_Two_Alter("aaaa") == False
assert is_Two_Alter("xyz") == False
|
|
915 | Write a function to rearrange positive and negative numbers in a given array using lambda function. | rearrange_numbs | def rearrange_numbs(array_nums):
result = sorted(array_nums, key = lambda i: 0 if i == 0 else -1 / i)
return result | [
"assert rearrange_numbs([-16, 20, -13, 14, -27, 32]) == [14, 20, 32, -27, -16, -13]",
"assert rearrange_numbs([-20, 21, -8, 5, -25, 34]) == [5, 21, 34, -25, -20, -8]",
"assert rearrange_numbs([-22, 23, -9, 13, -34, 35]) == [13, 23, 35, -34, -22, -9]"
] | def check(candidate):
# Check some simple cases
assert rearrange_numbs([-1, 2, -3, 5, 7, 8, 9, -10])==[2, 5, 7, 8, 9, -10, -3, -1]
assert rearrange_numbs([10,15,14,13,-18,12,-20])==[10, 12, 13, 14, 15, -20, -18]
assert rearrange_numbs([-20,20,-10,10,-30,30])==[10, 20, 30, -30, -20, -10]
|
|
916 | Write a function to find if there is a triplet in the array whose sum is equal to a given value. | find_triplet_array | def find_triplet_array(A, arr_size, sum):
for i in range( 0, arr_size-2):
for j in range(i + 1, arr_size-1):
for k in range(j + 1, arr_size):
if A[i] + A[j] + A[k] == sum:
return A[i],A[j],A[k]
return True
return False | [
"assert find_triplet_array([1, 1, 2, 4, 8], 1, 5) == False",
"assert find_triplet_array([1, 6, 5, 7, 7], 9, 14) == (1, 6, 7)",
"assert find_triplet_array([5, 3, 8, 3, 4], 5, 9) == False"
] | def check(candidate):
# Check some simple cases
assert find_triplet_array([1, 4, 45, 6, 10, 8], 6, 22) == (4, 10, 8)
assert find_triplet_array([12, 3, 5, 2, 6, 9], 6, 24) == (12, 3, 9)
assert find_triplet_array([1, 2, 3, 4, 5], 5, 9) == (1, 3, 5)
|
|
917 | Write a function to find the sequences of one upper case letter followed by lower case letters. | text_uppercase_lowercase | import re
def text_uppercase_lowercase(text):
patterns = '[A-Z]+[a-z]+$'
if re.search(patterns, text):
return 'Found a match!'
else:
return ('Not matched!') | [
"assert text_uppercase_lowercase(\"QCA\") == \"Not matched!\"",
"assert text_uppercase_lowercase(\"QJLAFWV\") == \"Not matched!\"",
"assert text_uppercase_lowercase(\"IFB\") == \"Not matched!\""
] | def check(candidate):
# Check some simple cases
assert text_uppercase_lowercase("AaBbGg")==('Found a match!')
assert text_uppercase_lowercase("aA")==('Not matched!')
assert text_uppercase_lowercase("PYTHON")==('Not matched!')
|
|
918 | Write a function to count coin change. | coin_change | def coin_change(S, m, n):
table = [[0 for x in range(m)] for x in range(n+1)]
for i in range(m):
table[0][i] = 1
for i in range(1, n+1):
for j in range(m):
x = table[i - S[j]][j] if i-S[j] >= 0 else 0
y = table[i][j-1] if j >= 1 else 0
table[i][j] = x + y
return table[n][m-1] | [
"assert coin_change([5, 1, 6, 4, 4, 7], 6, 4) == 3",
"assert coin_change([5, 3, 1, 4, 5, 4], 6, 1) == 1",
"assert coin_change([7, 2, 7, 12, 6, 13], 6, 8) == 2"
] | def check(candidate):
# Check some simple cases
assert coin_change([1, 2, 3],3,4)==4
assert coin_change([4,5,6,7,8,9],6,9)==2
assert coin_change([4,5,6,7,8,9],6,4)==1
|
|
919 | Write a python function to multiply all items in the list. | multiply_list | def multiply_list(items):
tot = 1
for x in items:
tot *= x
return tot | [
"assert multiply_list([4, 6, 7, 5]) == 840",
"assert multiply_list([6, 2, 2, 3]) == 72",
"assert multiply_list([1, 1, 1, 2]) == 2"
] | def check(candidate):
# Check some simple cases
assert multiply_list([1,-2,3]) == -6
assert multiply_list([1,2,3,4]) == 24
assert multiply_list([3,1,2,3]) == 18
|
|
920 | Write a function to remove all tuples with all none values in the given tuple list. | remove_tuple | def remove_tuple(test_list):
res = [sub for sub in test_list if not all(ele == None for ele in sub)]
return (str(res)) | [
"assert remove_tuple([(4, 5), (5, None), (4, None), (25, 4), (None, None)]) == [(4, 5), (5, None), (4, None), (25, 4)]",
"assert remove_tuple([(4, 1), (6, None), (4, None), (21, 2), (None, None)]) == [(4, 1), (6, None), (4, None), (21, 2)]",
"assert remove_tuple([(5, 6), (2, None), (4, None), (19, 4), (None, None)]) == [(5, 6), (2, None), (4, None), (19, 4)]"
] | def check(candidate):
# Check some simple cases
assert remove_tuple([(None, 2), (None, None), (3, 4), (12, 3), (None, )] ) == '[(None, 2), (3, 4), (12, 3)]'
assert remove_tuple([(None, None), (None, None), (3, 6), (17, 3), (None,1 )] ) == '[(3, 6), (17, 3), (None, 1)]'
assert remove_tuple([(1, 2), (2, None), (3, None), (24, 3), (None, None )] ) == '[(1, 2), (2, None), (3, None), (24, 3)]'
|
|
921 | Write a function to perform chunking of tuples each of size n. | chunk_tuples | def chunk_tuples(test_tup, N):
res = [test_tup[i : i + N] for i in range(0, len(test_tup), N)]
return (res) | [
"assert chunk_tuples((12, 19, 20, 12, 23, 19, 17, 25), 3) == [(12, 19, 20), (12, 23, 19), (17, 25)]",
"assert chunk_tuples((6, 10, 21, 18, 15, 23, 22, 29), 1) == [(6,), (10,), (21,), (18,), (15,), (23,), (22,), (29,)]",
"assert chunk_tuples((16, 9, 12, 14, 23, 25, 27, 20), 3) == [(16, 9, 12), (14, 23, 25), (27, 20)]"
] | def check(candidate):
# Check some simple cases
assert chunk_tuples((10, 4, 5, 6, 7, 6, 8, 3, 4), 3) == [(10, 4, 5), (6, 7, 6), (8, 3, 4)]
assert chunk_tuples((1, 2, 3, 4, 5, 6, 7, 8, 9), 2) == [(1, 2), (3, 4), (5, 6), (7, 8), (9,)]
assert chunk_tuples((11, 14, 16, 17, 19, 21, 22, 25), 4) == [(11, 14, 16, 17), (19, 21, 22, 25)]
|
|
922 | Write a function to find a pair with the highest product from a given array of integers. | max_product | def max_product(arr):
arr_len = len(arr)
if (arr_len < 2):
return None
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([5, 4, 9, 7, 9, 10]) == (9, 10)",
"assert max_product([2, 4, 8, 10, 10, 6]) == (10, 10)",
"assert max_product([6, 3, 2, 3, 8, 9]) == (8, 9)"
] | 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, 3, 5, 6, 8, 9])==(8,9)
|
|
923 | Write a function to find the length of the shortest string that has both str1 and str2 as subsequences. | super_seq | def super_seq(X, Y, m, n):
if (not m):
return n
if (not n):
return m
if (X[m - 1] == Y[n - 1]):
return 1 + super_seq(X, Y, m - 1, n - 1)
return 1 + min(super_seq(X, Y, m - 1, n), super_seq(X, Y, m, n - 1)) | [
"assert super_seq('IWWQZMOWB', 'IDQFM', 4, 3) == 5",
"assert super_seq('ZWLJJHPXO', 'NTVHGFOK', 5, 3) == 8",
"assert super_seq('HQORHP', 'NPQCVIVE', 6, 4) == 9"
] | def check(candidate):
# Check some simple cases
assert super_seq("AGGTAB", "GXTXAYB", 6, 7) == 9
assert super_seq("feek", "eke", 4, 3) == 5
assert super_seq("PARRT", "RTA", 5, 3) == 6
|
|
924 | Write a function to find maximum of two numbers. | max_of_two | def max_of_two( x, y ):
if x > y:
return x
return y | [
"assert max_of_two(-11, -17) == -11",
"assert max_of_two(-14, -22) == -14",
"assert max_of_two(-13, -23) == -13"
] | def check(candidate):
# Check some simple cases
assert max_of_two(10,20)==20
assert max_of_two(19,15)==19
assert max_of_two(-10,-20)==-10
|
|
925 | Write a python function to calculate the product of all the numbers of a given tuple. | mutiple_tuple | def mutiple_tuple(nums):
temp = list(nums)
product = 1
for x in temp:
product *= x
return product | [
"assert mutiple_tuple((3, -9, -3)) == 81",
"assert mutiple_tuple((2, 0, -8)) == 0",
"assert mutiple_tuple((2, -9, -1)) == 18"
] | def check(candidate):
# Check some simple cases
assert mutiple_tuple((4, 3, 2, 2, -1, 18)) == -864
assert mutiple_tuple((1,2,3)) == 6
assert mutiple_tuple((-2,-4,-6)) == -48
|
|
926 | Write a function to find n-th rencontres number. | rencontres_number | def binomial_coeffi(n, k):
if (k == 0 or k == n):
return 1
return (binomial_coeffi(n - 1, k - 1)
+ binomial_coeffi(n - 1, k))
def rencontres_number(n, m):
if (n == 0 and m == 0):
return 1
if (n == 1 and m == 0):
return 0
if (m == 0):
return ((n - 1) * (rencontres_number(n - 1, 0)+ rencontres_number(n - 2, 0)))
return (binomial_coeffi(n, m) * rencontres_number(n - m, 0)) | [
"assert rencontres_number(8, 3) == 2464",
"assert rencontres_number(2, 1) == 0",
"assert rencontres_number(4, 2) == 6"
] | def check(candidate):
# Check some simple cases
assert rencontres_number(7, 2) == 924
assert rencontres_number(3, 0) == 2
assert rencontres_number(3, 1) == 3
|
|
927 | Write a function to calculate the height of the given binary tree. | null | class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def max_height(node):
if node is None:
return 0 ;
else :
left_height = max_height(node.left)
right_height = max_height(node.right)
if (left_height > right_height):
return left_height+1
else:
return right_height+1 | [
"assert (max_height(root)) == 3",
"assert (max_height(root1)) == 5 ",
"assert (max_height(root2)) == 4"
] | def check(candidate):
# Check some simple cases
assert (max_height(root)) == 3
assert (max_height(root1)) == 5
assert (max_height(root2)) == 4
|
|
928 | Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format. | 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)
return change_date_format(dt) | [
"assert change_date_format(\"^70|-49_:/\") == ^70|-49_:/",
"assert change_date_format(\"79&<+$&5\") == 79&<+$&5",
"assert change_date_format(\"5>?2$0140/4^$\") == 5>?2$0140/4^$"
] | def check(candidate):
# Check some simple cases
assert change_date_format('2026-01-02')=='02-01-2026'
assert change_date_format('2021-01-04')=='04-01-2021'
assert change_date_format('2030-06-06')=='06-06-2030'
|
|
929 | Write a function to count repeated items of a tuple. | count_tuplex | def count_tuplex(tuplex,value):
count = tuplex.count(value)
return count | [
"assert count_tuplex((1, 2, 10, 3, 6, 3, 4, 8, 4), 4) == 2",
"assert count_tuplex((2, 1, 8, 9, 5, 5, 2, 3, 12), 11) == 0",
"assert count_tuplex((1, 7, 4, 12, 12, 8, 9, 7, 6), 9) == 1"
] | def check(candidate):
# Check some simple cases
assert count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7),4)==3
assert count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7),2)==2
assert count_tuplex((2, 4, 7, 7, 7, 3, 4, 4, 7),7)==4
|
|
930 | Write a function that matches a string that has an a followed by zero or more b's by using regex. | 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(\"efdgbsrjb\") == \"Not matched!\"",
"assert text_match(\"hnfkjmr\") == \"Not matched!\"",
"assert text_match(\"njtt\") == \"Not matched!\""
] | def check(candidate):
# Check some simple cases
assert text_match("msb") == 'Not matched!'
assert text_match("a0c") == 'Found a match!'
assert text_match("abbc") == 'Found a match!'
|
|
931 | Write a function to calculate the sum of series 1³+2³+3³+….+n³. | sum_series | import math
def sum_series(number):
total = 0
total = math.pow((number * (number + 1)) /2, 2)
return total | [
"assert sum_series(18) == 29241.0",
"assert sum_series(10) == 3025.0",
"assert sum_series(15) == 14400.0"
] | def check(candidate):
# Check some simple cases
assert sum_series(7)==784
assert sum_series(5)==225
assert sum_series(15)==14400
|
|
932 | Write a function to remove duplicate words from a given list of strings. | remove_duplic_list | def remove_duplic_list(l):
temp = []
for x in l:
if x not in temp:
temp.append(x)
return temp | [
"assert remove_duplic_list(['jTVQLFKVvMO', 'bWtkXhHWZxFm', 'AjffEzPpRRe', 'FubWBbJIs', 'NvxWjbMe', 'FARWKM', 'B', '~JM']) == ['jTVQLFKVvMO', 'bWtkXhHWZxFm', 'AjffEzPpRRe', 'FubWBbJIs', 'NvxWjbMe', 'FARWKM', 'B', '~JM']",
"assert remove_duplic_list(['KimGCbZGRO', 'fCOEHDIYUr', 'BljYDSE', 'ewNFgUOlV', 'FTuLtt', 'N-Y-=KR', 'I', 'H>Z#ZKI|>']) == ['KimGCbZGRO', 'fCOEHDIYUr', 'BljYDSE', 'ewNFgUOlV', 'FTuLtt', 'N-Y-=KR', 'I', 'H>Z#ZKI|>']",
"assert remove_duplic_list(['TuSXhhuOo', 'bSRHsr', 'Gom', 'wTp', 'uSmREyDgpcuJSb', '?R@', 'Z', 'H_O:>M']) == ['TuSXhhuOo', 'bSRHsr', 'Gom', 'wTp', 'uSmREyDgpcuJSb', '?R@', 'Z', 'H_O:>M']"
] | def check(candidate):
# Check some simple cases
assert remove_duplic_list(["Python", "Exercises", "Practice", "Solution", "Exercises"])==['Python', 'Exercises', 'Practice', 'Solution']
assert remove_duplic_list(["Python", "Exercises", "Practice", "Solution", "Exercises","Java"])==['Python', 'Exercises', 'Practice', 'Solution', 'Java']
assert remove_duplic_list(["Python", "Exercises", "Practice", "Solution", "Exercises","C++","C","C++"])==['Python', 'Exercises', 'Practice', 'Solution','C++','C']
|
|
933 | Write a function to convert camel case string to snake case string by using regex. | camel_to_snake | import re
def camel_to_snake(text):
str1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', text)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', str1).lower() | [
"assert camel_to_snake(\"ZvfsoVAHfm\") == \"zvfso_va_hfm\"",
"assert camel_to_snake(\"aAnQLnk\") == \"a_an_q_lnk\"",
"assert camel_to_snake(\"rHoao\") == \"r_hoao\""
] | def check(candidate):
# Check some simple cases
assert camel_to_snake('GoogleAssistant') == 'google_assistant'
assert camel_to_snake('ChromeCast') == 'chrome_cast'
assert camel_to_snake('QuadCore') == 'quad_core'
|
|
934 | Write a function to find the nth delannoy number. | dealnnoy_num | def dealnnoy_num(n, m):
if (m == 0 or n == 0) :
return 1
return dealnnoy_num(m - 1, n) + dealnnoy_num(m - 1, n - 1) + dealnnoy_num(m, n - 1) | [
"assert dealnnoy_num(3, 5) == 231",
"assert dealnnoy_num(4, 3) == 129",
"assert dealnnoy_num(9, 5) == 22363"
] | def check(candidate):
# Check some simple cases
assert dealnnoy_num(3, 4) == 129
assert dealnnoy_num(3, 3) == 63
assert dealnnoy_num(4, 5) == 681
|
|
935 | Write a function to calculate the sum of series 1²+2²+3²+….+n². | series_sum | def series_sum(number):
total = 0
total = (number * (number + 1) * (2 * number + 1)) / 6
return total | [
"assert series_sum(15) == 1240.0",
"assert series_sum(12) == 650.0",
"assert series_sum(8) == 204.0"
] | def check(candidate):
# Check some simple cases
assert series_sum(6)==91
assert series_sum(7)==140
assert series_sum(12)==650
|
|
936 | Write a function to re-arrange the given tuples based on the given ordered list. | re_arrange_tuples | def re_arrange_tuples(test_list, ord_list):
temp = dict(test_list)
res = [(key, temp[key]) for key in ord_list]
return (res) | [
"assert re_arrange_tuples([(9, 8), (2, 9), (1, 8), (4, 6)], [1, 4, 1, 2]) == [(1, 8), (4, 6), (1, 8), (2, 9)]",
"assert re_arrange_tuples([(8, 8), (6, 5), (7, 8), (7, 5)], [6, 7, 8, 8]) == [(6, 5), (7, 5), (8, 8), (8, 8)]",
"assert re_arrange_tuples([(4, 3), (7, 7), (2, 5), (1, 6)], [2, 1, 2, 1]) == [(2, 5), (1, 6), (2, 5), (1, 6)]"
] | def check(candidate):
# Check some simple cases
assert re_arrange_tuples([(4, 3), (1, 9), (2, 10), (3, 2)], [1, 4, 2, 3]) == [(1, 9), (4, 3), (2, 10), (3, 2)]
assert re_arrange_tuples([(5, 4), (2, 10), (3, 11), (4, 3)], [3, 4, 2, 3]) == [(3, 11), (4, 3), (2, 10), (3, 11)]
assert re_arrange_tuples([(6, 3), (3, 8), (5, 7), (2, 4)], [2, 5, 3, 6]) == [(2, 4), (5, 7), (3, 8), (6, 3)]
|
|
937 | Write a function to count the most common character in a given string. | max_char | from collections import Counter
def max_char(str1):
temp = Counter(str1)
max_char = max(temp, key = temp.get)
return max_char | [
"assert max_char(\"ltqoqitxbs\") == \"t\"",
"assert max_char(\"ykmsazzqmiui\") == \"m\"",
"assert max_char(\"eprxy b\") == \"e\""
] | def check(candidate):
# Check some simple cases
assert max_char("hello world")==('l')
assert max_char("hello ")==('l')
assert max_char("python pr")==('p')
|
|
938 | Write a function to find three closest elements from three sorted arrays. | find_closet | import sys
def find_closet(A, B, C, p, q, r):
diff = sys.maxsize
res_i = 0
res_j = 0
res_k = 0
i = 0
j = 0
k = 0
while(i < p and j < q and k < r):
minimum = min(A[i], min(B[j], C[k]))
maximum = max(A[i], max(B[j], C[k]));
if maximum-minimum < diff:
res_i = i
res_j = j
res_k = k
diff = maximum - minimum;
if diff == 0:
break
if A[i] == minimum:
i = i+1
elif B[j] == minimum:
j = j+1
else:
k = k+1
return A[res_i],B[res_j],C[res_k] | [
"assert find_closet([2, 9, 6], [3, 11, 21], [13, 18], 3, 4, 1) == (9, 11, 13)",
"assert find_closet([7, 4, 12], [7, 21, 20], [13, 9], 3, 1, 5) == (7, 7, 13)",
"assert find_closet([5, 6, 13], [5, 17, 19], [6, 16], 3, 5, 6) == (5, 5, 6)"
] | def check(candidate):
# Check some simple cases
assert find_closet([1, 4, 10],[2, 15, 20],[10, 12],3,3,2) == (10, 15, 10)
assert find_closet([20, 24, 100],[2, 19, 22, 79, 800],[10, 12, 23, 24, 119],3,5,5) == (24, 22, 23)
assert find_closet([2, 5, 11],[3, 16, 21],[11, 13],3,3,2) == (11, 16, 11)
|
|
939 | Write a function to sort a list of dictionaries using lambda function. | sorted_models | def sorted_models(models):
sorted_models = sorted(models, key = lambda x: x['color'])
return sorted_models | [
"assert sorted_models([{\"make\": \"micromax\", \"model\": 314, \"color\": \"green\"}, {\"make\": \"Nokia\", \"model\": 500, \"color\": \"black\"}, {\"make\": \"Samsung\", \"model\": 46, \"color\": \"green\"}, {\"make\": \"Vivo\", \"model\": 616, \"color\": \"Gold\"}, {\"make\": \"poco\", \"model\": 735, \"color\": \"Yellow\"}, {\"make\": \"Nokia\", \"model\": 252, \"color\": \"Orange\"}, {\"make\": \"Vivo\", \"model\": 810, \"color\": \"Pink\"}, {\"make\": \"Google\", \"model\": 217, \"color\": \"grey\"}, {\"make\": \"Mi Max\", \"model\": 91, \"color\": \"black\"}, {\"make\": \"Google\", \"model\": 878, \"color\": \"Pink\"}, {\"make\": \"Mi Max\", \"model\": 186, \"color\": \"Turquoise\"}, {\"make\": \"micromax\", \"model\": 528, \"color\": \"Gold\"}, {\"make\": \"poco\", \"model\": 990, \"color\": \"green\"}, {\"make\": \"oppo\", \"model\": 195, \"color\": \"Turquoise\"}, {\"make\": \"One plus\", \"model\": 985, \"color\": \"Maroon\"}, {\"make\": \"Apple\", \"model\": 748, \"color\": \"Turquoise\"}, {\"make\": \"micromax\", \"model\": 590, \"color\": \"Brown\"}, {\"make\": \"Vivo\", \"model\": 969, \"color\": \"green\"}, {\"make\": \"Samsung\", \"model\": 183, \"color\": \"grey\"}, {\"make\": \"Google\", \"model\": 927, \"color\": \"Yellow\"}, {\"make\": \"One plus\", \"model\": 19, \"color\": \"black\"}, {\"make\": \"oppo\", \"model\": 508, \"color\": \"Purple\"}, {\"make\": \"oppo\", \"model\": 131, \"color\": \"Brown\"}, {\"make\": \"Vivo\", \"model\": 436, \"color\": \"White\"}, {\"make\": \"oppo\", \"model\": 338, \"color\": \"Brown\"}, {\"make\": \"poco\", \"model\": 103, \"color\": \"Pink\"}, {\"make\": \"One plus\", \"model\": 504, \"color\": \"Yellow\"}, {\"make\": \"Nokia\", \"model\": 644, \"color\": \"Brown\"}, {\"make\": \"Apple\", \"model\": 932, \"color\": \"Purple\"}, {\"make\": \"Vivo\", \"model\": 112, \"color\": \"Purple\"}, {\"make\": \"One plus\", \"model\": 891, \"color\": \"Pink\"}, {\"make\": \"oppo\", \"model\": 393, \"color\": \"Brown\"}, {\"make\": \"micromax\", \"model\": 876, \"color\": \"black\"}, {\"make\": \"oppo\", \"model\": 23, \"color\": \"grey\"}, {\"make\": \"Vivo\", \"model\": 668, \"color\": \"Pink\"}, {\"make\": \"oppo\", \"model\": 680, \"color\": \"Yellow\"}, {\"make\": \"Apple\", \"model\": 185, \"color\": \"Yellow\"}, {\"make\": \"Vivo\", \"model\": 368, \"color\": \"Purple\"}, {\"make\": \"Vivo\", \"model\": 625, \"color\": \"Brown\"}, {\"make\": \"Mi Max\", \"model\": 896, \"color\": \"green\"}, {\"make\": \"Google\", \"model\": 667, \"color\": \"grey\"}, {\"make\": \"One plus\", \"model\": 823, \"color\": \"Orange\"}, {\"make\": \"One plus\", \"model\": 717, \"color\": \"Maroon\"}, {\"make\": \"Samsung\", \"model\": 615, \"color\": \"Turquoise\"}, {\"make\": \"poco\", \"model\": 249, \"color\": \"black\"}, {\"make\": \"oppo\", \"model\": 742, \"color\": \"Brown\"}, {\"make\": \"Vivo\", \"model\": 529, \"color\": \"green\"}, {\"make\": \"Apple\", \"model\": 334, \"color\": \"Purple\"}, {\"make\": \"One plus\", \"model\": 61, \"color\": \"Gold\"}, {\"make\": \"Nokia\", \"model\": 521, \"color\": \"Yellow\"}, {\"make\": \"Nokia\", \"model\": 170, \"color\": \"green\"}, {\"make\": \"Vivo\", \"model\": 915, \"color\": \"Purple\"}, {\"make\": \"micromax\", \"model\": 908, \"color\": \"Maroon\"}, {\"make\": \"Google\", \"model\": 304, \"color\": \"Orange\"}, {\"make\": \"Google\", \"model\": 48, \"color\": \"Brown\"}, {\"make\": \"micromax\", \"model\": 779, \"color\": \"Maroon\"}, {\"make\": \"oppo\", \"model\": 718, \"color\": \"grey\"}, {\"make\": \"Google\", \"model\": 809, \"color\": \"black\"}, {\"make\": \"poco\", \"model\": 82, \"color\": \"Yellow\"}, {\"make\": \"Nokia\", \"model\": 101, \"color\": \"Brown\"}]) == [{'make': 'micromax', 'model': 590, 'color': 'Brown'}, {'make': 'oppo', 'model': 131, 'color': 'Brown'}, {'make': 'oppo', 'model': 338, 'color': 'Brown'}, {'make': 'Nokia', 'model': 644, 'color': 'Brown'}, {'make': 'oppo', 'model': 393, 'color': 'Brown'}, {'make': 'Vivo', 'model': 625, 'color': 'Brown'}, {'make': 'oppo', 'model': 742, 'color': 'Brown'}, {'make': 'Google', 'model': 48, 'color': 'Brown'}, {'make': 'Nokia', 'model': 101, 'color': 'Brown'}, {'make': 'Vivo', 'model': 616, 'color': 'Gold'}, {'make': 'micromax', 'model': 528, 'color': 'Gold'}, {'make': 'One plus', 'model': 61, 'color': 'Gold'}, {'make': 'One plus', 'model': 985, 'color': 'Maroon'}, {'make': 'One plus', 'model': 717, 'color': 'Maroon'}, {'make': 'micromax', 'model': 908, 'color': 'Maroon'}, {'make': 'micromax', 'model': 779, 'color': 'Maroon'}, {'make': 'Nokia', 'model': 252, 'color': 'Orange'}, {'make': 'One plus', 'model': 823, 'color': 'Orange'}, {'make': 'Google', 'model': 304, 'color': 'Orange'}, {'make': 'Vivo', 'model': 810, 'color': 'Pink'}, {'make': 'Google', 'model': 878, 'color': 'Pink'}, {'make': 'poco', 'model': 103, 'color': 'Pink'}, {'make': 'One plus', 'model': 891, 'color': 'Pink'}, {'make': 'Vivo', 'model': 668, 'color': 'Pink'}, {'make': 'oppo', 'model': 508, 'color': 'Purple'}, {'make': 'Apple', 'model': 932, 'color': 'Purple'}, {'make': 'Vivo', 'model': 112, 'color': 'Purple'}, {'make': 'Vivo', 'model': 368, 'color': 'Purple'}, {'make': 'Apple', 'model': 334, 'color': 'Purple'}, {'make': 'Vivo', 'model': 915, 'color': 'Purple'}, {'make': 'Mi Max', 'model': 186, 'color': 'Turquoise'}, {'make': 'oppo', 'model': 195, 'color': 'Turquoise'}, {'make': 'Apple', 'model': 748, 'color': 'Turquoise'}, {'make': 'Samsung', 'model': 615, 'color': 'Turquoise'}, {'make': 'Vivo', 'model': 436, 'color': 'White'}, {'make': 'poco', 'model': 735, 'color': 'Yellow'}, {'make': 'Google', 'model': 927, 'color': 'Yellow'}, {'make': 'One plus', 'model': 504, 'color': 'Yellow'}, {'make': 'oppo', 'model': 680, 'color': 'Yellow'}, {'make': 'Apple', 'model': 185, 'color': 'Yellow'}, {'make': 'Nokia', 'model': 521, 'color': 'Yellow'}, {'make': 'poco', 'model': 82, 'color': 'Yellow'}, {'make': 'Nokia', 'model': 500, 'color': 'black'}, {'make': 'Mi Max', 'model': 91, 'color': 'black'}, {'make': 'One plus', 'model': 19, 'color': 'black'}, {'make': 'micromax', 'model': 876, 'color': 'black'}, {'make': 'poco', 'model': 249, 'color': 'black'}, {'make': 'Google', 'model': 809, 'color': 'black'}, {'make': 'micromax', 'model': 314, 'color': 'green'}, {'make': 'Samsung', 'model': 46, 'color': 'green'}, {'make': 'poco', 'model': 990, 'color': 'green'}, {'make': 'Vivo', 'model': 969, 'color': 'green'}, {'make': 'Mi Max', 'model': 896, 'color': 'green'}, {'make': 'Vivo', 'model': 529, 'color': 'green'}, {'make': 'Nokia', 'model': 170, 'color': 'green'}, {'make': 'Google', 'model': 217, 'color': 'grey'}, {'make': 'Samsung', 'model': 183, 'color': 'grey'}, {'make': 'oppo', 'model': 23, 'color': 'grey'}, {'make': 'Google', 'model': 667, 'color': 'grey'}, {'make': 'oppo', 'model': 718, 'color': 'grey'}]",
"assert sorted_models([{\"make\": \"micromax\", \"model\": 286, \"color\": \"red\"}, {\"make\": \"micromax\", \"model\": 606, \"color\": \"grey\"}, {\"make\": \"One plus\", \"model\": 517, \"color\": \"White\"}, {\"make\": \"Apple\", \"model\": 671, \"color\": \"Purple\"}, {\"make\": \"Google\", \"model\": 453, \"color\": \"green\"}, {\"make\": \"Samsung\", \"model\": 950, \"color\": \"Orange\"}, {\"make\": \"Apple\", \"model\": 208, \"color\": \"Purple\"}, {\"make\": \"oppo\", \"model\": 384, \"color\": \"Maroon\"}, {\"make\": \"micromax\", \"model\": 212, \"color\": \"black\"}, {\"make\": \"Mi Max\", \"model\": 287, \"color\": \"grey\"}, {\"make\": \"Mi Max\", \"model\": 153, \"color\": \"White\"}, {\"make\": \"Vivo\", \"model\": 736, \"color\": \"red\"}, {\"make\": \"Apple\", \"model\": 984, \"color\": \"Purple\"}, {\"make\": \"Nokia\", \"model\": 436, \"color\": \"Pink\"}, {\"make\": \"Google\", \"model\": 258, \"color\": \"grey\"}, {\"make\": \"Vivo\", \"model\": 740, \"color\": \"White\"}, {\"make\": \"micromax\", \"model\": 142, \"color\": \"Gold\"}, {\"make\": \"Apple\", \"model\": 209, \"color\": \"Brown\"}, {\"make\": \"Apple\", \"model\": 933, \"color\": \"Purple\"}, {\"make\": \"poco\", \"model\": 640, \"color\": \"Maroon\"}, {\"make\": \"oppo\", \"model\": 916, \"color\": \"Yellow\"}, {\"make\": \"Vivo\", \"model\": 912, \"color\": \"Yellow\"}, {\"make\": \"Apple\", \"model\": 173, \"color\": \"Brown\"}, {\"make\": \"Google\", \"model\": 919, \"color\": \"White\"}, {\"make\": \"Google\", \"model\": 694, \"color\": \"Pink\"}, {\"make\": \"Vivo\", \"model\": 708, \"color\": \"Maroon\"}, {\"make\": \"Google\", \"model\": 732, \"color\": \"Purple\"}, {\"make\": \"Apple\", \"model\": 133, \"color\": \"black\"}, {\"make\": \"Samsung\", \"model\": 744, \"color\": \"White\"}, {\"make\": \"Vivo\", \"model\": 645, \"color\": \"Gold\"}, {\"make\": \"poco\", \"model\": 447, \"color\": \"Turquoise\"}, {\"make\": \"Apple\", \"model\": 403, \"color\": \"Maroon\"}, {\"make\": \"Apple\", \"model\": 930, \"color\": \"grey\"}, {\"make\": \"Vivo\", \"model\": 822, \"color\": \"Turquoise\"}, {\"make\": \"Apple\", \"model\": 927, \"color\": \"Turquoise\"}, {\"make\": \"micromax\", \"model\": 240, \"color\": \"red\"}, {\"make\": \"Samsung\", \"model\": 799, \"color\": \"Maroon\"}, {\"make\": \"One plus\", \"model\": 909, \"color\": \"White\"}, {\"make\": \"Google\", \"model\": 632, \"color\": \"red\"}]) == [{'make': 'Apple', 'model': 209, 'color': 'Brown'}, {'make': 'Apple', 'model': 173, 'color': 'Brown'}, {'make': 'micromax', 'model': 142, 'color': 'Gold'}, {'make': 'Vivo', 'model': 645, 'color': 'Gold'}, {'make': 'oppo', 'model': 384, 'color': 'Maroon'}, {'make': 'poco', 'model': 640, 'color': 'Maroon'}, {'make': 'Vivo', 'model': 708, 'color': 'Maroon'}, {'make': 'Apple', 'model': 403, 'color': 'Maroon'}, {'make': 'Samsung', 'model': 799, 'color': 'Maroon'}, {'make': 'Samsung', 'model': 950, 'color': 'Orange'}, {'make': 'Nokia', 'model': 436, 'color': 'Pink'}, {'make': 'Google', 'model': 694, 'color': 'Pink'}, {'make': 'Apple', 'model': 671, 'color': 'Purple'}, {'make': 'Apple', 'model': 208, 'color': 'Purple'}, {'make': 'Apple', 'model': 984, 'color': 'Purple'}, {'make': 'Apple', 'model': 933, 'color': 'Purple'}, {'make': 'Google', 'model': 732, 'color': 'Purple'}, {'make': 'poco', 'model': 447, 'color': 'Turquoise'}, {'make': 'Vivo', 'model': 822, 'color': 'Turquoise'}, {'make': 'Apple', 'model': 927, 'color': 'Turquoise'}, {'make': 'One plus', 'model': 517, 'color': 'White'}, {'make': 'Mi Max', 'model': 153, 'color': 'White'}, {'make': 'Vivo', 'model': 740, 'color': 'White'}, {'make': 'Google', 'model': 919, 'color': 'White'}, {'make': 'Samsung', 'model': 744, 'color': 'White'}, {'make': 'One plus', 'model': 909, 'color': 'White'}, {'make': 'oppo', 'model': 916, 'color': 'Yellow'}, {'make': 'Vivo', 'model': 912, 'color': 'Yellow'}, {'make': 'micromax', 'model': 212, 'color': 'black'}, {'make': 'Apple', 'model': 133, 'color': 'black'}, {'make': 'Google', 'model': 453, 'color': 'green'}, {'make': 'micromax', 'model': 606, 'color': 'grey'}, {'make': 'Mi Max', 'model': 287, 'color': 'grey'}, {'make': 'Google', 'model': 258, 'color': 'grey'}, {'make': 'Apple', 'model': 930, 'color': 'grey'}, {'make': 'micromax', 'model': 286, 'color': 'red'}, {'make': 'Vivo', 'model': 736, 'color': 'red'}, {'make': 'micromax', 'model': 240, 'color': 'red'}, {'make': 'Google', 'model': 632, 'color': 'red'}]",
"assert sorted_models([{\"make\": \"Samsung\", \"model\": 862, \"color\": \"Orange\"}, {\"make\": \"Nokia\", \"model\": 581, \"color\": \"green\"}, {\"make\": \"Google\", \"model\": 507, \"color\": \"Yellow\"}, {\"make\": \"Nokia\", \"model\": 762, \"color\": \"Brown\"}, {\"make\": \"Samsung\", \"model\": 707, \"color\": \"black\"}, {\"make\": \"poco\", \"model\": 604, \"color\": \"Orange\"}, {\"make\": \"Google\", \"model\": 979, \"color\": \"Gold\"}, {\"make\": \"micromax\", \"model\": 287, \"color\": \"Maroon\"}, {\"make\": \"Apple\", \"model\": 938, \"color\": \"black\"}, {\"make\": \"oppo\", \"model\": 602, \"color\": \"White\"}, {\"make\": \"micromax\", \"model\": 158, \"color\": \"black\"}, {\"make\": \"Apple\", \"model\": 444, \"color\": \"Orange\"}, {\"make\": \"One plus\", \"model\": 432, \"color\": \"grey\"}, {\"make\": \"Apple\", \"model\": 580, \"color\": \"green\"}, {\"make\": \"Vivo\", \"model\": 410, \"color\": \"Yellow\"}, {\"make\": \"Mi Max\", \"model\": 684, \"color\": \"Yellow\"}, {\"make\": \"poco\", \"model\": 361, \"color\": \"Brown\"}, {\"make\": \"poco\", \"model\": 679, \"color\": \"Maroon\"}, {\"make\": \"Samsung\", \"model\": 195, \"color\": \"Pink\"}, {\"make\": \"Apple\", \"model\": 303, \"color\": \"grey\"}, {\"make\": \"Vivo\", \"model\": 838, \"color\": \"red\"}, {\"make\": \"Apple\", \"model\": 186, \"color\": \"red\"}, {\"make\": \"poco\", \"model\": 64, \"color\": \"Pink\"}, {\"make\": \"Google\", \"model\": 106, \"color\": \"Pink\"}, {\"make\": \"Mi Max\", \"model\": 379, \"color\": \"Maroon\"}, {\"make\": \"micromax\", \"model\": 157, \"color\": \"Pink\"}, {\"make\": \"micromax\", \"model\": 982, \"color\": \"Maroon\"}, {\"make\": \"Nokia\", \"model\": 899, \"color\": \"black\"}, {\"make\": \"Vivo\", \"model\": 423, \"color\": \"red\"}, {\"make\": \"poco\", \"model\": 901, \"color\": \"black\"}, {\"make\": \"Nokia\", \"model\": 109, \"color\": \"green\"}, {\"make\": \"oppo\", \"model\": 847, \"color\": \"red\"}, {\"make\": \"poco\", \"model\": 412, \"color\": \"Maroon\"}, {\"make\": \"micromax\", \"model\": 819, \"color\": \"Pink\"}, {\"make\": \"oppo\", \"model\": 54, \"color\": \"Orange\"}, {\"make\": \"One plus\", \"model\": 130, \"color\": \"Purple\"}, {\"make\": \"oppo\", \"model\": 925, \"color\": \"red\"}, {\"make\": \"Mi Max\", \"model\": 903, \"color\": \"Turquoise\"}, {\"make\": \"oppo\", \"model\": 945, \"color\": \"Purple\"}, {\"make\": \"Mi Max\", \"model\": 349, \"color\": \"Purple\"}, {\"make\": \"Google\", \"model\": 466, \"color\": \"Gold\"}, {\"make\": \"poco\", \"model\": 333, \"color\": \"Brown\"}, {\"make\": \"micromax\", \"model\": 51, \"color\": \"grey\"}, {\"make\": \"micromax\", \"model\": 546, \"color\": \"Maroon\"}, {\"make\": \"Nokia\", \"model\": 287, \"color\": \"Orange\"}, {\"make\": \"Samsung\", \"model\": 624, \"color\": \"grey\"}, {\"make\": \"Google\", \"model\": 913, \"color\": \"Pink\"}, {\"make\": \"micromax\", \"model\": 698, \"color\": \"black\"}, {\"make\": \"Google\", \"model\": 209, \"color\": \"Yellow\"}, {\"make\": \"One plus\", \"model\": 930, \"color\": \"red\"}, {\"make\": \"One plus\", \"model\": 205, \"color\": \"Purple\"}, {\"make\": \"poco\", \"model\": 521, \"color\": \"red\"}, {\"make\": \"micromax\", \"model\": 567, \"color\": \"Orange\"}, {\"make\": \"Nokia\", \"model\": 839, \"color\": \"grey\"}, {\"make\": \"poco\", \"model\": 591, \"color\": \"Pink\"}, {\"make\": \"Nokia\", \"model\": 717, \"color\": \"Orange\"}, {\"make\": \"oppo\", \"model\": 171, \"color\": \"White\"}, {\"make\": \"oppo\", \"model\": 266, \"color\": \"Pink\"}, {\"make\": \"micromax\", \"model\": 940, \"color\": \"Turquoise\"}, {\"make\": \"One plus\", \"model\": 337, \"color\": \"grey\"}, {\"make\": \"oppo\", \"model\": 553, \"color\": \"Yellow\"}, {\"make\": \"One plus\", \"model\": 563, \"color\": \"green\"}, {\"make\": \"oppo\", \"model\": 685, \"color\": \"red\"}, {\"make\": \"Apple\", \"model\": 892, \"color\": \"green\"}, {\"make\": \"Mi Max\", \"model\": 451, \"color\": \"Brown\"}, {\"make\": \"oppo\", \"model\": 257, \"color\": \"White\"}, {\"make\": \"poco\", \"model\": 797, \"color\": \"Brown\"}, {\"make\": \"Vivo\", \"model\": 1000, \"color\": \"Maroon\"}, {\"make\": \"One plus\", \"model\": 200, \"color\": \"red\"}, {\"make\": \"oppo\", \"model\": 277, \"color\": \"Orange\"}, {\"make\": \"oppo\", \"model\": 260, \"color\": \"Pink\"}, {\"make\": \"micromax\", \"model\": 157, \"color\": \"Yellow\"}, {\"make\": \"One plus\", \"model\": 378, \"color\": \"Brown\"}, {\"make\": \"micromax\", \"model\": 750, \"color\": \"Pink\"}, {\"make\": \"Apple\", \"model\": 109, \"color\": \"black\"}, {\"make\": \"Mi Max\", \"model\": 782, \"color\": \"Pink\"}, {\"make\": \"Apple\", \"model\": 442, \"color\": \"red\"}, {\"make\": \"Apple\", \"model\": 777, \"color\": \"Purple\"}, {\"make\": \"Apple\", \"model\": 598, \"color\": \"Purple\"}, {\"make\": \"oppo\", \"model\": 556, \"color\": \"Turquoise\"}, {\"make\": \"Google\", \"model\": 194, \"color\": \"Pink\"}, {\"make\": \"micromax\", \"model\": 839, \"color\": \"Orange\"}, {\"make\": \"Samsung\", \"model\": 901, \"color\": \"Maroon\"}, {\"make\": \"Samsung\", \"model\": 351, \"color\": \"White\"}, {\"make\": \"Mi Max\", \"model\": 523, \"color\": \"Maroon\"}, {\"make\": \"Apple\", \"model\": 910, \"color\": \"grey\"}, {\"make\": \"poco\", \"model\": 942, \"color\": \"grey\"}, {\"make\": \"oppo\", \"model\": 727, \"color\": \"Maroon\"}, {\"make\": \"Apple\", \"model\": 303, \"color\": \"Maroon\"}]) == [{'make': 'Nokia', 'model': 762, 'color': 'Brown'}, {'make': 'poco', 'model': 361, 'color': 'Brown'}, {'make': 'poco', 'model': 333, 'color': 'Brown'}, {'make': 'Mi Max', 'model': 451, 'color': 'Brown'}, {'make': 'poco', 'model': 797, 'color': 'Brown'}, {'make': 'One plus', 'model': 378, 'color': 'Brown'}, {'make': 'Google', 'model': 979, 'color': 'Gold'}, {'make': 'Google', 'model': 466, 'color': 'Gold'}, {'make': 'micromax', 'model': 287, 'color': 'Maroon'}, {'make': 'poco', 'model': 679, 'color': 'Maroon'}, {'make': 'Mi Max', 'model': 379, 'color': 'Maroon'}, {'make': 'micromax', 'model': 982, 'color': 'Maroon'}, {'make': 'poco', 'model': 412, 'color': 'Maroon'}, {'make': 'micromax', 'model': 546, 'color': 'Maroon'}, {'make': 'Vivo', 'model': 1000, 'color': 'Maroon'}, {'make': 'Samsung', 'model': 901, 'color': 'Maroon'}, {'make': 'Mi Max', 'model': 523, 'color': 'Maroon'}, {'make': 'oppo', 'model': 727, 'color': 'Maroon'}, {'make': 'Apple', 'model': 303, 'color': 'Maroon'}, {'make': 'Samsung', 'model': 862, 'color': 'Orange'}, {'make': 'poco', 'model': 604, 'color': 'Orange'}, {'make': 'Apple', 'model': 444, 'color': 'Orange'}, {'make': 'oppo', 'model': 54, 'color': 'Orange'}, {'make': 'Nokia', 'model': 287, 'color': 'Orange'}, {'make': 'micromax', 'model': 567, 'color': 'Orange'}, {'make': 'Nokia', 'model': 717, 'color': 'Orange'}, {'make': 'oppo', 'model': 277, 'color': 'Orange'}, {'make': 'micromax', 'model': 839, 'color': 'Orange'}, {'make': 'Samsung', 'model': 195, 'color': 'Pink'}, {'make': 'poco', 'model': 64, 'color': 'Pink'}, {'make': 'Google', 'model': 106, 'color': 'Pink'}, {'make': 'micromax', 'model': 157, 'color': 'Pink'}, {'make': 'micromax', 'model': 819, 'color': 'Pink'}, {'make': 'Google', 'model': 913, 'color': 'Pink'}, {'make': 'poco', 'model': 591, 'color': 'Pink'}, {'make': 'oppo', 'model': 266, 'color': 'Pink'}, {'make': 'oppo', 'model': 260, 'color': 'Pink'}, {'make': 'micromax', 'model': 750, 'color': 'Pink'}, {'make': 'Mi Max', 'model': 782, 'color': 'Pink'}, {'make': 'Google', 'model': 194, 'color': 'Pink'}, {'make': 'One plus', 'model': 130, 'color': 'Purple'}, {'make': 'oppo', 'model': 945, 'color': 'Purple'}, {'make': 'Mi Max', 'model': 349, 'color': 'Purple'}, {'make': 'One plus', 'model': 205, 'color': 'Purple'}, {'make': 'Apple', 'model': 777, 'color': 'Purple'}, {'make': 'Apple', 'model': 598, 'color': 'Purple'}, {'make': 'Mi Max', 'model': 903, 'color': 'Turquoise'}, {'make': 'micromax', 'model': 940, 'color': 'Turquoise'}, {'make': 'oppo', 'model': 556, 'color': 'Turquoise'}, {'make': 'oppo', 'model': 602, 'color': 'White'}, {'make': 'oppo', 'model': 171, 'color': 'White'}, {'make': 'oppo', 'model': 257, 'color': 'White'}, {'make': 'Samsung', 'model': 351, 'color': 'White'}, {'make': 'Google', 'model': 507, 'color': 'Yellow'}, {'make': 'Vivo', 'model': 410, 'color': 'Yellow'}, {'make': 'Mi Max', 'model': 684, 'color': 'Yellow'}, {'make': 'Google', 'model': 209, 'color': 'Yellow'}, {'make': 'oppo', 'model': 553, 'color': 'Yellow'}, {'make': 'micromax', 'model': 157, 'color': 'Yellow'}, {'make': 'Samsung', 'model': 707, 'color': 'black'}, {'make': 'Apple', 'model': 938, 'color': 'black'}, {'make': 'micromax', 'model': 158, 'color': 'black'}, {'make': 'Nokia', 'model': 899, 'color': 'black'}, {'make': 'poco', 'model': 901, 'color': 'black'}, {'make': 'micromax', 'model': 698, 'color': 'black'}, {'make': 'Apple', 'model': 109, 'color': 'black'}, {'make': 'Nokia', 'model': 581, 'color': 'green'}, {'make': 'Apple', 'model': 580, 'color': 'green'}, {'make': 'Nokia', 'model': 109, 'color': 'green'}, {'make': 'One plus', 'model': 563, 'color': 'green'}, {'make': 'Apple', 'model': 892, 'color': 'green'}, {'make': 'One plus', 'model': 432, 'color': 'grey'}, {'make': 'Apple', 'model': 303, 'color': 'grey'}, {'make': 'micromax', 'model': 51, 'color': 'grey'}, {'make': 'Samsung', 'model': 624, 'color': 'grey'}, {'make': 'Nokia', 'model': 839, 'color': 'grey'}, {'make': 'One plus', 'model': 337, 'color': 'grey'}, {'make': 'Apple', 'model': 910, 'color': 'grey'}, {'make': 'poco', 'model': 942, 'color': 'grey'}, {'make': 'Vivo', 'model': 838, 'color': 'red'}, {'make': 'Apple', 'model': 186, 'color': 'red'}, {'make': 'Vivo', 'model': 423, 'color': 'red'}, {'make': 'oppo', 'model': 847, 'color': 'red'}, {'make': 'oppo', 'model': 925, 'color': 'red'}, {'make': 'One plus', 'model': 930, 'color': 'red'}, {'make': 'poco', 'model': 521, 'color': 'red'}, {'make': 'oppo', 'model': 685, 'color': 'red'}, {'make': 'One plus', 'model': 200, 'color': 'red'}, {'make': 'Apple', 'model': 442, 'color': 'red'}]"
] | def check(candidate):
# Check some simple cases
assert sorted_models([{'make':'Nokia', 'model':216, 'color':'Black'}, {'make':'Mi Max', 'model':2, 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color':'Blue'}])==[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'Mi Max', 'model': 2, 'color': 'Gold'}]
assert sorted_models([{'make':'Vivo', 'model':20,'color':'Blue'},{'make': 'oppo','model':17,'color':'Gold'},{'make':'Apple','model':11,'color':'red'}])==([{'make':'Vivo', 'model':20,'color':'Blue'},{'make': 'oppo','model':17,'color':'Gold'},{'make':'Apple','model':11,'color':'red'}])
assert sorted_models([{'make':'micromax','model':40,'color':'grey'},{'make':'poco','model':60,'color':'blue'}])==([{'make':'poco','model':60,'color':'blue'},{'make':'micromax','model':40,'color':'grey'}])
|
|
940 | Write a function to sort the given array by using heap sort. | heap_sort | def heap_sort(arr):
heapify(arr)
end = len(arr) - 1
while end > 0:
arr[end], arr[0] = arr[0], arr[end]
shift_down(arr, 0, end - 1)
end -= 1
return arr
def heapify(arr):
start = len(arr) // 2
while start >= 0:
shift_down(arr, start, len(arr) - 1)
start -= 1
def shift_down(arr, start, end):
root = start
while root * 2 + 1 <= end:
child = root * 2 + 1
if child + 1 <= end and arr[child] < arr[child + 1]:
child += 1
if child <= end and arr[root] < arr[child]:
arr[root], arr[child] = arr[child], arr[root]
root = child
else:
return
| [
"assert heap_sort([16, 13, 27, 77, 66]) == [13, 16, 27, 66, 77]",
"assert heap_sort([24, 16, 31, 74, 66]) == [16, 24, 31, 66, 74]",
"assert heap_sort([16, 10, 25, 83, 66]) == [10, 16, 25, 66, 83]"
] | def check(candidate):
# Check some simple cases
assert heap_sort([12, 2, 4, 5, 2, 3]) == [2, 2, 3, 4, 5, 12]
assert heap_sort([32, 14, 5, 6, 7, 19]) == [5, 6, 7, 14, 19, 32]
assert heap_sort([21, 15, 29, 78, 65]) == [15, 21, 29, 65, 78]
|
|
941 | Write a function to count the elements in a list until an element is a tuple. | count_elim | def count_elim(num):
count_elim = 0
for n in num:
if isinstance(n, tuple):
break
count_elim += 1
return count_elim | [
"assert count_elim([(13, (21, 35, (10, 18), 36))]) == 0",
"assert count_elim([(13, (20, 34, (14, 22), 35))]) == 0",
"assert count_elim([(6, (20, 34, (13, 23), 42))]) == 0"
] | def check(candidate):
# Check some simple cases
assert count_elim([10,20,30,(10,20),40])==3
assert count_elim([10,(20,30),(10,20),40])==1
assert count_elim([(10,(20,30,(10,20),40))])==0
|
|
942 | Write a function to check if any list element is present in the given list. | check_element | def check_element(test_tup, check_list):
res = False
for ele in check_list:
if ele in test_tup:
res = True
break
return (res) | [
"assert check_element((7, 5, 6, 8, 3), [6, 6, 5, 7]) == True",
"assert check_element((8, 4, 6, 2, 1), [7, 13, 8, 8]) == True",
"assert check_element((3, 1, 6, 6, 3), [13, 3, 7, 7]) == True"
] | def check(candidate):
# Check some simple cases
assert check_element((4, 5, 7, 9, 3), [6, 7, 10, 11]) == True
assert check_element((1, 2, 3, 4), [4, 6, 7, 8, 9]) == True
assert check_element((3, 2, 1, 4, 5), [9, 8, 7, 6]) == False
|
|
943 | Write a function to combine two given sorted lists using heapq module. | combine_lists | from heapq import merge
def combine_lists(num1,num2):
combine_lists=list(merge(num1, num2))
return combine_lists | [
"assert combine_lists([6, 4, 4], [5, 9, 9]) == [5, 6, 4, 4, 9, 9]",
"assert combine_lists([1, 7, 10], [3, 3, 3]) == [1, 3, 3, 3, 7, 10]",
"assert combine_lists([4, 4, 7], [2, 6, 9]) == [2, 4, 4, 6, 7, 9]"
] | def check(candidate):
# Check some simple cases
assert combine_lists([1, 3, 5, 7, 9, 11],[0, 2, 4, 6, 8, 10])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
assert combine_lists([1, 3, 5, 6, 8, 9], [2, 5, 7, 11])==[1,2,3,5,5,6,7,8,9,11]
assert combine_lists([1,3,7],[2,4,6])==[1,2,3,4,6,7]
|
|
944 | Write a function to separate and print the numbers and their position of a given string. | num_position | import re
def num_position(text):
for m in re.finditer("\d+", text):
return m.start() | [
"assert num_position(\"qwd8delx8hfbaechjszoio7ndbkgyhddfdu9dw5\") == 3",
"assert num_position(\"w3m58kdjiv7sce2vrh76 5hm42husf7x17j30rl\") == 1",
"assert num_position(\" jjnbz cu feimytxhmt0syab0rye5m\") == 20"
] | def check(candidate):
# Check some simple cases
assert num_position("there are 70 flats in this apartment")==10
assert num_position("every adult have 32 teeth")==17
assert num_position("isha has 79 chocolates in her bag")==9
|
|
945 | Write a function to convert the given tuples into set. | tuple_to_set | def tuple_to_set(t):
s = set(t)
return (s) | [
"assert tuple_to_set(('w', 'e', 'o')) == {'o', 'e', 'w'}",
"assert tuple_to_set(('t', 'i', 'b')) == {'b', 't', 'i'}",
"assert tuple_to_set(('d', 'q', 'b')) == {'b', 'd', 'q'}"
] | def check(candidate):
# Check some simple cases
assert tuple_to_set(('x', 'y', 'z') ) == {'y', 'x', 'z'}
assert tuple_to_set(('a', 'b', 'c') ) == {'c', 'a', 'b'}
assert tuple_to_set(('z', 'd', 'e') ) == {'d', 'e', 'z'}
|
|
946 | Write a function to find the most common elements and their counts of a specified text. | most_common_elem | from collections import Counter
def most_common_elem(s,a):
most_common_elem=Counter(s).most_common(a)
return most_common_elem | [
"assert most_common_elem('ryqdnrltjstzyegphltxmfvsylf', 2) == [('y', 3), ('l', 3)]",
"assert most_common_elem('potjcapxfrqbkjtnmtbp', 12) == [('p', 3), ('t', 3), ('j', 2), ('b', 2), ('o', 1), ('c', 1), ('a', 1), ('x', 1), ('f', 1), ('r', 1), ('q', 1), ('k', 1)]",
"assert most_common_elem('dyiwugiagungwkeouzwoc', 10) == [('w', 3), ('u', 3), ('g', 3), ('i', 2), ('o', 2), ('d', 1), ('y', 1), ('a', 1), ('n', 1), ('k', 1)]"
] | def check(candidate):
# Check some simple cases
assert most_common_elem('lkseropewdssafsdfafkpwe',3)==[('s', 4), ('e', 3), ('f', 3)]
assert most_common_elem('lkseropewdssafsdfafkpwe',2)==[('s', 4), ('e', 3)]
assert most_common_elem('lkseropewdssafsdfafkpwe',7)==[('s', 4), ('e', 3), ('f', 3), ('k', 2), ('p', 2), ('w', 2), ('d', 2)]
|
|
947 | Write a python function to find the length of the shortest word. | len_log | def len_log(list1):
min=len(list1[0])
for i in list1:
if len(i)<min:
min=len(i)
return min | [
"assert len_log(['25007', '9825', '23122']) == 4",
"assert len_log(['05905', '2160', '3949304']) == 4",
"assert len_log(['466559', '040', '370952784']) == 3"
] | def check(candidate):
# Check some simple cases
assert len_log(["win","lose","great"]) == 3
assert len_log(["a","ab","abc"]) == 1
assert len_log(["12","12","1234"]) == 2
|
|
948 | Write a function to get an item of a tuple. | get_item | def get_item(tup1,index):
item = tup1[index]
return item | [
"assert get_item(('z', 1, 'u', 'k', 'g', 'w', 'y', 't', 'g', 'e'), 0) == z",
"assert get_item(('r', 3, 'i', 'l', 'n', 'v', 'a', 't', 'b', 'p'), 2) == i",
"assert get_item(('e', 8, 'k', 'm', 'c', 'd', 'i', 'f', 'c', 'j'), -5) == d"
] | def check(candidate):
# Check some simple cases
assert get_item(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),3)==('e')
assert get_item(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),-4)==('u')
assert get_item(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),-3)==('r')
|
|
949 | Write a function to sort the given tuple list basis the total digits in tuple. | sort_list | def count_digs(tup):
return sum([len(str(ele)) for ele in tup ])
def sort_list(test_list):
test_list.sort(key = count_digs)
return (str(test_list)) | [
"assert sort_list([(37, 3, 57, 728), (1, 2), (144,), (131, 19)]) == [(1, 2), (144,), (131, 19), (37, 3, 57, 728)]",
"assert sort_list([(33, 2, 62, 725), (5, 4), (146,), (134, 28)]) == [(5, 4), (146,), (134, 28), (33, 2, 62, 725)]",
"assert sort_list([(35, 8, 56, 718), (5, 4), (146,), (136, 27)]) == [(5, 4), (146,), (136, 27), (35, 8, 56, 718)]"
] | def check(candidate):
# Check some simple cases
assert sort_list([(3, 4, 6, 723), (1, 2), (12345,), (134, 234, 34)] ) == '[(1, 2), (12345,), (3, 4, 6, 723), (134, 234, 34)]'
assert sort_list([(3, 4, 8), (1, 2), (1234335,), (1345, 234, 334)] ) == '[(1, 2), (3, 4, 8), (1234335,), (1345, 234, 334)]'
assert sort_list([(34, 4, 61, 723), (1, 2), (145,), (134, 23)] ) == '[(1, 2), (145,), (134, 23), (34, 4, 61, 723)]'
|
|
950 | Write a function to display sign of the chinese zodiac for given year. | chinese_zodiac | def chinese_zodiac(year):
if (year - 2000) % 12 == 0:
sign = 'Dragon'
elif (year - 2000) % 12 == 1:
sign = 'Snake'
elif (year - 2000) % 12 == 2:
sign = 'Horse'
elif (year - 2000) % 12 == 3:
sign = 'sheep'
elif (year - 2000) % 12 == 4:
sign = 'Monkey'
elif (year - 2000) % 12 == 5:
sign = 'Rooster'
elif (year - 2000) % 12 == 6:
sign = 'Dog'
elif (year - 2000) % 12 == 7:
sign = 'Pig'
elif (year - 2000) % 12 == 8:
sign = 'Rat'
elif (year - 2000) % 12 == 9:
sign = 'Ox'
elif (year - 2000) % 12 == 10:
sign = 'Tiger'
else:
sign = 'Hare'
return sign | [
"assert chinese_zodiac(2271) == Pig",
"assert chinese_zodiac(2751) == Pig",
"assert chinese_zodiac(2483) == sheep"
] | def check(candidate):
# Check some simple cases
assert chinese_zodiac(1997)==('Ox')
assert chinese_zodiac(1998)==('Tiger')
assert chinese_zodiac(1994)==('Dog')
|
|
951 | Write a function to find the maximum of similar indices in two lists of tuples. | max_similar_indices | def max_similar_indices(test_list1, test_list2):
res = [(max(x[0], y[0]), max(x[1], y[1]))
for x, y in zip(test_list1, test_list2)]
return (res) | [
"assert max_similar_indices([(8, 11), (5, 14), (3, 6)], [(8, 5), (15, 12), (9, 11)]) == [(8, 11), (15, 14), (9, 11)]",
"assert max_similar_indices([(5, 2), (8, 13), (2, 5)], [(9, 5), (14, 8), (5, 19)]) == [(9, 5), (14, 13), (5, 19)]",
"assert max_similar_indices([(7, 3), (7, 8), (12, 5)], [(5, 2), (12, 15), (10, 14)]) == [(7, 3), (12, 15), (12, 14)]"
] | def check(candidate):
# Check some simple cases
assert max_similar_indices([(2, 4), (6, 7), (5, 1)],[(5, 4), (8, 10), (8, 14)]) == [(5, 4), (8, 10), (8, 14)]
assert max_similar_indices([(3, 5), (7, 8), (6, 2)],[(6, 5), (9, 11), (9, 15)]) == [(6, 5), (9, 11), (9, 15)]
assert max_similar_indices([(4, 6), (8, 9), (7, 3)],[(7, 6), (10, 12), (10, 16)]) == [(7, 6), (10, 12), (10, 16)]
|
|
952 | Write a function to compute the value of ncr mod p. | nCr_mod_p | def nCr_mod_p(n, r, p):
if (r > n- r):
r = n - r
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_mod_p(23, 9, 14) == 10",
"assert nCr_mod_p(21, 14, 22) == 10",
"assert nCr_mod_p(20, 19, 22) == 20"
] | def check(candidate):
# Check some simple cases
assert nCr_mod_p(10, 2, 13) == 6
assert nCr_mod_p(11, 3, 14) == 11
assert nCr_mod_p(18, 14, 19) == 1
|
|
953 | Write a python function to find the minimun number of subsets with distinct elements. | subset | def subset(ar, n):
res = 0
ar.sort()
for i in range(0, n) :
count = 1
for i in range(n - 1):
if ar[i] == ar[i + 1]:
count+=1
else:
break
res = max(res, count)
return res | [
"assert subset([4, 7, 8], 7) == 1",
"assert subset([3, 4, 4], 3) == 1",
"assert subset([6, 1, 7], 8) == 1"
] | def check(candidate):
# Check some simple cases
assert subset([1, 2, 3, 4],4) == 1
assert subset([5, 6, 9, 3, 4, 3, 4],7) == 2
assert subset([1, 2, 3 ],3) == 1
|
|
954 | Write a function that gives profit amount if the given amount has profit else return none. | profit_amount | def profit_amount(actual_cost,sale_amount):
if(actual_cost > sale_amount):
amount = actual_cost - sale_amount
return amount
else:
return None | [
"assert profit_amount(1878, 5959) == None",
"assert profit_amount(2354, 5807) == None",
"assert profit_amount(2983, 4220) == None"
] | def check(candidate):
# Check some simple cases
assert profit_amount(1500,1200)==300
assert profit_amount(100,200)==None
assert profit_amount(2000,5000)==None
|
|
955 | Write a function to find out, if the given number is abundant. | is_abundant | def is_abundant(n):
fctrsum = sum([fctr for fctr in range(1, n) if n % fctr == 0])
return fctrsum > n | [
"assert is_abundant(8) == False",
"assert is_abundant(5) == False",
"assert is_abundant(9) == False"
] | def check(candidate):
# Check some simple cases
assert is_abundant(12)==True
assert is_abundant(13)==False
assert is_abundant(9)==False
|
|
956 | Write a function to split the given string at uppercase letters by using regex. | split_list | import re
def split_list(text):
return (re.findall('[A-Z][^A-Z]*', text)) | [
"assert split_list(\"QmkxBOBGYfDdvGBVpSMwLp\") == ['Qmkx', 'B', 'O', 'B', 'G', 'Yf', 'Ddv', 'G', 'B', 'Vp', 'S', 'Mw', 'Lp']",
"assert split_list(\"WSiyZujojWrLfoaPvsflCDXpMqY\") == ['W', 'Siy', 'Zujoj', 'Wr', 'Lfoa', 'Pvsfl', 'C', 'D', 'Xp', 'Mq', 'Y']",
"assert split_list(\"DkpsslNEumAAbPCTzzvIhpsq\") == ['Dkpssl', 'N', 'Eum', 'A', 'Ab', 'P', 'C', 'Tzzv', 'Ihpsq']"
] | def check(candidate):
# Check some simple cases
assert split_list("LearnToBuildAnythingWithGoogle") == ['Learn', 'To', 'Build', 'Anything', 'With', 'Google']
assert split_list("ApmlifyingTheBlack+DeveloperCommunity") == ['Apmlifying', 'The', 'Black+', 'Developer', 'Community']
assert split_list("UpdateInTheGoEcoSystem") == ['Update', 'In', 'The', 'Go', 'Eco', 'System']
|
|
957 | Write a python function to get the position of rightmost set bit. | get_First_Set_Bit_Pos | import math
def get_First_Set_Bit_Pos(n):
return math.log2(n&-n)+1 | [
"assert get_First_Set_Bit_Pos(18) == 2.0",
"assert get_First_Set_Bit_Pos(20) == 3.0",
"assert get_First_Set_Bit_Pos(13) == 1.0"
] | def check(candidate):
# Check some simple cases
assert get_First_Set_Bit_Pos(12) == 3
assert get_First_Set_Bit_Pos(18) == 2
assert get_First_Set_Bit_Pos(16) == 5
|
|
958 | Write a function to convert an integer into a roman numeral. | int_to_roman | def int_to_roman( num):
val = [1000, 900, 500, 400,100, 90, 50, 40,10, 9, 5, 4,1]
syb = ["M", "CM", "D", "CD","C", "XC", "L", "XL","X", "IX", "V", "IV","I"]
roman_num = ''
i = 0
while num > 0:
for _ in range(num // val[i]):
roman_num += syb[i]
num -= val[i]
i += 1
return roman_num | [
"assert int_to_roman(9) == \"IX\"",
"assert int_to_roman(5) == \"V\"",
"assert int_to_roman(2) == \"II\""
] | def check(candidate):
# Check some simple cases
assert int_to_roman(1)==("I")
assert int_to_roman(50)==("L")
assert int_to_roman(4)==("IV")
|
|
959 | Write a python function to find the average of a list. | Average | def Average(lst):
return sum(lst) / len(lst) | [
"assert Average([3, 2, 3]) == 2.6666666666666665",
"assert Average([2, 1, 7]) == 3.3333333333333335",
"assert Average([3, 1, 5]) == 3.0"
] | def check(candidate):
# Check some simple cases
assert Average([15, 9, 55, 41, 35, 20, 62, 49]) == 35.75
assert Average([4, 5, 1, 2, 9, 7, 10, 8]) == 5.75
assert Average([1,2,3]) == 2
|
|
960 | Write a function to solve tiling problem. | get_noOfways | def get_noOfways(n):
if (n == 0):
return 0;
if (n == 1):
return 1;
return get_noOfways(n - 1) + get_noOfways(n - 2); | [
"assert get_noOfways(8) == 21",
"assert get_noOfways(1) == 1",
"assert get_noOfways(9) == 34"
] | def check(candidate):
# Check some simple cases
assert get_noOfways(4)==3
assert get_noOfways(3)==2
assert get_noOfways(5)==5
|
|
961 | Write a function to convert a roman numeral to an integer. | roman_to_int | def roman_to_int(s):
rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
int_val = 0
for i in range(len(s)):
if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]:
int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]]
else:
int_val += rom_val[s[i]]
return int_val | [
"assert roman_to_int(\"V\") == 5",
"assert roman_to_int(\"M\") == 1000",
"assert roman_to_int(\"C\") == 100"
] | def check(candidate):
# Check some simple cases
assert roman_to_int('MMMCMLXXXVI')==3986
assert roman_to_int('MMMM')==4000
assert roman_to_int('C')==100
|
|
962 | Write a python function to find the sum of all even natural numbers within the range l and r. | sum_Even | def sum_Natural(n):
sum = (n * (n + 1))
return int(sum)
def sum_Even(l,r):
return (sum_Natural(int(r / 2)) - sum_Natural(int((l - 1) / 2))) | [
"assert sum_Even(8, 8) == 8",
"assert sum_Even(8, 7) == 0",
"assert sum_Even(6, 7) == 6"
] | def check(candidate):
# Check some simple cases
assert sum_Even(2,5) == 6
assert sum_Even(3,8) == 18
assert sum_Even(4,6) == 10
|
|
963 | Write a function to calculate the discriminant value. | discriminant_value | def discriminant_value(x,y,z):
discriminant = (y**2) - (4*x*z)
if discriminant > 0:
return ("Two solutions",discriminant)
elif discriminant == 0:
return ("one solution",discriminant)
elif discriminant < 0:
return ("no real solution",discriminant) | [
"assert discriminant_value(5, 3, 12) == ('no real solution', -231)",
"assert discriminant_value(3, 3, 13) == ('no real solution', -147)",
"assert discriminant_value(4, 4, 6) == ('no real solution', -80)"
] | def check(candidate):
# Check some simple cases
assert discriminant_value(4,8,2)==("Two solutions",32)
assert discriminant_value(5,7,9)==("no real solution",-131)
assert discriminant_value(0,0,9)==("one solution",0)
|
|
964 | Write a python function to check whether the length of the word is even or not. | word_len | def word_len(s):
s = s.split(' ')
for word in s:
if len(word)%2==0:
return True
else:
return False | [
"assert word_len(\"iqkmvochh\") == False",
"assert word_len(\"jugkspbp\") == True",
"assert word_len(\"srfitchxf\") == False"
] | def check(candidate):
# Check some simple cases
assert word_len("program") == False
assert word_len("solution") == True
assert word_len("data") == True
|
|
965 | Write a function to convert camel case string to snake case string. | camel_to_snake | def camel_to_snake(text):
import re
str1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', text)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', str1).lower() | [
"assert camel_to_snake(\"grBOZLpwfppExvkmiCuiB\") == \"gr_boz_lpwfpp_exvkmi_cui_b\"",
"assert camel_to_snake(\"jtyeeRRBCuRocfveo\") == \"jtyee_rrb_cu_rocfveo\"",
"assert camel_to_snake(\"DIYDFvAaqoaNQYAVpeE\") == \"diyd_fv_aaqoa_nqya_vpe_e\""
] | def check(candidate):
# Check some simple cases
assert camel_to_snake('PythonProgram')==('python_program')
assert camel_to_snake('pythonLanguage')==('python_language')
assert camel_to_snake('ProgrammingLanguage')==('programming_language')
|
|
966 | Write a function to remove an empty tuple from a list of tuples. | remove_empty | def remove_empty(tuple1): #L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]
tuple1 = [t for t in tuple1 if t]
return tuple1 | [
"assert remove_empty([(), (), ('qj',), 'swqwy']) == [('qj',), 'swqwy']",
"assert remove_empty([(), (), ('z',), 'bgsugiig']) == [('z',), 'bgsugiig']",
"assert remove_empty([(), (), ('swg',), 'thtthap']) == [('swg',), 'thtthap']"
] | def check(candidate):
# Check some simple cases
assert remove_empty([(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')])==[('',), ('a', 'b'), ('a', 'b', 'c'), 'd']
assert remove_empty([(), (), ('',), ("python"), ("program")])==[('',), ("python"), ("program")]
assert remove_empty([(), (), ('',), ("java")])==[('',),("java") ]
|
|
967 | Write a python function to accept the strings which contains all vowels. | check | def check(string):
if len(set(string).intersection("AEIOUaeiou"))>=5:
return ('accepted')
else:
return ("not accepted") | [
"assert check(\"obfuob\") == \"not accepted\"",
"assert check(\"hzrmj\") == \"not accepted\"",
"assert check(\"cqnbm\") == \"not accepted\""
] | def check(candidate):
# Check some simple cases
assert check("SEEquoiaL") == 'accepted'
assert check('program') == "not accepted"
assert check('fine') == "not accepted"
|
|
968 | Write a python function to find maximum possible value for the given periodic function. | floor_Max | def floor_Max(A,B,N):
x = min(B - 1,N)
return (A*x) // B | [
"assert floor_Max(2, 3, 3) == 1",
"assert floor_Max(3, 4, 6) == 2",
"assert floor_Max(4, 7, 1) == 0"
] | def check(candidate):
# Check some simple cases
assert floor_Max(11,10,9) == 9
assert floor_Max(5,7,4) == 2
assert floor_Max(2,2,1) == 1
|
|
969 | Write a function to join the tuples if they have similar initial elements. | join_tuples | def join_tuples(test_list):
res = []
for sub in test_list:
if res and res[-1][0] == sub[0]:
res[-1].extend(sub[1:])
else:
res.append([ele for ele in sub])
res = list(map(tuple, res))
return (res) | [
"assert join_tuples([(5, 5), (10, 6), (12, 9), (5, 15), (6, 14)]) == [(5, 5), (10, 6), (12, 9), (5, 15), (6, 14)]",
"assert join_tuples([(8, 6), (5, 7), (13, 7), (6, 13), (5, 16)]) == [(8, 6), (5, 7), (13, 7), (6, 13), (5, 16)]",
"assert join_tuples([(3, 12), (8, 12), (5, 7), (10, 14), (12, 15)]) == [(3, 12), (8, 12), (5, 7), (10, 14), (12, 15)]"
] | def check(candidate):
# Check some simple cases
assert join_tuples([(5, 6), (5, 7), (6, 8), (6, 10), (7, 13)] ) == [(5, 6, 7), (6, 8, 10), (7, 13)]
assert join_tuples([(6, 7), (6, 8), (7, 9), (7, 11), (8, 14)] ) == [(6, 7, 8), (7, 9, 11), (8, 14)]
assert join_tuples([(7, 8), (7, 9), (8, 10), (8, 12), (9, 15)] ) == [(7, 8, 9), (8, 10, 12), (9, 15)]
|
|
970 | Write a function to find minimum of two numbers. | min_of_two | def min_of_two( x, y ):
if x < y:
return x
return y | [
"assert min_of_two(-14, -15) == -15",
"assert min_of_two(-13, -20) == -20",
"assert min_of_two(-6, -15) == -15"
] | def check(candidate):
# Check some simple cases
assert min_of_two(10,20)==10
assert min_of_two(19,15)==15
assert min_of_two(-10,-20)==-20
|
|
971 | Write a function to find the maximum number of segments of lengths a, b and c that can be formed from n. | maximum_segments | def maximum_segments(n, a, b, c) :
dp = [-1] * (n + 10)
dp[0] = 0
for i in range(0, n) :
if (dp[i] != -1) :
if(i + a <= n ):
dp[i + a] = max(dp[i] + 1,
dp[i + a])
if(i + b <= n ):
dp[i + b] = max(dp[i] + 1,
dp[i + b])
if(i + c <= n ):
dp[i + c] = max(dp[i] + 1,
dp[i + c])
return dp[n] | [
"assert maximum_segments(15, 14, 2, 3) == 7",
"assert maximum_segments(22, 13, 8, 11) == 2",
"assert maximum_segments(15, 12, 4, 4) == -1"
] | def check(candidate):
# Check some simple cases
assert maximum_segments(7, 5, 2, 5) == 2
assert maximum_segments(17, 2, 1, 3) == 17
assert maximum_segments(18, 16, 3, 6) == 6
|
|
972 | Write a function to concatenate the given two tuples to a nested tuple. | concatenate_nested | def concatenate_nested(test_tup1, test_tup2):
res = test_tup1 + test_tup2
return (res) | [
"assert concatenate_nested((5, 1), (1, 4)) == (5, 1, 1, 4)",
"assert concatenate_nested((7, 8), (8, 3)) == (7, 8, 8, 3)",
"assert concatenate_nested((7, 6), (7, 12)) == (7, 6, 7, 12)"
] | def check(candidate):
# Check some simple cases
assert concatenate_nested((3, 4), (5, 6)) == (3, 4, 5, 6)
assert concatenate_nested((1, 2), (3, 4)) == (1, 2, 3, 4)
assert concatenate_nested((4, 5), (6, 8)) == (4, 5, 6, 8)
|
|
973 | Write a python function to left rotate the string. | left_rotate | def left_rotate(s,d):
tmp = s[d : ] + s[0 : d]
return tmp | [
"assert left_rotate('nhvhygxvlihy', 4) == \"ygxvlihynhvh\"",
"assert left_rotate('sljaguscbk', 6) == \"scbksljagu\"",
"assert left_rotate('ikyptxmx', 2) == \"yptxmxik\""
] | def check(candidate):
# Check some simple cases
assert left_rotate("python",2) == "thonpy"
assert left_rotate("bigdata",3 ) == "databig"
assert left_rotate("hadoop",1 ) == "adooph"
|
|
974 | Write a function to find the minimum total path sum in the given triangle. | min_sum_path | def min_sum_path(A):
memo = [None] * len(A)
n = len(A) - 1
for i in range(len(A[n])):
memo[i] = A[n][i]
for i in range(len(A) - 2, -1,-1):
for j in range( len(A[i])):
memo[j] = A[i][j] + min(memo[j],
memo[j + 1])
return memo[0] | [
"assert min_sum_path([[5], [3, 3], [8, 1, 7]]) == 9",
"assert min_sum_path([[5], [6, 6], [3, 3, 9]]) == 14",
"assert min_sum_path([[4], [3, 3], [1, 7, 8]]) == 8"
] | def check(candidate):
# Check some simple cases
assert min_sum_path([[ 2 ], [3, 9 ], [1, 6, 7 ]]) == 6
assert min_sum_path([[ 2 ], [3, 7 ], [8, 5, 6 ]]) == 10
assert min_sum_path([[ 3 ], [6, 4 ], [5, 2, 7 ]]) == 9
|
Subsets and Splits