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
|
---|---|---|---|---|---|---|
801 | Write a python function to count the number of equal numbers from three given integers. | test_three_equal | def test_three_equal(x,y,z):
result= set([x,y,z])
if len(result)==3:
return 0
else:
return (4-len(result)) | [
"assert test_three_equal(1, 6, 3) == 0",
"assert test_three_equal(6, 6, 3) == 2",
"assert test_three_equal(3, 4, 7) == 0"
] | def check(candidate):
# Check some simple cases
assert test_three_equal(1,1,1) == 3
assert test_three_equal(-1,-2,-3) == 0
assert test_three_equal(1,2,2) == 2
|
|
802 | Write a python function to count the number of rotations required to generate a sorted array. | count_Rotation | def count_Rotation(arr,n):
for i in range (1,n):
if (arr[i] < arr[i - 1]):
return i
return 0 | [
"assert count_Rotation([10, 7, 13, 1, 7, 2], 7) == 1",
"assert count_Rotation([4, 8, 5, 1, 1, 6], 7) == 2",
"assert count_Rotation([3, 13, 11, 5, 7, 2], 7) == 2"
] | def check(candidate):
# Check some simple cases
assert count_Rotation([3,2,1],3) == 1
assert count_Rotation([4,5,1,2,3],5) == 2
assert count_Rotation([7,8,9,1,2,3],6) == 3
|
|
803 | Write a python function to check whether the given number is a perfect square or not. | is_Perfect_Square | def is_Perfect_Square(n) :
i = 1
while (i * i<= n):
if ((n % i == 0) and (n / i == i)):
return True
i = i + 1
return False | [
"assert is_Perfect_Square(9) == True",
"assert is_Perfect_Square(19) == False",
"assert is_Perfect_Square(14) == False"
] | def check(candidate):
# Check some simple cases
assert is_Perfect_Square(10) == False
assert is_Perfect_Square(36) == True
assert is_Perfect_Square(14) == False
|
|
804 | Write a python function to check whether the product of numbers is even or not. | is_Product_Even | def is_Product_Even(arr,n):
for i in range(0,n):
if ((arr[i] & 1) == 0):
return True
return False | [
"assert is_Product_Even([4, 3], 7) == True",
"assert is_Product_Even([2, 4], 4) == True",
"assert is_Product_Even([5, 2], 6) == True"
] | def check(candidate):
# Check some simple cases
assert is_Product_Even([1,2,3],3) == True
assert is_Product_Even([1,2,1,4],4) == True
assert is_Product_Even([1,1],2) == False
|
|
805 | Write a function to find the list in a list of lists whose sum of elements is the highest. | max_sum_list | def max_sum_list(lists):
return max(lists, key=sum) | [
"assert max_sum_list([[5, 1, 6]]) == [5, 1, 6]",
"assert max_sum_list([[5, 5, 1]]) == [5, 5, 1]",
"assert max_sum_list([[1, 1, 1]]) == [1, 1, 1]"
] | def check(candidate):
# Check some simple cases
assert max_sum_list([[1,2,3], [4,5,6], [10,11,12], [7,8,9]])==[10, 11, 12]
assert max_sum_list([[3,2,1], [6,5,4], [12,11,10]])==[12,11,10]
assert max_sum_list([[2,3,1]])==[2,3,1]
|
|
806 | Write a function to find maximum run of uppercase characters in the given string. | max_run_uppercase | def max_run_uppercase(test_str):
cnt = 0
res = 0
for idx in range(0, len(test_str)):
if test_str[idx].isupper():
cnt += 1
else:
res = cnt
cnt = 0
if test_str[len(test_str) - 1].isupper():
res = cnt
return (res) | [
"assert max_run_uppercase(\"gYBjRBigkSVx\") == 2",
"assert max_run_uppercase(\"oMHBjPUunK\") == 1",
"assert max_run_uppercase(\"MVqkCETqoFKiP\") == 1"
] | def check(candidate):
# Check some simple cases
assert max_run_uppercase('GeMKSForGERksISBESt') == 5
assert max_run_uppercase('PrECIOusMOVemENTSYT') == 6
assert max_run_uppercase('GooGLEFluTTER') == 4
|
|
807 | Write a python function to find the first odd number in a given list of numbers. | first_odd | def first_odd(nums):
first_odd = next((el for el in nums if el%2!=0),-1)
return first_odd | [
"assert first_odd([3, 7, 6]) == 3",
"assert first_odd([8, 8, 2]) == -1",
"assert first_odd([12, 5, 5]) == 5"
] | def check(candidate):
# Check some simple cases
assert first_odd([1,3,5]) == 1
assert first_odd([2,4,1,3]) == 1
assert first_odd ([8,9,1]) == 9
|
|
808 | Write a function to check if the given tuples contain the k or not. | check_K | def check_K(test_tup, K):
res = False
for ele in test_tup:
if ele == K:
res = True
break
return (res) | [
"assert check_K((12, 7, 11, 42, 8, 17), 14) == False",
"assert check_K((4, 3, 13, 40, 6, 16), 7) == False",
"assert check_K((4, 12, 6, 48, 6, 14), 6) == True"
] | def check(candidate):
# Check some simple cases
assert check_K((10, 4, 5, 6, 8), 6) == True
assert check_K((1, 2, 3, 4, 5, 6), 7) == False
assert check_K((7, 8, 9, 44, 11, 12), 11) == True
|
|
809 | Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple. | check_smaller | def check_smaller(test_tup1, test_tup2):
res = all(x > y for x, y in zip(test_tup1, test_tup2))
return (res) | [
"assert check_smaller((6, 7, 17), (5, 11, 15)) == False",
"assert check_smaller((14, 12, 8), (12, 13, 10)) == False",
"assert check_smaller((12, 11, 18), (11, 12, 9)) == False"
] | def check(candidate):
# Check some simple cases
assert check_smaller((1, 2, 3), (2, 3, 4)) == False
assert check_smaller((4, 5, 6), (3, 4, 5)) == True
assert check_smaller((11, 12, 13), (10, 11, 12)) == True
|
|
810 | Write a function to iterate over elements repeating each as many times as its count. | count_variable | from collections import Counter
def count_variable(a,b,c,d):
c = Counter(p=a, q=b, r=c, s=d)
return list(c.elements()) | [
"assert count_variable(13, 16, 11, 19) == ['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's']",
"assert count_variable(8, 12, 10, 21) == ['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's']",
"assert count_variable(9, 14, 17, 23) == ['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's']"
] | def check(candidate):
# Check some simple cases
assert count_variable(4,2,0,-2)==['p', 'p', 'p', 'p', 'q', 'q']
assert count_variable(0,1,2,3)==['q', 'r', 'r', 's', 's', 's']
assert count_variable(11,15,12,23)==['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's']
|
|
811 | Write a function to check if two lists of tuples are identical or not. | check_identical | def check_identical(test_list1, test_list2):
res = test_list1 == test_list2
return (res) | [
"assert check_identical([(1, 12), (12, 23)], [(1, 15), (13, 23)]) == False",
"assert check_identical([(3, 12), (11, 30)], [(5, 18), (7, 23)]) == False",
"assert check_identical([(5, 17), (11, 26)], [(4, 18), (14, 22)]) == False"
] | def check(candidate):
# Check some simple cases
assert check_identical([(10, 4), (2, 5)], [(10, 4), (2, 5)]) == True
assert check_identical([(1, 2), (3, 7)], [(12, 14), (12, 45)]) == False
assert check_identical([(2, 14), (12, 25)], [(2, 14), (12, 25)]) == True
|
|
812 | Write a function to abbreviate 'road' as 'rd.' in a given string. | road_rd | import re
def road_rd(street):
return (re.sub('Road$', 'Rd.', street)) | [
"assert road_rd(\"fukObiuXeFjsylIi aUQ\") == \"fukObiuXeFjsylIi aUQ\"",
"assert road_rd(\"vflyyjm hPnTtdfcKW\") == \"vflyyjm hPnTtdfcKW\"",
"assert road_rd(\"BKMUPPW njGbzohgvNEeky\") == \"BKMUPPW njGbzohgvNEeky\""
] | def check(candidate):
# Check some simple cases
assert road_rd("ravipadu Road")==('ravipadu Rd.')
assert road_rd("palnadu Road")==('palnadu Rd.')
assert road_rd("eshwar enclave Road")==('eshwar enclave Rd.')
|
|
813 | Write a function to find length of the string. | string_length | def string_length(str1):
count = 0
for char in str1:
count += 1
return count | [
"assert string_length(\"wwlpxefgho\") == 10",
"assert string_length(\"ndbo\") == 4",
"assert string_length(\"puuciovsjtk\") == 11"
] | def check(candidate):
# Check some simple cases
assert string_length('python')==6
assert string_length('program')==7
assert string_length('language')==8
|
|
814 | Write a function to find the area of a rombus. | rombus_area | def rombus_area(p,q):
area=(p*q)/2
return area | [
"assert rombus_area(4, 1) == 2.0",
"assert rombus_area(8, 2) == 8.0",
"assert rombus_area(1, 3) == 1.5"
] | def check(candidate):
# Check some simple cases
assert rombus_area(10,20)==100
assert rombus_area(10,5)==25
assert rombus_area(4,2)==4
|
|
815 | Write a function to sort the given array without using any sorting algorithm. the given array consists of only 0, 1, and 2. | sort_by_dnf | def sort_by_dnf(arr, n):
low=0
mid=0
high=n-1
while mid <= high:
if arr[mid] == 0:
arr[low], arr[mid] = arr[mid], arr[low]
low = low + 1
mid = mid + 1
elif arr[mid] == 1:
mid = mid + 1
else:
arr[mid], arr[high] = arr[high], arr[mid]
high = high - 1
return arr | [
"assert sort_by_dnf([5, 1, 1, 3, 2, 3, 1, 4, 5, 6], 9) == [1, 1, 1, 2, 3, 3, 4, 5, 5, 6]",
"assert sort_by_dnf([4, 7, 5, 3, 1, 5, 3, 5, 1, 4], 6) == [1, 5, 3, 7, 5, 4, 3, 5, 1, 4]",
"assert sort_by_dnf([1, 4, 3, 3, 1, 2, 1, 2, 2, 3], 10) == [1, 1, 1, 3, 2, 3, 2, 2, 3, 4]"
] | def check(candidate):
# Check some simple cases
assert sort_by_dnf([1,2,0,1,0,1,2,1,1], 9) == [0, 0, 1, 1, 1, 1, 1, 2, 2]
assert sort_by_dnf([1,0,0,1,2,1,2,2,1,0], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]
assert sort_by_dnf([2,2,1,0,0,0,1,1,2,1], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]
|
|
816 | Write a function to clear the values of the given tuples. | clear_tuple | def clear_tuple(test_tup):
temp = list(test_tup)
temp.clear()
test_tup = tuple(temp)
return (test_tup) | [
"assert clear_tuple((1, 2, 9, 8, 10)) == ()",
"assert clear_tuple((8, 6, 2, 1, 6)) == ()",
"assert clear_tuple((1, 6, 3, 10, 9)) == ()"
] | def check(candidate):
# Check some simple cases
assert clear_tuple((1, 5, 3, 6, 8)) == ()
assert clear_tuple((2, 1, 4 ,5 ,6)) == ()
assert clear_tuple((3, 2, 5, 6, 8)) == ()
|
|
817 | Write a function to find numbers divisible by m or n from a list of numbers using lambda function. | div_of_nums | def div_of_nums(nums,m,n):
result = list(filter(lambda x: (x % m == 0 or x % n == 0), nums))
return result | [
"assert div_of_nums([13, 10, 15, 10, 22, 14, 20], 10, 2) == [10, 10, 22, 14, 20]",
"assert div_of_nums([9, 10, 16, 8, 21, 14, 24], 10, 10) == [10]",
"assert div_of_nums([14, 19, 9, 17, 23, 14, 19], 12, 1) == [14, 19, 9, 17, 23, 14, 19]"
] | def check(candidate):
# Check some simple cases
assert div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190],19,13)==[19, 65, 57, 39, 152, 190]
assert div_of_nums([1, 2, 3, 5, 7, 8, 10],2,5)==[2, 5, 8, 10]
assert div_of_nums([10,15,14,13,18,12,20],10,5)==[10, 15, 20]
|
|
818 | Write a python function to count lower case letters in a given string. | lower_ctr | def lower_ctr(str):
lower_ctr= 0
for i in range(len(str)):
if str[i] >= 'a' and str[i] <= 'z': lower_ctr += 1
return lower_ctr | [
"assert lower_ctr(\"eKvv\") == 3",
"assert lower_ctr(\"IJHilxMX\") == 3",
"assert lower_ctr(\"oDx\") == 2"
] | def check(candidate):
# Check some simple cases
assert lower_ctr('abc') == 3
assert lower_ctr('string') == 6
assert lower_ctr('Python') == 5
|
|
819 | Write a function to count the frequency of consecutive duplicate elements in a given list of numbers. | count_duplic | def count_duplic(lists):
element = []
frequency = []
if not lists:
return element
running_count = 1
for i in range(len(lists)-1):
if lists[i] == lists[i+1]:
running_count += 1
else:
frequency.append(running_count)
element.append(lists[i])
running_count = 1
frequency.append(running_count)
element.append(lists[i+1])
return element,frequency
| [
"assert count_duplic([3, 3, 3, 8, 5, 3, 8, 9, 13, 15, 13, 11]) == ([3, 8, 5, 3, 8, 9, 13, 15, 13, 11], [3, 1, 1, 1, 1, 1, 1, 1, 1, 1])",
"assert count_duplic([3, 2, 2, 10, 8, 6, 6, 9, 6, 11, 5, 15]) == ([3, 2, 10, 8, 6, 9, 6, 11, 5, 15], [1, 2, 1, 1, 2, 1, 1, 1, 1, 1])",
"assert count_duplic([1, 4, 5, 10, 8, 3, 7, 9, 12, 7, 11, 10]) == ([1, 4, 5, 10, 8, 3, 7, 9, 12, 7, 11, 10], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])"
] | def check(candidate):
# Check some simple cases
assert count_duplic([1,2,2,2,4,4,4,5,5,5,5])==([1, 2, 4, 5], [1, 3, 3, 4])
assert count_duplic([2,2,3,1,2,6,7,9])==([2, 3, 1, 2, 6, 7, 9], [2, 1, 1, 1, 1, 1, 1])
assert count_duplic([2,1,5,6,8,3,4,9,10,11,8,12])==([2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
|
|
820 | Write a function to check whether the given month number contains 28 days or not. | check_monthnum_number | def check_monthnum_number(monthnum1):
if monthnum1 == 2:
return True
else:
return False | [
"assert check_monthnum_number(8) == False",
"assert check_monthnum_number(1) == False",
"assert check_monthnum_number(1) == False"
] | def check(candidate):
# Check some simple cases
assert check_monthnum_number(2)==True
assert check_monthnum_number(1)==False
assert check_monthnum_number(3)==False
|
|
821 | Write a function to merge two dictionaries into a single expression. | merge_dictionaries | import collections as ct
def merge_dictionaries(dict1,dict2):
merged_dict = dict(ct.ChainMap({}, dict1, dict2))
return merged_dict | [
"assert merge_dictionaries({'X': 'KevZNVwE', 'D': 'gJNjSi'}, {'H': 'DtIfLXgL', 'W': 'lBchakOo', 'T': 'YUqnwOZcY'}) == {'H': 'DtIfLXgL', 'W': 'lBchakOo', 'T': 'YUqnwOZcY', 'X': 'KevZNVwE', 'D': 'gJNjSi'}",
"assert merge_dictionaries({'L': 'ELlflKC', 'M': 'Wvbs'}, {'T': 'ESTQQTtiOGaF', 'P': 'LKdaARL', 'M': 'oxBwht'}) == {'T': 'ESTQQTtiOGaF', 'P': 'LKdaARL', 'M': 'Wvbs', 'L': 'ELlflKC'}",
"assert merge_dictionaries({'S': 'rwhjyc', 'P': 'ImwTtdv'}, {'U': 'sJoJJF', 'V': 'frR'}) == {'U': 'sJoJJF', 'V': 'frR', 'S': 'rwhjyc', 'P': 'ImwTtdv'}"
] | def check(candidate):
# Check some simple cases
assert merge_dictionaries({ "R": "Red", "B": "Black", "P": "Pink" }, { "G": "Green", "W": "White" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White'}
assert merge_dictionaries({ "R": "Red", "B": "Black", "P": "Pink" },{ "O": "Orange", "W": "White", "B": "Black" })=={'O': 'Orange', 'P': 'Pink', 'B': 'Black', 'W': 'White', 'R': 'Red'}
assert merge_dictionaries({ "G": "Green", "W": "White" },{ "O": "Orange", "W": "White", "B": "Black" })=={'W': 'White', 'O': 'Orange', 'G': 'Green', 'B': 'Black'}
|
|
822 | Write a function to return true if the password is valid. | pass_validity | import re
def pass_validity(p):
x = True
while x:
if (len(p)<6 or len(p)>12):
break
elif not re.search("[a-z]",p):
break
elif not re.search("[0-9]",p):
break
elif not re.search("[A-Z]",p):
break
elif not re.search("[$#@]",p):
break
elif re.search("\s",p):
break
else:
return True
x=False
break
if x:
return False | [
"assert pass_validity(\"~3tpog-e>d783p\") == False",
"assert pass_validity(\":#6dhoe\") == False",
"assert pass_validity(\"w!bo5r7cj4evt$w\") == False"
] | def check(candidate):
# Check some simple cases
assert pass_validity("password")==False
assert pass_validity("Password@10")==True
assert pass_validity("password@10")==False
|
|
823 | Write a function to check if the given string starts with a substring using regex. | check_substring | import re
def check_substring(string, sample) :
if (sample in string):
y = "\A" + sample
x = re.search(y, string)
if x :
return ("string starts with the given substring")
else :
return ("string doesnt start with the given substring")
else :
return ("entered string isnt a substring") | [
"assert check_substring('N zucFRgUHpuamBnCXG', 'zwb') == \"entered string isnt a substring\"",
"assert check_substring('ZXHJsxVahbeubyqs', 'fnglygwv') == \"entered string isnt a substring\"",
"assert check_substring('DQqZmdbITLmTjVJNLcT', 'wakbqymzz') == \"entered string isnt a substring\""
] | def check(candidate):
# Check some simple cases
assert check_substring("dreams for dreams makes life fun", "makes") == 'string doesnt start with the given substring'
assert check_substring("Hi there how are you Hi alex", "Hi") == 'string starts with the given substring'
assert check_substring("Its been a long day", "been") == 'string doesnt start with the given substring'
|
|
824 | Write a python function to remove even numbers from a given list. | remove_even | def remove_even(l):
for i in l:
if i % 2 == 0:
l.remove(i)
return l | [
"assert remove_even([5, 7, 5, 5]) == [5, 7, 5, 5]",
"assert remove_even([6, 4, 4, 8]) == [4, 8]",
"assert remove_even([2, 4, 6, 7]) == [4, 7]"
] | def check(candidate):
# Check some simple cases
assert remove_even([1,3,5,2]) == [1,3,5]
assert remove_even([5,6,7]) == [5,7]
assert remove_even([1,2,3,4]) == [1,3]
|
|
825 | Write a python function to access multiple elements of specified index from a given list. | access_elements | def access_elements(nums, list_index):
result = [nums[i] for i in list_index]
return result | [
"assert access_elements([3, 1, 7, 6], [2, 1]) == [7, 1]",
"assert access_elements([2, 2, 7, 1], [3, 3]) == [1, 1]",
"assert access_elements([2, 2, 1, 4], [2, 2]) == [1, 1]"
] | def check(candidate):
# Check some simple cases
assert access_elements([2,3,8,4,7,9],[0,3,5]) == [2, 4, 9]
assert access_elements([1, 2, 3, 4, 5],[1,2]) == [2,3]
assert access_elements([1,0,2,3],[0,1]) == [1,0]
|
|
826 | Write a python function to find the type of triangle from the given sides. | check_Type_Of_Triangle | def check_Type_Of_Triangle(a,b,c):
sqa = pow(a,2)
sqb = pow(b,2)
sqc = pow(c,2)
if (sqa == sqa + sqb or sqb == sqa + sqc or sqc == sqa + sqb):
return ("Right-angled Triangle")
elif (sqa > sqc + sqb or sqb > sqa + sqc or sqc > sqa + sqb):
return ("Obtuse-angled Triangle")
else:
return ("Acute-angled Triangle") | [
"assert check_Type_Of_Triangle(4, 4, 4) == \"Acute-angled Triangle\"",
"assert check_Type_Of_Triangle(2, 1, 3) == \"Obtuse-angled Triangle\"",
"assert check_Type_Of_Triangle(2, 1, 5) == \"Obtuse-angled Triangle\""
] | def check(candidate):
# Check some simple cases
assert check_Type_Of_Triangle(1,2,3) == "Obtuse-angled Triangle"
assert check_Type_Of_Triangle(2,2,2) == "Acute-angled Triangle"
assert check_Type_Of_Triangle(1,0,1) == "Right-angled Triangle"
|
|
827 | Write a function to sum a specific column of a list in a given list of lists. | sum_column | def sum_column(list1, C):
result = sum(row[C] for row in list1)
return result | [
"assert sum_column([[5, 7, 3, 5], [8, 9, 2, 6], [10, 11, 12, 9]], 3) == 20",
"assert sum_column([[2, 3, 4, 6], [3, 3, 7, 2], [11, 10, 9, 8]], 2) == 20",
"assert sum_column([[2, 1, 5, 7], [4, 2, 7, 6], [6, 5, 12, 4]], 2) == 24"
] | def check(candidate):
# Check some simple cases
assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],0)==12
assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],1)==15
assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],3)==9
|
|
828 | Write a function to count alphabets,digits and special charactes in a given string. | count_alpha_dig_spl | def count_alpha_dig_spl(string):
alphabets=digits = special = 0
for i in range(len(string)):
if(string[i].isalpha()):
alphabets = alphabets + 1
elif(string[i].isdigit()):
digits = digits + 1
else:
special = special + 1
return (alphabets,digits,special) | [
"assert count_alpha_dig_spl(\"#g$zfn=51&?$4&u@2f0\") == (6, 5, 8)",
"assert count_alpha_dig_spl(\"h-s>^^#&x^j*/5%af+\") == (6, 1, 11)",
"assert count_alpha_dig_spl(\"41f*w0cf|r8<aa/^yk##%\") == (9, 4, 8)"
] | def check(candidate):
# Check some simple cases
assert count_alpha_dig_spl("abc!@#123")==(3,3,3)
assert count_alpha_dig_spl("dgsuy@#$%&1255")==(5,4,5)
assert count_alpha_dig_spl("fjdsif627348#%$^&")==(6,6,5)
|
|
829 | Write a function to find out the second most repeated (or frequent) string in the given sequence. | second_frequent | from collections import Counter
def second_frequent(input):
dict = Counter(input)
value = sorted(dict.values(), reverse=True)
second_large = value[1]
for (key, val) in dict.items():
if val == second_large:
return (key) | [
"assert second_frequent(['wuuelp', 'mzksgkp', 'zrya', 'aokplnoso', 'gubnesez', 'rtjeypm']) == \"wuuelp\"",
"assert second_frequent(['qgfqhkq', 'eprhemy', 'tzmiq', 'kho', 'thsvu', 'faxhwye']) == \"qgfqhkq\"",
"assert second_frequent(['fukdi', 'zveppaqvq', 'oou', 'mcuekvn', 'cznb', 'jlvxlc']) == \"fukdi\""
] | def check(candidate):
# Check some simple cases
assert second_frequent(['aaa','bbb','ccc','bbb','aaa','aaa']) == 'bbb'
assert second_frequent(['abc','bcd','abc','bcd','bcd','bcd']) == 'abc'
assert second_frequent(['cdma','gsm','hspa','gsm','cdma','cdma']) == 'gsm'
|
|
830 | Write a function to round up a number to specific digits. | round_up | import math
def round_up(a, digits):
n = 10**-digits
return round(math.ceil(a / n) * n, digits) | [
"assert round_up(121.31901499427268, 2) == 121.32",
"assert round_up(122.4943110721177, 4) == 122.4944",
"assert round_up(128.74544572126754, 1) == 128.8"
] | def check(candidate):
# Check some simple cases
assert round_up(123.01247,0)==124
assert round_up(123.01247,1)==123.1
assert round_up(123.01247,2)==123.02
|
|
831 | Write a python function to count equal element pairs from the given array. | count_Pairs | def count_Pairs(arr,n):
cnt = 0;
for i in range(n):
for j in range(i + 1,n):
if (arr[i] == arr[j]):
cnt += 1;
return cnt; | [
"assert count_Pairs([5, 2, 3, 6, 6, 4], 1) == 0",
"assert count_Pairs([2, 4, 4, 5, 13, 14], 6) == 1",
"assert count_Pairs([8, 1, 4, 2, 10, 11], 4) == 0"
] | def check(candidate):
# Check some simple cases
assert count_Pairs([1,1,1,1],4) == 6
assert count_Pairs([1,5,1],3) == 1
assert count_Pairs([3,2,1,7,8,9],6) == 0
|
|
832 | Write a function to extract the maximum numeric value from a string by using regex. | extract_max | import re
def extract_max(input):
numbers = re.findall('\d+',input)
numbers = map(int,numbers)
return max(numbers) | [
"assert extract_max(\"pxj4s6i7ddnyva1uetvtg876y011k\") == 876",
"assert extract_max(\"z3kae2fxh15b49msgtw54ybh\") == 54",
"assert extract_max(\"xlyf2pyk1ik746go6jguuw2kkeh\") == 746"
] | def check(candidate):
# Check some simple cases
assert extract_max('100klh564abc365bg') == 564
assert extract_max('hello300how546mer231') == 546
assert extract_max('its233beenalong343journey234') == 343
|
|
833 | Write a function to get dictionary keys as a list. | get_key | def get_key(dict):
list = []
for key in dict.keys():
list.append(key)
return list | [
"assert get_key({29: 'bjvuiine', 38: 'qdakgrs', 48: 'luibtcbtrfe'}) == [29, 38, 48]",
"assert get_key({28: 'wvtbbyqjjlmu', 43: 'cay', 45: 'ambh'}) == [28, 43, 45]",
"assert get_key({27: 'uccnnd', 42: 'zcn', 43: 'kqfkvskjc'}) == [27, 42, 43]"
] | def check(candidate):
# Check some simple cases
assert get_key({1:'python',2:'java'})==[1,2]
assert get_key({10:'red',20:'blue',30:'black'})==[10,20,30]
assert get_key({27:'language',39:'java',44:'little'})==[27,39,44]
|
|
834 | Write a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order. | generate_matrix | def generate_matrix(n):
if n<=0:
return []
matrix=[row[:] for row in [[0]*n]*n]
row_st=0
row_ed=n-1
col_st=0
col_ed=n-1
current=1
while (True):
if current>n*n:
break
for c in range (col_st, col_ed+1):
matrix[row_st][c]=current
current+=1
row_st+=1
for r in range (row_st, row_ed+1):
matrix[r][col_ed]=current
current+=1
col_ed-=1
for c in range (col_ed, col_st-1, -1):
matrix[row_ed][c]=current
current+=1
row_ed-=1
for r in range (row_ed, row_st-1, -1):
matrix[r][col_st]=current
current+=1
col_st+=1
return matrix | [
"assert generate_matrix(3) == [[1, 2, 3], [8, 9, 4], [7, 6, 5]]",
"assert generate_matrix(2) == [[1, 2], [4, 3]]",
"assert generate_matrix(2) == [[1, 2], [4, 3]]"
] | def check(candidate):
# Check some simple cases
assert generate_matrix(3)==[[1, 2, 3], [8, 9, 4], [7, 6, 5]]
assert generate_matrix(2)==[[1,2],[4,3]]
assert generate_matrix(7)==[[1, 2, 3, 4, 5, 6, 7], [24, 25, 26, 27, 28, 29, 8], [23, 40, 41, 42, 43, 30, 9], [22, 39, 48, 49, 44, 31, 10], [21, 38, 47, 46, 45, 32, 11], [20, 37, 36, 35, 34, 33, 12], [19, 18, 17, 16, 15, 14, 13]]
|
|
835 | Write a python function to find the slope of a line. | slope | def slope(x1,y1,x2,y2):
return (float)(y2-y1)/(x2-x1) | [
"assert slope(3, 2, 1, 4) == -1.0",
"assert slope(2, 2, 8, 2) == 0.0",
"assert slope(5, 1, 2, 1) == -0.0"
] | def check(candidate):
# Check some simple cases
assert slope(4,2,2,5) == -1.5
assert slope(2,4,4,6) == 1
assert slope(1,2,4,2) == 0
|
|
836 | Write a function to find length of the subarray having maximum sum. | max_sub_array_sum | from sys import maxsize
def max_sub_array_sum(a,size):
max_so_far = -maxsize - 1
max_ending_here = 0
start = 0
end = 0
s = 0
for i in range(0,size):
max_ending_here += a[i]
if max_so_far < max_ending_here:
max_so_far = max_ending_here
start = s
end = i
if max_ending_here < 0:
max_ending_here = 0
s = i+1
return (end - start + 1) | [
"assert max_sub_array_sum([-6, 0, 4, 2, 6], 5) == 4",
"assert max_sub_array_sum([4, -3, 7, 9, 10], 5) == 5",
"assert max_sub_array_sum([-1, 0, 7, 9, 1], 3) == 2"
] | def check(candidate):
# Check some simple cases
assert max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3],8) == 5
assert max_sub_array_sum([1, -2, 1, 1, -2, 1],6) == 2
assert max_sub_array_sum([-1, -2, 3, 4, 5],5) == 3
|
|
837 | Write a python function to find the cube sum of first n odd natural numbers. | cube_Sum | def cube_Sum(n):
sum = 0
for i in range(0,n) :
sum += (2*i+1)*(2*i+1)*(2*i+1)
return sum | [
"assert cube_Sum(8) == 8128",
"assert cube_Sum(8) == 8128",
"assert cube_Sum(7) == 4753"
] | def check(candidate):
# Check some simple cases
assert cube_Sum(2) == 28
assert cube_Sum(3) == 153
assert cube_Sum(4) == 496
|
|
838 | Write a python function to find minimum number swaps required to make two binary strings equal. | min_Swaps | def min_Swaps(s1,s2) :
c0 = 0; c1 = 0;
for i in range(len(s1)) :
if (s1[i] == '0' and s2[i] == '1') :
c0 += 1;
elif (s1[i] == '1' and s2[i] == '0') :
c1 += 1;
result = c0 // 2 + c1 // 2;
if (c0 % 2 == 0 and c1 % 2 == 0) :
return result;
elif ((c0 + c1) % 2 == 0) :
return result + 2;
else :
return -1; | [
"assert min_Swaps('9637', '119332269') == 0",
"assert min_Swaps('128906152', '575847390') == 0",
"assert min_Swaps('7769879', '60469') == 0"
] | def check(candidate):
# Check some simple cases
assert min_Swaps("0011","1111") == 1
assert min_Swaps("00011","01001") == 2
assert min_Swaps("111","111") == 0
|
|
839 | Write a function to sort the tuples alphabetically by the first item of each tuple. | sort_tuple | def sort_tuple(tup):
n = len(tup)
for i in range(n):
for j in range(n-i-1):
if tup[j][0] > tup[j + 1][0]:
tup[j], tup[j + 1] = tup[j + 1], tup[j]
return tup | [
"assert sort_tuple([('PeiKHalJ', 23), ('UhkoOlHzDEGL', 28), ('poahS', 30), ('AfuUWG', 21), ('R', 'G')]) == [('AfuUWG', 21), ('PeiKHalJ', 23), ('R', 'G'), ('UhkoOlHzDEGL', 28), ('poahS', 30)]",
"assert sort_tuple([('drKdARAnMcxl', 31), ('yqVtpoqEXQwe', 26), ('FeBQZi', 27), ('pFQBi', 17), ('E', 'G')]) == [('E', 'G'), ('FeBQZi', 27), ('drKdARAnMcxl', 31), ('pFQBi', 17), ('yqVtpoqEXQwe', 26)]",
"assert sort_tuple([('XcrNOywNjTUc', 28), ('SHMGSAKQl', 27), ('ChSWZWVw', 25), ('NuEPMVJWZ', 26), ('X', 'X')]) == [('ChSWZWVw', 25), ('NuEPMVJWZ', 26), ('SHMGSAKQl', 27), ('X', 'X'), ('XcrNOywNjTUc', 28)]"
] | def check(candidate):
# Check some simple cases
assert sort_tuple([("Amana", 28), ("Zenat", 30), ("Abhishek", 29),("Nikhil", 21), ("B", "C")]) == [('Abhishek', 29), ('Amana', 28), ('B', 'C'), ('Nikhil', 21), ('Zenat', 30)]
assert sort_tuple([("aaaa", 28), ("aa", 30), ("bab", 29), ("bb", 21), ("csa", "C")]) == [('aa', 30), ('aaaa', 28), ('bab', 29), ('bb', 21), ('csa', 'C')]
assert sort_tuple([("Sarala", 28), ("Ayesha", 30), ("Suman", 29),("Sai", 21), ("G", "H")]) == [('Ayesha', 30), ('G', 'H'), ('Sai', 21), ('Sarala', 28), ('Suman', 29)]
|
|
840 | Write a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not. | Check_Solution | def Check_Solution(a,b,c):
if b == 0:
return ("Yes")
else:
return ("No") | [
"assert Check_Solution(7, 2, 5) == \"No\"",
"assert Check_Solution(3, 5, 6) == \"No\"",
"assert Check_Solution(7, 1, 7) == \"No\""
] | def check(candidate):
# Check some simple cases
assert Check_Solution(2,0,-1) == "Yes"
assert Check_Solution(1,-5,6) == "No"
assert Check_Solution(2,0,2) == "Yes"
|
|
841 | Write a function to count the number of inversions in the given array. | get_inv_count | def get_inv_count(arr, n):
inv_count = 0
for i in range(n):
for j in range(i + 1, n):
if (arr[i] > arr[j]):
inv_count += 1
return inv_count | [
"assert get_inv_count([8, 1, 5], 3) == 2",
"assert get_inv_count([2, 5, 1], 2) == 0",
"assert get_inv_count([1, 3, 3], 3) == 0"
] | def check(candidate):
# Check some simple cases
assert get_inv_count([1, 20, 6, 4, 5], 5) == 5
assert get_inv_count([8, 4, 2, 1], 4) == 6
assert get_inv_count([3, 1, 2], 3) == 2
|
|
842 | Write a function to find the number which occurs for odd number of times in the given array. | get_odd_occurence | def get_odd_occurence(arr, arr_size):
for i in range(0, arr_size):
count = 0
for j in range(0, arr_size):
if arr[i] == arr[j]:
count += 1
if (count % 2 != 0):
return arr[i]
return -1 | [
"assert get_odd_occurence([5, 5, 6, 9, 4, 1, 4], 3) == 6",
"assert get_odd_occurence([2, 3, 3, 4, 5, 3, 3], 4) == 2",
"assert get_odd_occurence([5, 10, 6, 9, 6, 7, 10], 4) == 5"
] | def check(candidate):
# Check some simple cases
assert get_odd_occurence([2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2], 13) == 5
assert get_odd_occurence([1, 2, 3, 2, 3, 1, 3], 7) == 3
assert get_odd_occurence([5, 7, 2, 7, 5, 2, 5], 7) == 5
|
|
843 | Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm. | nth_super_ugly_number | import heapq
def nth_super_ugly_number(n, primes):
uglies = [1]
def gen(prime):
for ugly in uglies:
yield ugly * prime
merged = heapq.merge(*map(gen, primes))
while len(uglies) < n:
ugly = next(merged)
if ugly != uglies[-1]:
uglies.append(ugly)
return uglies[-1] | [
"assert nth_super_ugly_number(104, [3, 12, 9, 18]) == 13436928",
"assert nth_super_ugly_number(98, [1, 11, 15, 16]) == 81776640",
"assert nth_super_ugly_number(102, [7, 5, 16, 24]) == 98304"
] | def check(candidate):
# Check some simple cases
assert nth_super_ugly_number(12,[2,7,13,19])==32
assert nth_super_ugly_number(10,[2,7,13,19])==26
assert nth_super_ugly_number(100,[2,7,13,19])==5408
|
|
844 | Write a python function to find the kth element in an array containing odd elements first and then even elements. | get_Number | def get_Number(n, k):
arr = [0] * n;
i = 0;
odd = 1;
while (odd <= n):
arr[i] = odd;
i += 1;
odd += 2;
even = 2;
while (even <= n):
arr[i] = even;
i += 1;
even += 2;
return arr[k - 1]; | [
"assert get_Number(8, 2) == 3",
"assert get_Number(10, 6) == 2",
"assert get_Number(6, 3) == 5"
] | def check(candidate):
# Check some simple cases
assert get_Number(8,5) == 2
assert get_Number(7,2) == 3
assert get_Number(5,2) == 3
|
|
845 | Write a python function to count the number of digits in factorial of a given number. | find_Digits | import math
def find_Digits(n):
if (n < 0):
return 0;
if (n <= 1):
return 1;
x = ((n * math.log10(n / math.e) + math.log10(2 * math.pi * n) /2.0));
return math.floor(x) + 1; | [
"assert find_Digits(7) == 4",
"assert find_Digits(9) == 6",
"assert find_Digits(2) == 1"
] | def check(candidate):
# Check some simple cases
assert find_Digits(7) == 4
assert find_Digits(5) == 3
assert find_Digits(4) == 2
|
|
846 | Write a function to find the minimum number of platforms required for a railway/bus station. | find_platform | def find_platform(arr, dep, n):
arr.sort()
dep.sort()
plat_needed = 1
result = 1
i = 1
j = 0
while (i < n and j < n):
if (arr[i] <= dep[j]):
plat_needed+= 1
i+= 1
elif (arr[i] > dep[j]):
plat_needed-= 1
j+= 1
if (plat_needed > result):
result = plat_needed
return result | [
"assert find_platform([6, 6, 2, 8], [3, 2, 6, 3], 3) == 1",
"assert find_platform([8, 9, 6, 8], [4, 6, 6, 3], 3) == 1",
"assert find_platform([3, 10, 9, 11], [9, 8, 3, 3], 3) == 1"
] | def check(candidate):
# Check some simple cases
assert find_platform([900, 940, 950, 1100, 1500, 1800],[910, 1200, 1120, 1130, 1900, 2000],6)==3
assert find_platform([100,200,300,400],[700,800,900,1000],4)==4
assert find_platform([5,6,7,8],[4,3,2,1],4)==1
|
|
847 | Write a python function to copy a list from a singleton tuple. | lcopy | def lcopy(xs):
return xs[:]
| [
"assert lcopy([5, 1, 4]) == [5, 1, 4]",
"assert lcopy([6, 9, 3]) == [6, 9, 3]",
"assert lcopy([3, 6, 11]) == [3, 6, 11]"
] | def check(candidate):
# Check some simple cases
assert lcopy([1, 2, 3]) == [1, 2, 3]
assert lcopy([4, 8, 2, 10, 15, 18]) == [4, 8, 2, 10, 15, 18]
assert lcopy([4, 5, 6]) == [4, 5, 6]
|
|
848 | Write a function to find the area of a trapezium. | area_trapezium | def area_trapezium(base1,base2,height):
area = 0.5 * (base1 + base2) * height
return area | [
"assert area_trapezium(19, 25, 35) == 770.0",
"assert area_trapezium(11, 24, 33) == 577.5",
"assert area_trapezium(18, 26, 32) == 704.0"
] | def check(candidate):
# Check some simple cases
assert area_trapezium(6,9,4)==30
assert area_trapezium(10,20,30)==450
assert area_trapezium(15,25,35)==700
|
|
849 | Write a python function to find sum of all prime divisors of a given number. | Sum | def Sum(N):
SumOfPrimeDivisors = [0]*(N + 1)
for i in range(2,N + 1) :
if (SumOfPrimeDivisors[i] == 0) :
for j in range(i,N + 1,i) :
SumOfPrimeDivisors[j] += i
return SumOfPrimeDivisors[N] | [
"assert Sum(41) == 41",
"assert Sum(42) == 12",
"assert Sum(35) == 12"
] | def check(candidate):
# Check some simple cases
assert Sum(60) == 10
assert Sum(39) == 16
assert Sum(40) == 7
|
|
850 | Write a function to check if a triangle of positive area is possible with the given angles. | is_triangleexists | def is_triangleexists(a,b,c):
if(a != 0 and b != 0 and c != 0 and (a + b + c)== 180):
if((a + b)>= c or (b + c)>= a or (a + c)>= b):
return True
else:
return False
else:
return False | [
"assert is_triangleexists(150, 28, 68) == False",
"assert is_triangleexists(151, 28, 65) == False",
"assert is_triangleexists(154, 34, 71) == False"
] | def check(candidate):
# Check some simple cases
assert is_triangleexists(50,60,70)==True
assert is_triangleexists(90,45,45)==True
assert is_triangleexists(150,30,70)==False
|
|
851 | Write a python function to find sum of inverse of divisors. | Sum_of_Inverse_Divisors | def Sum_of_Inverse_Divisors(N,Sum):
ans = float(Sum)*1.0 /float(N);
return round(ans,2); | [
"assert Sum_of_Inverse_Divisors(5, 9) == 1.8",
"assert Sum_of_Inverse_Divisors(6, 8) == 1.33",
"assert Sum_of_Inverse_Divisors(5, 8) == 1.6"
] | def check(candidate):
# Check some simple cases
assert Sum_of_Inverse_Divisors(6,12) == 2
assert Sum_of_Inverse_Divisors(9,13) == 1.44
assert Sum_of_Inverse_Divisors(1,4) == 4
|
|
852 | Write a python function to remove negative numbers from a list. | remove_negs | def remove_negs(num_list):
for item in num_list:
if item < 0:
num_list.remove(item)
return num_list | [
"assert remove_negs([5, 6, -7, 12, -7]) == [5, 6, 12]",
"assert remove_negs([7, 3, -2, 10, -12]) == [7, 3, 10]",
"assert remove_negs([5, 9, -3, 3, -8]) == [5, 9, 3]"
] | def check(candidate):
# Check some simple cases
assert remove_negs([1,-2,3,-4]) == [1,3]
assert remove_negs([1,2,3,-4]) == [1,2,3]
assert remove_negs([4,5,-6,7,-8]) == [4,5,7]
|
|
853 | Write a python function to find sum of odd factors of a number. | sum_of_odd_Factors | import math
def sum_of_odd_Factors(n):
res = 1
while n % 2 == 0:
n = n // 2
for i in range(3,int(math.sqrt(n) + 1)):
count = 0
curr_sum = 1
curr_term = 1
while n % i == 0:
count+=1
n = n // i
curr_term *= i
curr_sum += curr_term
res *= curr_sum
if n >= 2:
res *= (1 + n)
return res | [
"assert sum_of_odd_Factors(3) == 4",
"assert sum_of_odd_Factors(3) == 4",
"assert sum_of_odd_Factors(4) == 1"
] | def check(candidate):
# Check some simple cases
assert sum_of_odd_Factors(30) == 24
assert sum_of_odd_Factors(18) == 13
assert sum_of_odd_Factors(2) == 1
|
|
854 | Write a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm. | raw_heap | import heapq as hq
def raw_heap(rawheap):
hq.heapify(rawheap)
return rawheap | [
"assert raw_heap([1, 1, 5, 7]) == [1, 1, 5, 7]",
"assert raw_heap([5, 3, 3, 2]) == [2, 3, 3, 5]",
"assert raw_heap([3, 7, 1, 3]) == [1, 3, 3, 7]"
] | def check(candidate):
# Check some simple cases
assert raw_heap([25, 44, 68, 21, 39, 23, 89])==[21, 25, 23, 44, 39, 68, 89]
assert raw_heap([25, 35, 22, 85, 14, 65, 75, 25, 58])== [14, 25, 22, 25, 35, 65, 75, 85, 58]
assert raw_heap([4, 5, 6, 2])==[2, 4, 6, 5]
|
|
855 | Write a python function to check for even parity of a given number. | check_Even_Parity | def check_Even_Parity(x):
parity = 0
while (x != 0):
x = x & (x - 1)
parity += 1
if (parity % 2 == 0):
return True
else:
return False | [
"assert check_Even_Parity(14) == False",
"assert check_Even_Parity(17) == True",
"assert check_Even_Parity(17) == True"
] | def check(candidate):
# Check some simple cases
assert check_Even_Parity(10) == True
assert check_Even_Parity(11) == False
assert check_Even_Parity(18) == True
|
|
856 | Write a python function to find minimum adjacent swaps required to sort binary array. | find_Min_Swaps | def find_Min_Swaps(arr,n) :
noOfZeroes = [0] * n
count = 0
noOfZeroes[n - 1] = 1 - arr[n - 1]
for i in range(n-2,-1,-1) :
noOfZeroes[i] = noOfZeroes[i + 1]
if (arr[i] == 0) :
noOfZeroes[i] = noOfZeroes[i] + 1
for i in range(0,n) :
if (arr[i] == 1) :
count = count + noOfZeroes[i]
return count | [
"assert find_Min_Swaps([5, 4, 1, 5, 2], 2) == 0",
"assert find_Min_Swaps([3, 4, 1, 3, 4], 2) == 0",
"assert find_Min_Swaps([1, 5, 5, 3, 3], 1) == 0"
] | def check(candidate):
# Check some simple cases
assert find_Min_Swaps([1,0,1,0],4) == 3
assert find_Min_Swaps([0,1,0],3) == 1
assert find_Min_Swaps([0,0,1,1,0],5) == 2
|
|
857 | Write a function to list out the list of given strings individually using map function. | listify_list | def listify_list(list1):
result = list(map(list,list1))
return result | [
"assert listify_list(['ikellk', 'cpbdwejj', 'qvqn', 'pgiivaks', 'wezggakemy', 'jhgmhdhi']) == [['i', 'k', 'e', 'l', 'l', 'k'], ['c', 'p', 'b', 'd', 'w', 'e', 'j', 'j'], ['q', 'v', 'q', 'n'], ['p', 'g', 'i', 'i', 'v', 'a', 'k', 's'], ['w', 'e', 'z', 'g', 'g', 'a', 'k', 'e', 'm', 'y'], ['j', 'h', 'g', 'm', 'h', 'd', 'h', 'i']]",
"assert listify_list(['zzrfc', 'mouobeth', 'xktrak', 'phi rjq', 'qfttobjj', 'clkefvqka']) == [['z', 'z', 'r', 'f', 'c'], ['m', 'o', 'u', 'o', 'b', 'e', 't', 'h'], ['x', 'k', 't', 'r', 'a', 'k'], ['p', 'h', 'i', ' ', 'r', 'j', 'q'], ['q', 'f', 't', 't', 'o', 'b', 'j', 'j'], ['c', 'l', 'k', 'e', 'f', 'v', 'q', 'k', 'a']]",
"assert listify_list(['rpyxd', 'ufwbpsv', 'zt gdzbqkoh', 'vyoykj', 'qngksik', 'znbhwxfzb']) == [['r', 'p', 'y', 'x', 'd'], ['u', 'f', 'w', 'b', 'p', 's', 'v'], ['z', 't', ' ', 'g', 'd', 'z', 'b', 'q', 'k', 'o', 'h'], ['v', 'y', 'o', 'y', 'k', 'j'], ['q', 'n', 'g', 'k', 's', 'i', 'k'], ['z', 'n', 'b', 'h', 'w', 'x', 'f', 'z', 'b']]"
] | def check(candidate):
# Check some simple cases
assert listify_list(['Red', 'Blue', 'Black', 'White', 'Pink'])==[['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e'], ['P', 'i', 'n', 'k']]
assert listify_list(['python'])==[['p', 'y', 't', 'h', 'o', 'n']]
assert listify_list([' red ', 'green',' black', 'blue ',' orange', 'brown'])==[[' ', 'r', 'e', 'd', ' '], ['g', 'r', 'e', 'e', 'n'], [' ', 'b', 'l', 'a', 'c', 'k'], ['b', 'l', 'u', 'e', ' '], [' ', 'o', 'r', 'a', 'n', 'g', 'e'], ['b', 'r', 'o', 'w', 'n']]
|
|
858 | Write a function to count number of lists in a given list of lists and square the count. | count_list | def count_list(input_list):
return (len(input_list))**2 | [
"assert count_list([[7, 6], [[8, 8], [6, 3, 11]], [14, 12, 12]]) == 9",
"assert count_list([[1, 4], [[7, 6], [3, 2, 3]], [6, 11, 16]]) == 9",
"assert count_list([[1, 2], [[10, 11], [6, 8, 4]], [8, 16, 17]]) == 9"
] | def check(candidate):
# Check some simple cases
assert count_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==25
assert count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]] )==16
assert count_list([[2, 4], [[6,8], [4,5,8]], [10, 12, 14]])==9
|
|
859 | Write a function to generate all sublists of a given list. | sub_lists | from itertools import combinations
def sub_lists(my_list):
subs = []
for i in range(0, len(my_list)+1):
temp = [list(x) for x in combinations(my_list, i)]
if len(temp)>0:
subs.extend(temp)
return subs | [
"assert sub_lists([1, 7, 2]) == [[], [1], [7], [2], [1, 7], [1, 2], [7, 2], [1, 7, 2]]",
"assert sub_lists([3, 4, 2]) == [[], [3], [4], [2], [3, 4], [3, 2], [4, 2], [3, 4, 2]]",
"assert sub_lists([3, 5, 1]) == [[], [3], [5], [1], [3, 5], [3, 1], [5, 1], [3, 5, 1]]"
] | def check(candidate):
# Check some simple cases
assert sub_lists([10, 20, 30, 40])==[[], [10], [20], [30], [40], [10, 20], [10, 30], [10, 40], [20, 30], [20, 40], [30, 40], [10, 20, 30], [10, 20, 40], [10, 30, 40], [20, 30, 40], [10, 20, 30, 40]]
assert sub_lists(['X', 'Y', 'Z'])==[[], ['X'], ['Y'], ['Z'], ['X', 'Y'], ['X', 'Z'], ['Y', 'Z'], ['X', 'Y', 'Z']]
assert sub_lists([1,2,3])==[[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]
|
|
860 | Write a function to check whether the given string is ending with only alphanumeric characters or not using regex. | check_alphanumeric | import re
regex = '[a-zA-z0-9]$'
def check_alphanumeric(string):
if(re.search(regex, string)):
return ("Accept")
else:
return ("Discard") | [
"assert check_alphanumeric(\"/u>d%r\") == \"Accept\"",
"assert check_alphanumeric(\"zw+gjlj\") == \"Accept\"",
"assert check_alphanumeric(\"%oh$+caj#rvij\") == \"Accept\""
] | def check(candidate):
# Check some simple cases
assert check_alphanumeric("dawood@") == 'Discard'
assert check_alphanumeric("skdmsam326") == 'Accept'
assert check_alphanumeric("cooltricks@") == 'Discard'
|
|
861 | Write a function to find all anagrams of a string in a given list of strings using lambda function. | anagram_lambda | from collections import Counter
def anagram_lambda(texts,str):
result = list(filter(lambda x: (Counter(str) == Counter(x)), texts))
return result | [
"assert anagram_lambda(['wxw pjy', 'muphf', 'vlj'], 'dniecpqt') == []",
"assert anagram_lambda(['zhybg', 'lcba urjvrlw', 'faoz'], 'rcdy') == []",
"assert anagram_lambda(['eqwlsx', 'ygz', 'cqstm'], 'qkts') == []"
] | def check(candidate):
# Check some simple cases
assert anagram_lambda(["bcda", "abce", "cbda", "cbea", "adcb"],"abcd")==['bcda', 'cbda', 'adcb']
assert anagram_lambda(["recitals"," python"], "articles" )==["recitals"]
assert anagram_lambda([" keep"," abcdef"," xyz"]," peek")==[" keep"]
|
|
862 | Write a function to find the occurrences of n most common words in a given text. | n_common_words | from collections import Counter
import re
def n_common_words(text,n):
words = re.findall('\w+',text)
n_common_words= Counter(words).most_common(n)
return list(n_common_words) | [
"assert n_common_words('chbbkm gmxpybveg wjkst bhotvpn ', 6) == [('chbbkm', 1), ('gmxpybveg', 1), ('wjkst', 1), ('bhotvpn', 1)]",
"assert n_common_words('fazkdrxzmyxvmjuo leyzkpjxglkczf', 5) == [('fazkdrxzmyxvmjuo', 1), ('leyzkpjxglkczf', 1)]",
"assert n_common_words('ufxkiaytsjehzzb vgzwwrkugnudbylqc', 1) == [('ufxkiaytsjehzzb', 1)]"
] | def check(candidate):
# Check some simple cases
assert n_common_words("python is a programming language",1)==[('python', 1)]
assert n_common_words("python is a programming language",1)==[('python', 1)]
assert n_common_words("python is a programming language",5)==[('python', 1),('is', 1), ('a', 1), ('programming', 1), ('language', 1)]
|
|
863 | Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers. | find_longest_conseq_subseq | def find_longest_conseq_subseq(arr, n):
ans = 0
count = 0
arr.sort()
v = []
v.append(arr[0])
for i in range(1, n):
if (arr[i] != arr[i - 1]):
v.append(arr[i])
for i in range(len(v)):
if (i > 0 and v[i] == v[i - 1] + 1):
count += 1
else:
count = 1
ans = max(ans, count)
return ans | [
"assert find_longest_conseq_subseq([41, 37, 56, 34, 40, 32, 34, 97, 48, 32, 45], 7) == 2",
"assert find_longest_conseq_subseq([31, 43, 59, 32, 43, 38, 34, 97, 38, 34, 44], 6) == 2",
"assert find_longest_conseq_subseq([38, 38, 52, 34, 49, 36, 33, 91, 40, 36, 45], 8) == 2"
] | def check(candidate):
# Check some simple cases
assert find_longest_conseq_subseq([1, 2, 2, 3], 4) == 3
assert find_longest_conseq_subseq([1, 9, 3, 10, 4, 20, 2], 7) == 4
assert find_longest_conseq_subseq([36, 41, 56, 35, 44, 33, 34, 92, 43, 32, 42], 11) == 5
|
|
864 | Write a function to find palindromes in a given list of strings using lambda function. | palindrome_lambda | def palindrome_lambda(texts):
result = list(filter(lambda x: (x == "".join(reversed(x))), texts))
return result | [
"assert palindrome_lambda(['nooo', 'ojyurs', 'abusn', 'uulcvfhw']) == []",
"assert palindrome_lambda(['yycqvtqm', 'cvlq', 'rxkgdpn', 'afuk']) == []",
"assert palindrome_lambda(['wwys', 'avsbe', 'zmj', 'ollnqco']) == []"
] | def check(candidate):
# Check some simple cases
assert palindrome_lambda(["php", "res", "Python", "abcd", "Java", "aaa"])==['php', 'aaa']
assert palindrome_lambda(["abcd", "Python", "abba", "aba"])==['abba', 'aba']
assert palindrome_lambda(["abcd", "abbccbba", "abba", "aba"])==['abbccbba', 'abba', 'aba']
|
|
865 | Write a function to print n-times a list using map function. | ntimes_list | def ntimes_list(nums,n):
result = map(lambda x:n*x, nums)
return list(result) | [
"assert ntimes_list([2, 4, 1, 2, 9, 6, 6], 12) == [24, 48, 12, 24, 108, 72, 72]",
"assert ntimes_list([1, 1, 1, 9, 2, 9, 4], 15) == [15, 15, 15, 135, 30, 135, 60]",
"assert ntimes_list([1, 3, 5, 6, 10, 4, 2], 13) == [13, 39, 65, 78, 130, 52, 26]"
] | def check(candidate):
# Check some simple cases
assert ntimes_list([1, 2, 3, 4, 5, 6, 7],3)==[3, 6, 9, 12, 15, 18, 21]
assert ntimes_list([1, 2, 3, 4, 5, 6, 7],4)==[4, 8, 12, 16, 20, 24, 28]
assert ntimes_list([1, 2, 3, 4, 5, 6, 7],10)==[10, 20, 30, 40, 50, 60, 70]
|
|
866 | Write a function to check whether the given month name contains 31 days or not. | check_monthnumb | def check_monthnumb(monthname2):
if(monthname2=="January" or monthname2=="March"or monthname2=="May" or monthname2=="July" or monthname2=="Augest" or monthname2=="October" or monthname2=="December"):
return True
else:
return False | [
"assert check_monthnumb(\"DNzVHPMP\") == False",
"assert check_monthnumb(\"JeA\") == False",
"assert check_monthnumb(\"xOyIrpm\") == False"
] | def check(candidate):
# Check some simple cases
assert check_monthnumb("February")==False
assert check_monthnumb("January")==True
assert check_monthnumb("March")==True
|
|
867 | Write a python function to add a minimum number such that the sum of array becomes even. | min_Num | def min_Num(arr,n):
odd = 0
for i in range(n):
if (arr[i] % 2):
odd += 1
if (odd % 2):
return 1
return 2 | [
"assert min_Num([5, 1, 4], 2) == 2",
"assert min_Num([3, 6, 6], 3) == 1",
"assert min_Num([6, 3, 4], 3) == 1"
] | def check(candidate):
# Check some simple cases
assert min_Num([1,2,3,4,5,6,7,8,9],9) == 1
assert min_Num([1,2,3,4,5,6,7,8],8) == 2
assert min_Num([1,2,3],3) == 2
|
|
868 | Write a python function to find the length of the last word in a given string. | length_Of_Last_Word | def length_Of_Last_Word(a):
l = 0
x = a.strip()
for i in range(len(x)):
if x[i] == " ":
l = 0
else:
l += 1
return l | [
"assert length_Of_Last_Word(\"kh\") == 2",
"assert length_Of_Last_Word(\"bht\") == 3",
"assert length_Of_Last_Word(\"m\") == 1"
] | def check(candidate):
# Check some simple cases
assert length_Of_Last_Word("python language") == 8
assert length_Of_Last_Word("PHP") == 3
assert length_Of_Last_Word("") == 0
|
|
869 | Write a function to remove sublists from a given list of lists, which are outside a given range. | remove_list_range | def remove_list_range(list1, leftrange, rigthrange):
result = [i for i in list1 if (min(i)>=leftrange and max(i)<=rigthrange)]
return result | [
"assert remove_list_range([[4], [4], [4, 3, 4], [5, 5, 3, 6, 9, 2], [8, 14], [15, 17, 19, 18]], 1, 8) == [[4], [4], [4, 3, 4]]",
"assert remove_list_range([[5], [3], [1, 7, 6], [2, 4, 6, 8, 4, 6], [8, 7], [13, 11, 13, 12]], 1, 4) == [[3]]",
"assert remove_list_range([[7], [2], [3, 1, 2], [2, 3, 2, 6, 11, 7], [5, 16], [14, 17, 16, 18]], 4, 11) == [[7]]"
] | def check(candidate):
# Check some simple cases
assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],13,17)==[[13, 14, 15, 17]]
assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],1,3)==[[2], [1, 2, 3]]
assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],0,7)==[[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7]]
|
|
870 | Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function. | sum_positivenum | def sum_positivenum(nums):
sum_positivenum = list(filter(lambda nums:nums>0,nums))
return sum(sum_positivenum) | [
"assert sum_positivenum([14, -69, 53, 42, 152, -636, 116, 44, 85, -194]) == 506",
"assert sum_positivenum([23, -63, 57, 44, 148, -634, 116, 45, 92, -192]) == 525",
"assert sum_positivenum([19, -60, 53, 44, 155, -641, 122, 43, 93, -192]) == 529"
] | def check(candidate):
# Check some simple cases
assert sum_positivenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==48
assert sum_positivenum([10,15,-14,13,-18,12,-20])==50
assert sum_positivenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==522
|
|
871 | Write a python function to check whether the given strings are rotations of each other or not. | are_Rotations | def are_Rotations(string1,string2):
size1 = len(string1)
size2 = len(string2)
temp = ''
if size1 != size2:
return False
temp = string1 + string1
if (temp.count(string2)> 0):
return True
else:
return False | [
"assert are_Rotations('znv', 'levtuhb') == False",
"assert are_Rotations('zoom', 'uugflrguw') == False",
"assert are_Rotations('oqh', 'yxyvqjme') == False"
] | def check(candidate):
# Check some simple cases
assert are_Rotations("abc","cba") == False
assert are_Rotations("abcd","cdba") == False
assert are_Rotations("abacd","cdaba") == True
|
|
872 | Write a function to check if a nested list is a subset of another nested list. | check_subset | def check_subset(list1,list2):
return all(map(list1.__contains__,list2)) | [
"assert check_subset([[[2, 1], [4, 6]], [[7, 5], [1, 7]]], [[[5, 7], [3, 4]]]) == False",
"assert check_subset([[[3, 6], [4, 4]], [[8, 6], [9, 10]]], [[[8, 4], [2, 11]]]) == False",
"assert check_subset([[[1, 5], [4, 8]], [[7, 2], [7, 5]]], [[[8, 4], [5, 8]]]) == False"
] | def check(candidate):
# Check some simple cases
assert check_subset([[1, 3], [5, 7], [9, 11], [13, 15, 17]] ,[[1, 3],[13,15,17]])==True
assert check_subset([[1, 2], [2, 3], [3, 4], [5, 6]],[[3, 4], [5, 6]])==True
assert check_subset([[[1, 2], [2, 3]], [[3, 4], [5, 7]]],[[[3, 4], [5, 6]]])==False
|
|
873 | Write a function to solve the fibonacci sequence using recursion. | fibonacci | def fibonacci(n):
if n == 1 or n == 2:
return 1
else:
return (fibonacci(n - 1) + (fibonacci(n - 2))) | [
"assert fibonacci(13) == 233",
"assert fibonacci(12) == 144",
"assert fibonacci(9) == 34"
] | def check(candidate):
# Check some simple cases
assert fibonacci(7) == 13
assert fibonacci(8) == 21
assert fibonacci(9) == 34
|
|
874 | Write a python function to check if the string is a concatenation of another string. | check_Concat | def check_Concat(str1,str2):
N = len(str1)
M = len(str2)
if (N % M != 0):
return False
for i in range(N):
if (str1[i] != str2[i % M]):
return False
return True | [
"assert check_Concat('sjmhbtzt', 'psipzb') == False",
"assert check_Concat('tfchgkmxj', 'csyts') == False",
"assert check_Concat('rtxiymllt', 'tty') == False"
] | def check(candidate):
# Check some simple cases
assert check_Concat("abcabcabc","abc") == True
assert check_Concat("abcab","abc") == False
assert check_Concat("aba","ab") == False
|
|
875 | Write a function to find the minimum difference in the tuple pairs of given tuples. | min_difference | def min_difference(test_list):
temp = [abs(b - a) for a, b in test_list]
res = min(temp)
return (res) | [
"assert min_difference([(8, 17), (6, 9), (7, 3), (6, 22)]) == 3",
"assert min_difference([(8, 19), (2, 4), (11, 1), (3, 20)]) == 2",
"assert min_difference([(1, 13), (6, 12), (12, 7), (8, 24)]) == 5"
] | def check(candidate):
# Check some simple cases
assert min_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 1
assert min_difference([(4, 6), (12, 8), (11, 4), (2, 13)]) == 2
assert min_difference([(5, 17), (3, 9), (12, 5), (3, 24)]) == 6
|
|
876 | Write a python function to find lcm of two positive integers. | lcm | def lcm(x, y):
if x > y:
z = x
else:
z = y
while(True):
if((z % x == 0) and (z % y == 0)):
lcm = z
break
z += 1
return lcm | [
"assert lcm(3, 1) == 3",
"assert lcm(4, 8) == 8",
"assert lcm(6, 3) == 6"
] | def check(candidate):
# Check some simple cases
assert lcm(4,6) == 12
assert lcm(15,17) == 255
assert lcm(2,6) == 6
|
|
877 | Write a python function to sort the given string. | sort_String | def sort_String(str) :
str = ''.join(sorted(str))
return (str) | [
"assert sort_String(\"jweluiwl\") == \"eijlluww\"",
"assert sort_String(\"vjyn\") == \"jnvy\"",
"assert sort_String(\"tenkfm\") == \"efkmnt\""
] | def check(candidate):
# Check some simple cases
assert sort_String("cba") == "abc"
assert sort_String("data") == "aadt"
assert sort_String("zxy") == "xyz"
|
|
878 | Write a function to check if the given tuple contains only k elements. | check_tuples | def check_tuples(test_tuple, K):
res = all(ele in K for ele in test_tuple)
return (res) | [
"assert check_tuples((11, 6, 12, 10, 13, 6), [4, 6, 3]) == False",
"assert check_tuples((9, 7, 8, 7, 4, 8), [12, 11, 6]) == False",
"assert check_tuples((10, 5, 9, 1, 6, 9), [12, 5, 5]) == False"
] | def check(candidate):
# Check some simple cases
assert check_tuples((3, 5, 6, 5, 3, 6),[3, 6, 5]) == True
assert check_tuples((4, 5, 6, 4, 6, 5),[4, 5, 6]) == True
assert check_tuples((9, 8, 7, 6, 8, 9),[9, 8, 1]) == False
|
|
879 | Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex. | text_match | import re
def text_match(text):
patterns = 'a.*?b$'
if re.search(patterns, text):
return ('Found a match!')
else:
return ('Not matched!') | [
"assert text_match(\"spwtlec\") == \"Not matched!\"",
"assert text_match(\"ebgwwu\") == \"Not matched!\"",
"assert text_match(\"jdttxlhndrwh\") == \"Not matched!\""
] | def check(candidate):
# Check some simple cases
assert text_match("aabbbbd") == 'Not matched!'
assert text_match("aabAbbbc") == 'Not matched!'
assert text_match("accddbbjjjb") == 'Found a match!'
|
|
880 | Write a python function to find number of solutions in quadratic equation. | Check_Solution | def Check_Solution(a,b,c) :
if ((b*b) - (4*a*c)) > 0 :
return ("2 solutions")
elif ((b*b) - (4*a*c)) == 0 :
return ("1 solution")
else :
return ("No solutions") | [
"assert Check_Solution(1, 5, 1) == \"2 solutions\"",
"assert Check_Solution(1, 2, 2) == \"No solutions\"",
"assert Check_Solution(2, 2, 5) == \"No solutions\""
] | def check(candidate):
# Check some simple cases
assert Check_Solution(2,5,2) == "2 solutions"
assert Check_Solution(1,1,1) == "No solutions"
assert Check_Solution(1,2,1) == "1 solution"
|
|
881 | Write a function to find the sum of first even and odd number of a given list. | sum_even_odd | def sum_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 sum_even_odd([3, 10, 4, 14, 10]) == 13",
"assert sum_even_odd([4, 7, 4, 8, 10]) == 11",
"assert sum_even_odd([2, 4, 9, 10, 7]) == 11"
] | def check(candidate):
# Check some simple cases
assert sum_even_odd([1,3,5,7,4,1,6,8])==5
assert sum_even_odd([1,2,3,4,5,6,7,8,9,10])==3
assert sum_even_odd([1,5,7,9,10])==11
|
|
882 | Write a function to caluclate perimeter of a parallelogram. | parallelogram_perimeter | def parallelogram_perimeter(b,h):
perimeter=2*(b*h)
return perimeter | [
"assert parallelogram_perimeter(6, 10) == 120",
"assert parallelogram_perimeter(8, 6) == 96",
"assert parallelogram_perimeter(13, 5) == 130"
] | def check(candidate):
# Check some simple cases
assert parallelogram_perimeter(10,20)==400
assert parallelogram_perimeter(15,20)==600
assert parallelogram_perimeter(8,9)==144
|
|
883 | Write a function to find numbers divisible by m and n from a list of numbers using lambda function. | div_of_nums | def div_of_nums(nums,m,n):
result = list(filter(lambda x: (x % m == 0 and x % n == 0), nums))
return result | [
"assert div_of_nums([9, 15, 9, 13, 22, 10, 16], 5, 10) == [10]",
"assert div_of_nums([10, 12, 16, 13, 19, 10, 19], 7, 2) == []",
"assert div_of_nums([7, 20, 16, 12, 18, 15, 16], 5, 5) == [20, 15]"
] | def check(candidate):
# Check some simple cases
assert div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190],2,4)==[ 152,44]
assert div_of_nums([1, 2, 3, 5, 7, 8, 10],2,5)==[10]
assert div_of_nums([10,15,14,13,18,12,20],10,5)==[10,20]
|
|
884 | Write a python function to check whether all the bits are within a given range or not. | all_Bits_Set_In_The_Given_Range | def all_Bits_Set_In_The_Given_Range(n,l,r):
num = ((1 << r) - 1) ^ ((1 << (l - 1)) - 1)
new_num = n & num
if (num == new_num):
return True
return False | [
"assert all_Bits_Set_In_The_Given_Range(18, 3, 5) == False",
"assert all_Bits_Set_In_The_Given_Range(23, 1, 5) == False",
"assert all_Bits_Set_In_The_Given_Range(24, 2, 3) == False"
] | def check(candidate):
# Check some simple cases
assert all_Bits_Set_In_The_Given_Range(10,2,1) == True
assert all_Bits_Set_In_The_Given_Range(5,2,4) == False
assert all_Bits_Set_In_The_Given_Range(22,2,3) == True
|
|
885 | Write a python function to check whether the two given strings are isomorphic to each other or not. | is_Isomorphic | def is_Isomorphic(str1,str2):
dict_str1 = {}
dict_str2 = {}
for i, value in enumerate(str1):
dict_str1[value] = dict_str1.get(value,[]) + [i]
for j, value in enumerate(str2):
dict_str2[value] = dict_str2.get(value,[]) + [j]
if sorted(dict_str1.values()) == sorted(dict_str2.values()):
return True
else:
return False | [
"assert is_Isomorphic('conv', 'syukcw') == False",
"assert is_Isomorphic('rflupu', 'ohq') == False",
"assert is_Isomorphic('hvef', 'kkqgfu') == False"
] | def check(candidate):
# Check some simple cases
assert is_Isomorphic("paper","title") == True
assert is_Isomorphic("ab","ba") == True
assert is_Isomorphic("ab","aa") == False
|
|
886 | Write a function to add all the numbers in a list and divide it with the length of the list. | sum_num | def sum_num(numbers):
total = 0
for x in numbers:
total += x
return total/len(numbers) | [
"assert sum_num((22, 12, 23)) == 19.0",
"assert sum_num((16, 10, 18)) == 14.666666666666666",
"assert sum_num((23, 20, 13)) == 18.666666666666668"
] | def check(candidate):
# Check some simple cases
assert sum_num((8, 2, 3, 0, 7))==4.0
assert sum_num((-10,-20,-30))==-20.0
assert sum_num((19,15,18))==17.333333333333332
|
|
887 | Write a python function to check whether the given number is odd or not using bitwise operator. | is_odd | def is_odd(n) :
if (n^1 == n-1) :
return True;
else :
return False; | [
"assert is_odd(5) == True",
"assert is_odd(12) == False",
"assert is_odd(8) == False"
] | def check(candidate):
# Check some simple cases
assert is_odd(5) == True
assert is_odd(6) == False
assert is_odd(7) == True
|
|
888 | Write a function to substract the elements of the given nested tuples. | substract_elements | def substract_elements(test_tup1, test_tup2):
res = tuple(tuple(a - b for a, b in zip(tup1, tup2))
for tup1, tup2 in zip(test_tup1, test_tup2))
return (res) | [
"assert substract_elements(((23, 1), (16, 5), (24, 15), (15, 17)), ((15, 5), (12, 15), (10, 2), (19, 5))) == ((8, -4), (4, -10), (14, 13), (-4, 12))",
"assert substract_elements(((16, 1), (13, 2), (24, 15), (12, 7)), ((10, 4), (20, 6), (12, 1), (23, 8))) == ((6, -3), (-7, -4), (12, 14), (-11, -1))",
"assert substract_elements(((21, 2), (23, 9), (15, 10), (21, 8)), ((10, 12), (17, 16), (17, 6), (15, 1))) == ((11, -10), (6, -7), (-2, 4), (6, 7))"
] | def check(candidate):
# Check some simple cases
assert substract_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((-5, -4), (1, -4), (1, 8), (-6, 7))
assert substract_elements(((13, 4), (14, 6), (13, 10), (12, 11)), ((19, 8), (14, 10), (12, 2), (18, 4))) == ((-6, -4), (0, -4), (1, 8), (-6, 7))
assert substract_elements(((19, 5), (18, 7), (19, 11), (17, 12)), ((12, 9), (17, 11), (13, 3), (19, 5))) == ((7, -4), (1, -4), (6, 8), (-2, 7))
|
|
889 | Write a function to reverse each list in a given list of lists. | reverse_list_lists | def reverse_list_lists(lists):
for l in lists:
l.sort(reverse = True)
return lists | [
"assert reverse_list_lists([[6, 21], [33, 37]]) == [[21, 6], [37, 33]]",
"assert reverse_list_lists([[9, 23], [33, 39]]) == [[23, 9], [39, 33]]",
"assert reverse_list_lists([[14, 19], [25, 41]]) == [[19, 14], [41, 25]]"
] | def check(candidate):
# Check some simple cases
assert reverse_list_lists([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])==[[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9], [16, 15, 14, 13]]
assert reverse_list_lists([[1,2],[2,3],[3,4]])==[[2,1],[3,2],[4,3]]
assert reverse_list_lists([[10,20],[30,40]])==[[20,10],[40,30]]
|
|
890 | Write a python function to find the index of an extra element present in one sorted array. | find_Extra | def find_Extra(arr1,arr2,n) :
for i in range(0, n) :
if (arr1[i] != arr2[i]) :
return i
return n | [
"assert find_Extra([2, 1, 6, 6, 9, 16], [1, 5, 1, 4, 4], 5) == 0",
"assert find_Extra([5, 8, 5, 12, 13, 16], [5, 3, 1, 7, 7], 10) == 1",
"assert find_Extra([6, 4, 9, 3, 14, 7], [2, 6, 3, 11, 9], 6) == 0"
] | def check(candidate):
# Check some simple cases
assert find_Extra([1,2,3,4],[1,2,3],3) == 3
assert find_Extra([2,4,6,8,10],[2,4,6,8],4) == 4
assert find_Extra([1,3,5,7,9,11],[1,3,5,7,9],5) == 5
|
|
891 | Write a python function to check whether the given two numbers have same number of digits or not. | same_Length | def same_Length(A,B):
while (A > 0 and B > 0):
A = A / 10;
B = B / 10;
if (A == 0 and B == 0):
return True;
return False; | [
"assert same_Length(13, 17) == True",
"assert same_Length(11, 22) == True",
"assert same_Length(15, 20) == True"
] | def check(candidate):
# Check some simple cases
assert same_Length(12,1) == False
assert same_Length(2,2) == True
assert same_Length(10,20) == True
|
|
892 | Write a function to remove multiple spaces in a string. | remove_spaces | import re
def remove_spaces(text):
return (re.sub(' +',' ',text)) | [
"assert remove_spaces(\"duuwwgyhueohefekdfdkzosglkfmqsyomgh wj\") == \"duuwwgyhueohefekdfdkzosglkfmqsyomgh wj\"",
"assert remove_spaces(\"xtpiuidqpzw wxnanegq vcvnobfrqe\") == \"xtpiuidqpzw wxnanegq vcvnobfrqe\"",
"assert remove_spaces(\" krcbauxc adefhmihgp twwnnjner\") == \"krcbauxc adefhmihgp twwnnjner\""
] | def check(candidate):
# Check some simple cases
assert remove_spaces('python program')==('python program')
assert remove_spaces('python programming language')==('python programming language')
assert remove_spaces('python program')==('python program')
|
|
893 | Write a python function to get the last element of each sublist. | Extract | def Extract(lst):
return [item[-1] for item in lst] | [
"assert Extract([[3, 3, 3], [1, 7]]) == [3, 7]",
"assert Extract([[6, 4, 2], [5, 5]]) == [2, 5]",
"assert Extract([[1, 6, 7], [5, 9]]) == [7, 9]"
] | def check(candidate):
# Check some simple cases
assert Extract([[1, 2, 3], [4, 5], [6, 7, 8, 9]]) == [3, 5, 9]
assert Extract([['x', 'y', 'z'], ['m'], ['a', 'b'], ['u', 'v']]) == ['z', 'm', 'b', 'v']
assert Extract([[1, 2, 3], [4, 5]]) == [3, 5]
|
|
894 | Write a function to convert the given string of float type into tuple. | float_to_tuple | def float_to_tuple(test_str):
res = tuple(map(float, test_str.split(', ')))
return (res) | [
"assert float_to_tuple(\"64930187.9, 38755\") == (64930187.9, 38755.0)",
"assert float_to_tuple(\"0535592191554140.\") == (535592191554140.0,)",
"assert float_to_tuple(\"910455154.715584229167\") == (910455154.7155843,)"
] | def check(candidate):
# Check some simple cases
assert float_to_tuple("1.2, 1.3, 2.3, 2.4, 6.5") == (1.2, 1.3, 2.3, 2.4, 6.5)
assert float_to_tuple("2.3, 2.4, 5.6, 5.4, 8.9") == (2.3, 2.4, 5.6, 5.4, 8.9)
assert float_to_tuple("0.3, 0.5, 7.8, 9.4") == (0.3, 0.5, 7.8, 9.4)
|
|
895 | Write a function to find the maximum sum of subsequences of given array with no adjacent elements. | max_sum_subseq | def max_sum_subseq(A):
n = len(A)
if n == 1:
return A[0]
look_up = [None] * n
look_up[0] = A[0]
look_up[1] = max(A[0], A[1])
for i in range(2, n):
look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i])
look_up[i] = max(look_up[i], A[i])
return look_up[n - 1] | [
"assert max_sum_subseq([6, 8, 14, 3, 10, 1, 4, 10, 20]) == 54",
"assert max_sum_subseq([2, 6, 5, 2, 5, 3, 1, 12, 20]) == 33",
"assert max_sum_subseq([3, 3, 6, 5, 2, 2, 8, 15, 25]) == 44"
] | def check(candidate):
# Check some simple cases
assert max_sum_subseq([1, 2, 9, 4, 5, 0, 4, 11, 6]) == 26
assert max_sum_subseq([1, 2, 9, 5, 6, 0, 5, 12, 7]) == 28
assert max_sum_subseq([1, 3, 10, 5, 6, 0, 6, 14, 21]) == 44
|
|
896 | Write a function to sort a list in increasing order by the last element in each tuple from a given list of non-empty tuples. | sort_list_last | def last(n):
return n[-1]
def sort_list_last(tuples):
return sorted(tuples, key=last) | [
"assert sort_list_last([(20, 50), (5, 15), (42, 45)]) == [(5, 15), (42, 45), (20, 50)]",
"assert sort_list_last([(15, 49), (7, 19), (42, 45)]) == [(7, 19), (42, 45), (15, 49)]",
"assert sort_list_last([(20, 48), (5, 21), (43, 38)]) == [(5, 21), (43, 38), (20, 48)]"
] | def check(candidate):
# Check some simple cases
assert sort_list_last([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)])==[(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)]
assert sort_list_last([(9,8), (4, 7), (3,5), (7,9), (1,2)])==[(1,2), (3,5), (4,7), (9,8), (7,9)]
assert sort_list_last([(20,50), (10,20), (40,40)])==[(10,20),(40,40),(20,50)]
|
|
897 | Write a python function to check whether the word is present in a given sentence or not. | is_Word_Present | def is_Word_Present(sentence,word):
s = sentence.split(" ")
for i in s:
if (i == word):
return True
return False | [
"assert is_Word_Present('atfhugeqpvuloqe', 'xfytmgptp') == False",
"assert is_Word_Present('qwbhcewqbaacz', 'pqg') == False",
"assert is_Word_Present('fryiorkdfsxzbrt', 'abbp') == False"
] | def check(candidate):
# Check some simple cases
assert is_Word_Present("machine learning","machine") == True
assert is_Word_Present("easy","fun") == False
assert is_Word_Present("python language","code") == False
|
|
898 | Write a function to extract specified number of elements from a given list, which follow each other continuously. | extract_elements | from itertools import groupby
def extract_elements(numbers, n):
result = [i for i, j in groupby(numbers) if len(list(j)) == n]
return result | [
"assert extract_elements([2, 2, 5, 5, 5], 7) == []",
"assert extract_elements([4, 1, 2, 3, 4], 6) == []",
"assert extract_elements([4, 5, 5, 4, 2], 4) == []"
] | def check(candidate):
# Check some simple cases
assert extract_elements([1, 1, 3, 4, 4, 5, 6, 7],2)==[1, 4]
assert extract_elements([0, 1, 2, 3, 4, 4, 4, 4, 5, 7],4)==[4]
assert extract_elements([0,0,0,0,0],5)==[0]
|
|
899 | Write a python function to check whether an array can be sorted or not by picking only the corner elements. | check | def check(arr,n):
g = 0
for i in range(1,n):
if (arr[i] - arr[i - 1] > 0 and g == 1):
return False
if (arr[i] - arr[i] < 0):
g = 1
return True | [
"assert check([5, 5, 1, 4, 6, 1], 2) == True",
"assert check([1, 2, 1, 2, 7, 2], 1) == True",
"assert check([3, 4, 7, 5, 4, 5], 4) == True"
] | def check(candidate):
# Check some simple cases
assert check([3,2,1,2,3,4],6) == True
assert check([2,1,4,5,1],5) == True
assert check([1,2,2,1,2,3],6) == True
|
|
900 | Write a function where a string will start with a specific number. | match_num | import re
def match_num(string):
text = re.compile(r"^5")
if text.match(string):
return True
else:
return False | [
"assert match_num(\"198\") == False",
"assert match_num(\"6618\") == False",
"assert match_num(\"779339\") == False"
] | def check(candidate):
# Check some simple cases
assert match_num('5-2345861')==True
assert match_num('6-2345861')==False
assert match_num('78910')==False
|
Subsets and Splits