Dataset Preview Go to dataset viewer
task_id (int)text (string)code (string)test_list (json)test_setup_code (string)challenge_test_list (json)
1
Write a function to find the minimum cost path to reach (m, n) from (0, 0) for the given cost matrix cost[][] and a position (m, n) in cost[][].
R = 3 C = 3 def min_cost(cost, m, n): tc = [[0 for x in range(C)] for x in range(R)] tc[0][0] = cost[0][0] for i in range(1, m+1): tc[i][0] = tc[i-1][0] + cost[i][0] for j in range(1, n+1): tc[0][j] = tc[0][j-1] + cost[0][j] for i in range(1, m+1): for j in range(1, n+1): tc[i][j] = min(tc[i-1][j-1], tc[i-1][j], tc[i][j-1]) + cost[i][j] return tc[m][n]
[ "assert min_cost([[1, 2, 3], [4, 8, 2], [1, 5, 3]], 2, 2) == 8", "assert min_cost([[2, 3, 4], [5, 9, 3], [2, 6, 4]], 2, 2) == 12", "assert min_cost([[3, 4, 5], [6, 10, 4], [3, 7, 5]], 2, 2) == 16" ]
[]
2
Write a function to find the similar elements from the given two tuple lists.
def similar_elements(test_tup1, test_tup2): res = tuple(set(test_tup1) & set(test_tup2)) return (res)
[ "assert similar_elements((3, 4, 5, 6),(5, 7, 4, 10)) == (4, 5)", "assert similar_elements((1, 2, 3, 4),(5, 4, 3, 7)) == (3, 4)", "assert similar_elements((11, 12, 14, 13),(17, 15, 14, 13)) == (13, 14)" ]
[]
3
Write a python function to identify non-prime numbers.
import math def is_not_prime(n): result = False for i in range(2,int(math.sqrt(n)) + 1): if n % i == 0: result = True return result
[ "assert is_not_prime(2) == False", "assert is_not_prime(10) == True", "assert is_not_prime(35) == True" ]
[]
4
Write a function to find the largest integers from a given list of numbers using heap queue algorithm.
import heapq as hq def heap_queue_largest(nums,n): largest_nums = hq.nlargest(n, nums) return largest_nums
[ "assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],3)==[85, 75, 65] ", "assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],2)==[85, 75] ", "assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],5)==[85, 75, 65, 58, 35]" ]
[]
5
Write a function to find the number of ways to fill it with 2 x 1 dominoes for the given 3 x n board.
def count_ways(n): A = [0] * (n + 1) B = [0] * (n + 1) A[0] = 1 A[1] = 0 B[0] = 0 B[1] = 1 for i in range(2, n+1): A[i] = A[i - 2] + 2 * B[i - 1] B[i] = A[i - 1] + B[i - 2] return A[n]
[ "assert count_ways(2) == 3", "assert count_ways(8) == 153", "assert count_ways(12) == 2131" ]
[]
6
Write a python function to check whether the two numbers differ at one bit position only or not.
def is_Power_Of_Two (x): return x and (not(x & (x - 1))) def differ_At_One_Bit_Pos(a,b): return is_Power_Of_Two(a ^ b)
[ "assert differ_At_One_Bit_Pos(13,9) == True", "assert differ_At_One_Bit_Pos(15,8) == False", "assert differ_At_One_Bit_Pos(2,4) == False" ]
[]
7
Write a function to find all words which are at least 4 characters long in a string by using regex.
import re def find_char_long(text): return (re.findall(r"\b\w{4,}\b", text))
[ "assert find_char_long('Please move back to stream') == ['Please', 'move', 'back', 'stream']", "assert find_char_long('Jing Eco and Tech') == ['Jing', 'Tech']", "assert find_char_long('Jhingai wulu road Zone 3') == ['Jhingai', 'wulu', 'road', 'Zone']" ]
[]
8
Write a function to find squares of individual elements in a list using lambda function.
def square_nums(nums): square_nums = list(map(lambda x: x ** 2, nums)) return square_nums
[ "assert square_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]", "assert square_nums([10,20,30])==([100,400,900])", "assert square_nums([12,15])==([144,225])" ]
[]
9
Write a python function to find the minimum number of rotations required to get the same string.
def find_Rotations(str): tmp = str + str n = len(str) for i in range(1,n + 1): substring = tmp[i: i+n] if (str == substring): return i return n
[ "assert find_Rotations(\"aaaa\") == 1", "assert find_Rotations(\"ab\") == 2", "assert find_Rotations(\"abc\") == 3" ]
[]
10
Write a function to get the n smallest items from a dataset.
import heapq def small_nnum(list1,n): smallest=heapq.nsmallest(n,list1) return smallest
[ "assert small_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2)==[10,20]", "assert small_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5)==[10,20,20,40,50]", "assert small_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3)==[10,20,20]" ]
[]
11
Write a python function to remove first and last occurrence of a given character from the string.
def remove_Occ(s,ch): for i in range(len(s)): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break for i in range(len(s) - 1,-1,-1): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break return s
[ "assert remove_Occ(\"hello\",\"l\") == \"heo\"", "assert remove_Occ(\"abcda\",\"a\") == \"bcd\"", "assert remove_Occ(\"PHP\",\"P\") == \"H\"" ]
[ "assert remove_Occ(\"hellolloll\",\"l\") == \"helollol\"", "assert remove_Occ(\"\",\"l\") == \"\"" ]
12
Write a function to sort a given matrix in ascending order according to the sum of its rows.
def sort_matrix(M): result = sorted(M, key=sum) return result
[ "assert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]]", "assert sort_matrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])==[[-2, 4, -5], [1, -1, 1], [1, 2, 3]]", "assert sort_matrix([[5,8,9],[6,4,3],[2,1,4]])==[[2, 1, 4], [6, 4, 3], [5, 8, 9]]" ]
[]
13
Write a function to count the most common words in a dictionary.
from collections import Counter def count_common(words): word_counts = Counter(words) top_four = word_counts.most_common(4) return (top_four)
[ "assert count_common(['red','green','black','pink','black','white','black','eyes','white','black','orange','pink','pink','red','red','white','orange','white',\"black\",'pink','green','green','pink','green','pink','white','orange',\"orange\",'red']) == [('pink', 6), ('black', 5), ('white', 5), ('red', 4)]", "assert count_common(['one', 'two', 'three', 'four', 'five', 'one', 'two', 'one', 'three', 'one']) == [('one', 4), ('two', 2), ('three', 2), ('four', 1)]", "assert count_common(['Facebook', 'Apple', 'Amazon', 'Netflix', 'Google', 'Apple', 'Netflix', 'Amazon']) == [('Apple', 2), ('Amazon', 2), ('Netflix', 2), ('Facebook', 1)]" ]
[]
14
Write a python function to find the volume of a triangular prism.
def find_Volume(l,b,h) : return ((l * b * h) / 2)
[ "assert find_Volume(10,8,6) == 240", "assert find_Volume(3,2,2) == 6", "assert find_Volume(1,2,1) == 1" ]
[]
15
Write a function to split a string at lowercase letters.
import re def split_lowerstring(text): return (re.findall('[a-z][^a-z]*', text))
[ "assert split_lowerstring(\"AbCd\")==['bC','d']", "assert split_lowerstring(\"Python\")==['y', 't', 'h', 'o', 'n']", "assert split_lowerstring(\"Programming\")==['r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g']" ]
[]
16
Write a function to find sequences of lowercase letters joined with an underscore.
import re def text_lowercase_underscore(text): patterns = '^[a-z]+_[a-z]+$' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
[ "assert text_lowercase_underscore(\"aab_cbbbc\")==('Found a match!')", "assert text_lowercase_underscore(\"aab_Abbbc\")==('Not matched!')", "assert text_lowercase_underscore(\"Aaab_abbbc\")==('Not matched!')" ]
[ "assert text_lowercase_underscore(\"aab-cbbbc\")==('Not matched!')" ]
17
Write a function to find the perimeter of a square.
def square_perimeter(a): perimeter=4*a return perimeter
[ "assert square_perimeter(10)==40", "assert square_perimeter(5)==20", "assert square_perimeter(4)==16" ]
[]
18
Write a function to remove characters from the first string which are present in the second string.
NO_OF_CHARS = 256 def str_to_list(string): temp = [] for x in string: temp.append(x) return temp def lst_to_string(List): return ''.join(List) def get_char_count_array(string): count = [0] * NO_OF_CHARS for i in string: count[ord(i)] += 1 return count def remove_dirty_chars(string, second_string): count = get_char_count_array(second_string) ip_ind = 0 res_ind = 0 temp = '' str_list = str_to_list(string) while ip_ind != len(str_list): temp = str_list[ip_ind] if count[ord(temp)] == 0: str_list[res_ind] = str_list[ip_ind] res_ind += 1 ip_ind+=1 return lst_to_string(str_list[0:res_ind])
[ "assert remove_dirty_chars(\"probasscurve\", \"pros\") == 'bacuve'", "assert remove_dirty_chars(\"digitalindia\", \"talent\") == 'digiidi'", "assert remove_dirty_chars(\"exoticmiles\", \"toxic\") == 'emles' " ]
[]
19
Write a function to find whether a given array of integers contains any duplicate element.
def test_duplicate(arraynums): nums_set = set(arraynums) return len(arraynums) != len(nums_set)
[ "assert test_duplicate(([1,2,3,4,5]))==False", "assert test_duplicate(([1,2,3,4, 4]))==True", "assert test_duplicate([1,1,2,2,3,3,4,4,5])==True" ]
[]
20
Write a function to check if the given number is woodball or not.
def is_woodall(x): if (x % 2 == 0): return False if (x == 1): return True x = x + 1 p = 0 while (x % 2 == 0): x = x/2 p = p + 1 if (p == x): return True return False
[ "assert is_woodall(383) == True", "assert is_woodall(254) == False", "assert is_woodall(200) == False" ]
[ "assert is_woodall(32212254719) == True", "assert is_woodall(32212254718) == False", "assert is_woodall(159) == True" ]
21
Write a function to find m number of multiples of n.
def multiples_of_num(m,n): multiples_of_num= list(range(n,(m+1)*n, n)) return list(multiples_of_num)
[ "assert multiples_of_num(4,3)== [3,6,9,12]", "assert multiples_of_num(2,5)== [5,10]", "assert multiples_of_num(9,2)== [2,4,6,8,10,12,14,16,18]" ]
[]
22
Write a function to find the first duplicate element in a given array of integers.
def find_first_duplicate(nums): num_set = set() no_duplicate = -1 for i in range(len(nums)): if nums[i] in num_set: return nums[i] else: num_set.add(nums[i]) return no_duplicate
[ "assert find_first_duplicate(([1, 2, 3, 4, 4, 5]))==4", "assert find_first_duplicate([1, 2, 3, 4])==-1", "assert find_first_duplicate([1, 1, 2, 3, 3, 2, 2])==1" ]
[]
23
Write a python function to find the maximum sum of elements of list in a list of lists.
def maximum_Sum(list1): maxi = -100000 for x in list1: sum = 0 for y in x: sum+= y maxi = max(sum,maxi) return maxi
[ "assert maximum_Sum([[1,2,3],[4,5,6],[10,11,12],[7,8,9]]) == 33", "assert maximum_Sum([[0,1,1],[1,1,2],[3,2,1]]) == 6", "assert maximum_Sum([[0,1,3],[1,2,1],[9,8,2],[0,1,0],[6,4,8]]) == 19" ]
[ "assert maximum_Sum([[0,-1,-1],[-1,-1,-2],[-3,-2,-1]]) == -2" ]
24
Write a function to convert the given binary number to its decimal equivalent.
def binary_to_decimal(binary): binary1 = binary decimal, i, n = 0, 0, 0 while(binary != 0): dec = binary % 10 decimal = decimal + dec * pow(2, i) binary = binary//10 i += 1 return (decimal)
[ "assert binary_to_decimal(100) == 4", "assert binary_to_decimal(1011) == 11", "assert binary_to_decimal(1101101) == 109" ]
[]
25
Write a python function to find the product of non-repeated elements in a given array.
def find_Product(arr,n): arr.sort() prod = 1 for i in range(0,n,1): if (arr[i - 1] != arr[i]): prod = prod * arr[i] return prod;
[ "assert find_Product([1,1,2,3],4) == 6", "assert find_Product([1,2,3,1,1],5) == 6", "assert find_Product([1,1,4,5,6],5) == 120" ]
[ "assert find_Product([1,1,4,5,6,5,7,1,1,3,4],11) == 2520" ]
26
Write a function to check if the given tuple list has all k elements.
def check_k_elements(test_list, K): res = True for tup in test_list: for ele in tup: if ele != K: res = False return (res)
[ "assert check_k_elements([(4, 4), (4, 4, 4), (4, 4), (4, 4, 4, 4), (4, )], 4) == True", "assert check_k_elements([(7, 7, 7), (7, 7)], 7) == True", "assert check_k_elements([(9, 9), (9, 9, 9, 9)], 7) == False" ]
[ "assert check_k_elements([(4, 4), (4, 4, 4), (4, 4), (4, 4, 6, 4), (4, )], 4) == False" ]
27
Write a python function to remove all digits from a list of strings.
import re def remove(list): pattern = '[0-9]' list = [re.sub(pattern, '', i) for i in list] return list
[ "assert remove(['4words', '3letters', '4digits']) == ['words', 'letters', 'digits']", "assert remove(['28Jan','12Jan','11Jan']) == ['Jan','Jan','Jan']", "assert remove(['wonder1','wonder2','wonder3']) == ['wonder','wonder','wonder']" ]
[]
28
Write a python function to find binomial co-efficient.
def binomial_Coeff(n,k): if k > n : return 0 if k==0 or k ==n : return 1 return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k)
[ "assert binomial_Coeff(5,2) == 10", "assert binomial_Coeff(4,3) == 4", "assert binomial_Coeff(3,2) == 3" ]
[ "assert binomial_Coeff(14,6) == 3003" ]
29
Write a python function to find the element occurring odd number of times.
def get_Odd_Occurrence(arr,arr_size): for i in range(0,arr_size): count = 0 for j in range(0,arr_size): if arr[i] == arr[j]: count+=1 if (count % 2 != 0): return arr[i] return -1
[ "assert get_Odd_Occurrence([1,2,3,1,2,3,1],7) == 1", "assert get_Odd_Occurrence([1,2,3,2,3,1,3],7) == 3", "assert get_Odd_Occurrence([2,3,5,4,5,2,4,3,5,2,4,4,2],13) == 5" ]
[]
30
Write a python function to count all the substrings starting and ending with same characters.
def check_Equality(s): return (ord(s[0]) == ord(s[len(s) - 1])); def count_Substring_With_Equal_Ends(s): result = 0; n = len(s); for i in range(n): for j in range(1,n-i+1): if (check_Equality(s[i:i+j])): result+=1; return result;
[ "assert count_Substring_With_Equal_Ends(\"abc\") == 3", "assert count_Substring_With_Equal_Ends(\"abcda\") == 6", "assert count_Substring_With_Equal_Ends(\"ab\") == 2" ]
[]
31
Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm.
def func(nums, k): import collections d = collections.defaultdict(int) for row in nums: for i in row: d[i] += 1 temp = [] import heapq for key, v in d.items(): if len(temp) < k: temp.append((v, key)) if len(temp) == k: heapq.heapify(temp) else: if v > temp[0][0]: heapq.heappop(temp) heapq.heappush(temp, (v, key)) result = [] while temp: v, key = heapq.heappop(temp) result.append(key) return result
[ "assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],3)==[5, 7, 1]", "assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],1)==[1]", "assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],5)==[6, 5, 7, 8, 1]" ]
[]
32
Write a python function to find the largest prime factor of a given number.
import math def max_Prime_Factors (n): maxPrime = -1 while n%2 == 0: maxPrime = 2 n >>= 1 for i in range(3,int(math.sqrt(n))+1,2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime)
[ "assert max_Prime_Factors(15) == 5", "assert max_Prime_Factors(6) == 3", "assert max_Prime_Factors(2) == 2" ]
[]
33
Write a python function to convert a decimal number to binary number.
def decimal_To_Binary(N): B_Number = 0 cnt = 0 while (N != 0): rem = N % 2 c = pow(10,cnt) B_Number += rem*c N //= 2 cnt += 1 return B_Number
[ "assert decimal_To_Binary(10) == 1010", "assert decimal_To_Binary(1) == 1", "assert decimal_To_Binary(20) == 10100" ]
[]
34
Write a python function to find the missing number in a sorted array.
def find_missing(ar,N): l = 0 r = N - 1 while (l <= r): mid = (l + r) / 2 mid= int (mid) if (ar[mid] != mid + 1 and ar[mid - 1] == mid): return (mid + 1) elif (ar[mid] != mid + 1): r = mid - 1 else: l = mid + 1 return (-1)
[ "assert find_missing([1,2,3,5],4) == 4", "assert find_missing([1,3,4,5],4) == 2", "assert find_missing([1,2,3,5,6,7],5) == 4" ]
[]
35
Write a function to find the n-th rectangular number.
def find_rect_num(n): return n*(n + 1)
[ "assert find_rect_num(4) == 20", "assert find_rect_num(5) == 30", "assert find_rect_num(6) == 42" ]
[]
36
Write a python function to find the nth digit in the proper fraction of two given numbers.
def find_Nth_Digit(p,q,N) : while (N > 0) : N -= 1; p *= 10; res = p // q; p %= q; return res;
[ "assert find_Nth_Digit(1,2,1) == 5", "assert find_Nth_Digit(3,5,1) == 6", "assert find_Nth_Digit(5,6,5) == 3" ]
[]
37
Write a function to sort a given mixed list of integers and strings.
def sort_mixed_list(mixed_list): int_part = sorted([i for i in mixed_list if type(i) is int]) str_part = sorted([i for i in mixed_list if type(i) is str]) return int_part + str_part
[ "assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']", "assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']", "assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']" ]
[]
38
Write a function to find the division of first even and odd number of a given list.
def div_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el for el in list1 if el%2!=0),-1) return (first_even/first_odd)
[ "assert div_even_odd([1,3,5,7,4,1,6,8])==4", "assert div_even_odd([1,2,3,4,5,6,7,8,9,10])==2", "assert div_even_odd([1,5,7,9,10])==10" ]
[]
39
Write a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different.
import heapq from collections import Counter def rearange_string(S): ctr = Counter(S) heap = [(-value, key) for key, value in ctr.items()] heapq.heapify(heap) if (-heap[0][0]) * 2 > len(S) + 1: return "" ans = [] while len(heap) >= 2: nct1, char1 = heapq.heappop(heap) nct2, char2 = heapq.heappop(heap) ans.extend([char1, char2]) if nct1 + 1: heapq.heappush(heap, (nct1 + 1, char1)) if nct2 + 1: heapq.heappush(heap, (nct2 + 1, char2)) return "".join(ans) + (heap[0][1] if heap else "")
[ "assert rearange_string(\"aab\")==('aba')", "assert rearange_string(\"aabb\")==('abab')", "assert rearange_string(\"abccdd\")==('cdabcd')" ]
[]
40
Write a function to find frequency of the elements in a given list of lists using collections module.
from collections import Counter from itertools import chain def freq_element(nums): result = Counter(chain.from_iterable(nums)) return result
[ "assert freq_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]])==({2: 3, 1: 2, 5: 2, 3: 1, 4: 1, 6: 1, 7: 1, 9: 1})", "assert freq_element([[1,2,3,4],[5,6,7,8],[9,10,11,12]])==({1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1, 12: 1})", "assert freq_element([[15,20,30,40],[80,90,100,110],[30,30,80,90]])==({30: 3, 80: 2, 90: 2, 15: 1, 20: 1, 40: 1, 100: 1, 110: 1})" ]
[]
41
Write a function to filter even numbers using lambda function.
def filter_evennumbers(nums): even_nums = list(filter(lambda x: x%2 == 0, nums)) return even_nums
[ "assert filter_evennumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[2, 4, 6, 8, 10]", "assert filter_evennumbers([10,20,45,67,84,93])==[10,20,84]", "assert filter_evennumbers([5,7,9,8,6,4,3])==[8,6,4]" ]
[]
42
Write a python function to find the sum of repeated elements in a given array.
def find_Sum(arr,n): return sum([x for x in arr if arr.count(x) > 1])
[ "assert find_Sum([1,2,3,1,1,4,5,6],8) == 3", "assert find_Sum([1,2,3,1,1],5) == 3", "assert find_Sum([1,1,2],3) == 2" ]
[ "assert find_Sum([1,1,2,3,4,5,6,3,5],9) == 18" ]
43
Write a function to find sequences of lowercase letters joined with an underscore using regex.
import re def text_match(text): patterns = '^[a-z]+_[a-z]+$' if re.search(patterns, text): return ('Found a match!') else: return ('Not matched!')
[ "assert text_match(\"aab_cbbbc\") == 'Found a match!'", "assert text_match(\"aab_Abbbc\") == 'Not matched!'", "assert text_match(\"Aaab_abbbc\") == 'Not matched!'" ]
[ "assert text_match(\"aab-cbbbc\") == 'Not matched!'" ]
44
Write a function that matches a word at the beginning of a string.
import re def text_match_string(text): patterns = '^\w+' if re.search(patterns, text): return 'Found a match!' else: return 'Not matched!'
[ "assert text_match_string(\" python\")==('Not matched!')", "assert text_match_string(\"python\")==('Found a match!')", "assert text_match_string(\" lang\")==('Not matched!')" ]
[ "assert text_match_string(\"foo\")==('Found a match!')" ]
45
Write a function to find the gcd of the given array elements.
def find_gcd(x, y): while(y): x, y = y, x % y return x def get_gcd(l): num1 = l[0] num2 = l[1] gcd = find_gcd(num1, num2) for i in range(2, len(l)): gcd = find_gcd(gcd, l[i]) return gcd
[ "assert get_gcd([2, 4, 6, 8, 16]) == 2", "assert get_gcd([1, 2, 3]) == 1", "assert get_gcd([2, 4, 6, 8]) == 2 " ]
[]
46
Write a python function to determine whether all the numbers are different from each other are not.
def test_distinct(data): if len(data) == len(set(data)): return True else: return False;
[ "assert test_distinct([1,5,7,9]) == True", "assert test_distinct([2,4,5,5,7,9]) == False", "assert test_distinct([1,2,3]) == True" ]
[]
47
Write a python function to find the last digit when factorial of a divides factorial of b.
def compute_Last_Digit(A,B): variable = 1 if (A == B): return 1 elif ((B - A) >= 5): return 0 else: for i in range(A + 1,B + 1): variable = (variable * (i % 10)) % 10 return variable % 10
[ "assert compute_Last_Digit(2,4) == 2", "assert compute_Last_Digit(6,8) == 6", "assert compute_Last_Digit(1,2) == 2" ]
[ "assert compute_Last_Digit(3,7) == 0", "assert compute_Last_Digit(20,23) == 6", "assert compute_Last_Digit(1021,1024) == 4" ]
48
Write a python function to set all odd bits of a given number.
def odd_bit_set_number(n): count = 0;res = 0;temp = n while temp > 0: if count % 2 == 0: res |= (1 << count) count += 1 temp >>= 1 return (n | res)
[ "assert odd_bit_set_number(10) == 15", "assert odd_bit_set_number(20) == 21", "assert odd_bit_set_number(30) == 31" ]
[]
49
Write a function to extract every first or specified element from a given two-dimensional list.
def specified_element(nums, N): result = [i[N] for i in nums] return result
[ "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],0)==[1, 4, 7]", "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],2)==[3, 6, 9]", "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],1)==[2,5,1]" ]
[]
50
Write a function to find the list with minimum length using lambda function.
def min_length_list(input_list): min_length = min(len(x) for x in input_list ) min_list = min(input_list, key = lambda i: len(i)) return(min_length, min_list)
[ "assert min_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(1, [0])", "assert min_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(1,[1])", "assert min_length_list([[3,4,5],[6,7,8,9],[10,11,12],[1,2]])==(2,[1,2])" ]
[]
51
Write a function to print check if the triangle is equilateral or not.
def check_equilateral(x,y,z): if x == y == z: return True else: return False
[ "assert check_equilateral(6,8,12)==False ", "assert check_equilateral(6,6,12)==False", "assert check_equilateral(6,6,6)==True" ]
[]
52
Write a function to caluclate area of a parallelogram.
def parallelogram_area(b,h): area=b*h return area
[ "assert parallelogram_area(10,20)==200", "assert parallelogram_area(15,20)==300", "assert parallelogram_area(8,9)==72" ]
[]
53
Write a python function to check whether the first and last characters of a given string are equal or not.
def check_Equality(str): if (str[0] == str[-1]): return ("Equal") else: return ("Not Equal")
[ "assert check_Equality(\"abcda\") == \"Equal\"", "assert check_Equality(\"ab\") == \"Not Equal\"", "assert check_Equality(\"mad\") == \"Not Equal\"" ]
[]
54
Write a function to sort the given array by using counting sort.
def counting_sort(my_list): max_value = 0 for i in range(len(my_list)): if my_list[i] > max_value: max_value = my_list[i] buckets = [0] * (max_value + 1) for i in my_list: buckets[i] += 1 i = 0 for j in range(max_value + 1): for a in range(buckets[j]): my_list[i] = j i += 1 return my_list
[ "assert counting_sort([1,23,4,5,6,7,8]) == [1, 4, 5, 6, 7, 8, 23]", "assert counting_sort([12, 9, 28, 33, 69, 45]) == [9, 12, 28, 33, 45, 69]", "assert counting_sort([8, 4, 14, 3, 2, 1]) == [1, 2, 3, 4, 8, 14]" ]
[]
55
Write a function to find t-nth term of geometric series.
import math def tn_gp(a,n,r): tn = a * (math.pow(r, n - 1)) return tn
[ "assert tn_gp(1,5,2)==16", "assert tn_gp(1,5,4)==256", "assert tn_gp(2,6,3)==486" ]
[]
56
Write a python function to check if a given number is one less than twice its reverse.
def rev(num): rev_num = 0 while (num > 0): rev_num = (rev_num * 10 + num % 10) num = num // 10 return rev_num def check(n): return (2 * rev(n) == n + 1)
[ "assert check(70) == False", "assert check(23) == False", "assert check(73) == True" ]
[]
57
Write a python function to find the largest number that can be formed with the given digits.
def find_Max_Num(arr,n) : arr.sort(reverse = True) num = arr[0] for i in range(1,n) : num = num * 10 + arr[i] return num
[ "assert find_Max_Num([1,2,3],3) == 321", "assert find_Max_Num([4,5,6,1],4) == 6541", "assert find_Max_Num([1,2,3,9],4) == 9321" ]
[]
58
Write a python function to check whether the given two integers have opposite sign or not.
def opposite_Signs(x,y): return ((x ^ y) < 0);
[ "assert opposite_Signs(1,-2) == True", "assert opposite_Signs(3,2) == False", "assert opposite_Signs(-10,-10) == False" ]
[]
59
Write a function to find the nth octagonal number.
def is_octagonal(n): return 3 * n * n - 2 * n
[ "assert is_octagonal(5) == 65", "assert is_octagonal(10) == 280", "assert is_octagonal(15) == 645" ]
[]
60
Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array.
def max_len_sub( arr, n): mls=[] max = 0 for i in range(n): mls.append(1) for i in range(n): for j in range(i): if (abs(arr[i] - arr[j]) <= 1 and mls[i] < mls[j] + 1): mls[i] = mls[j] + 1 for i in range(n): if (max < mls[i]): max = mls[i] return max
[ "assert max_len_sub([2, 5, 6, 3, 7, 6, 5, 8], 8) == 5", "assert max_len_sub([-2, -1, 5, -1, 4, 0, 3], 7) == 4", "assert max_len_sub([9, 11, 13, 15, 18], 5) == 1" ]
[]
61
Write a python function to count number of substrings with the sum of digits equal to their length.
from collections import defaultdict def count_Substrings(s,n): count,sum = 0,0 mp = defaultdict(lambda : 0) mp[0] += 1 for i in range(n): sum += ord(s[i]) - ord('0') count += mp[sum - (i + 1)] mp[sum - (i + 1)] += 1 return count
[ "assert count_Substrings('112112',6) == 6", "assert count_Substrings('111',3) == 6", "assert count_Substrings('1101112',7) == 12" ]
[]
62
Write a python function to find smallest number in a list.
def smallest_num(xs): return min(xs)
[ "assert smallest_num([10, 20, 1, 45, 99]) == 1", "assert smallest_num([1, 2, 3]) == 1", "assert smallest_num([45, 46, 50, 60]) == 45" ]
[]
63
Write a function to find the maximum difference between available pairs in the given tuple list.
def max_difference(test_list): temp = [abs(b - a) for a, b in test_list] res = max(temp) return (res)
[ "assert max_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 7", "assert max_difference([(4, 6), (2, 17), (9, 13), (11, 12)]) == 15", "assert max_difference([(12, 35), (21, 27), (13, 23), (41, 22)]) == 23" ]
[]
64
Write a function to sort a list of tuples using lambda.
def subject_marks(subjectmarks): #subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]) subjectmarks.sort(key = lambda x: x[1]) return subjectmarks
[ "assert subject_marks([('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])==[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)]", "assert subject_marks([('Telugu',49),('Hindhi',54),('Social',33)])==([('Social',33),('Telugu',49),('Hindhi',54)])", "assert subject_marks([('Physics',96),('Chemistry',97),('Biology',45)])==([('Biology',45),('Physics',96),('Chemistry',97)])" ]
[]
65
Write a function of recursion list sum.
def recursive_list_sum(data_list): total = 0 for element in data_list: if type(element) == type([]): total = total + recursive_list_sum(element) else: total = total + element return total
[ "assert recursive_list_sum(([1, 2, [3,4],[5,6]]))==21", "assert recursive_list_sum(([7, 10, [15,14],[19,41]]))==106", "assert recursive_list_sum(([10, 20, [30,40],[50,60]]))==210" ]
[]
66
Write a python function to count positive numbers in a list.
def pos_count(list): pos_count= 0 for num in list: if num >= 0: pos_count += 1 return pos_count
[ "assert pos_count([1,-2,3,-4]) == 2", "assert pos_count([3,4,5,-1]) == 3", "assert pos_count([1,2,3,4]) == 4" ]
[]
67
Write a function to find the number of ways to partition a set of bell numbers.
def bell_number(n): bell = [[0 for i in range(n+1)] for j in range(n+1)] bell[0][0] = 1 for i in range(1, n+1): bell[i][0] = bell[i-1][i-1] for j in range(1, i+1): bell[i][j] = bell[i-1][j-1] + bell[i][j-1] return bell[n][0]
[ "assert bell_number(2)==2", "assert bell_number(10)==115975", "assert bell_number(56)==6775685320645824322581483068371419745979053216268760300" ]
[]
68
Write a python function to check whether the given array is monotonic or not.
def is_Monotonic(A): return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or all(A[i] >= A[i + 1] for i in range(len(A) - 1)))
[ "assert is_Monotonic([6, 5, 4, 4]) == True", "assert is_Monotonic([1, 2, 2, 3]) == True", "assert is_Monotonic([1, 3, 2]) == False" ]
[]
69
Write a function to check whether a list contains the given sublist or not.
def is_sublist(l, s): sub_set = False if s == []: sub_set = True elif s == l: sub_set = True elif len(s) > len(l): sub_set = False else: for i in range(len(l)): if l[i] == s[0]: n = 1 while (n < len(s)) and (l[i+n] == s[n]): n += 1 if n == len(s): sub_set = True return sub_set
[ "assert is_sublist([2,4,3,5,7],[3,7])==False", "assert is_sublist([2,4,3,5,7],[4,3])==True", "assert is_sublist([2,4,3,5,7],[1,6])==False" ]
[]
70
Write a function to find whether all the given tuples have equal length or not.
def find_equal_tuple(Input, k): flag = 1 for tuple in Input: if len(tuple) != k: flag = 0 break return flag def get_equal(Input, k): if find_equal_tuple(Input, k) == 1: return ("All tuples have same length") else: return ("All tuples do not have same length")
[ "assert get_equal([(11, 22, 33), (44, 55, 66)], 3) == 'All tuples have same length'", "assert get_equal([(1, 2, 3), (4, 5, 6, 7)], 3) == 'All tuples do not have same length'", "assert get_equal([(1, 2), (3, 4)], 2) == 'All tuples have same length'" ]
[]
71
Write a function to sort a list of elements using comb sort.
def comb_sort(nums): shrink_fact = 1.3 gaps = len(nums) swapped = True i = 0 while gaps > 1 or swapped: gaps = int(float(gaps) / shrink_fact) swapped = False i = 0 while gaps + i < len(nums): if nums[i] > nums[i+gaps]: nums[i], nums[i+gaps] = nums[i+gaps], nums[i] swapped = True i += 1 return nums
[ "assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79]", "assert comb_sort([41, 32, 15, 19, 22]) == [15, 19, 22, 32, 41]", "assert comb_sort([99, 15, 13, 47]) == [13, 15, 47, 99]" ]
[]
72
Write a python function to check whether the given number can be represented as difference of two squares or not.
def dif_Square(n): if (n % 4 != 2): return True return False
[ "assert dif_Square(5) == True", "assert dif_Square(10) == False", "assert dif_Square(15) == True" ]
[]
73
Write a function to split the given string with multiple delimiters by using regex.
import re def multiple_split(text): return (re.split('; |, |\*|\n',text))
[ "assert multiple_split('Forces of the \\ndarkness*are coming into the play.') == ['Forces of the ', 'darkness', 'are coming into the play.']", "assert multiple_split('Mi Box runs on the \\n Latest android*which has google assistance and chromecast.') == ['Mi Box runs on the ', ' Latest android', 'which has google assistance and chromecast.']", "assert multiple_split('Certain services\\nare subjected to change*over the seperate subscriptions.') == ['Certain services', 'are subjected to change', 'over the seperate subscriptions.']" ]
[]
74
Write a function to check whether it follows the sequence given in the patterns array.
def is_samepatterns(colors, patterns): if len(colors) != len(patterns): return False sdict = {} pset = set() sset = set() for i in range(len(patterns)): pset.add(patterns[i]) sset.add(colors[i]) if patterns[i] not in sdict.keys(): sdict[patterns[i]] = [] keys = sdict[patterns[i]] keys.append(colors[i]) sdict[patterns[i]] = keys if len(pset) != len(sset): return False for values in sdict.values(): for i in range(len(values) - 1): if values[i] != values[i+1]: return False return True
[ "assert is_samepatterns([\"red\",\"green\",\"green\"], [\"a\", \"b\", \"b\"])==True ", "assert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\",\"b\"])==False ", "assert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\"])==False " ]
[]
75
Write a function to find tuples which have all elements divisible by k from the given list of tuples.
def find_tuples(test_list, K): res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)] return (str(res))
[ "assert find_tuples([(6, 24, 12), (7, 9, 6), (12, 18, 21)], 6) == '[(6, 24, 12)]'", "assert find_tuples([(5, 25, 30), (4, 2, 3), (7, 8, 9)], 5) == '[(5, 25, 30)]'", "assert find_tuples([(7, 9, 16), (8, 16, 4), (19, 17, 18)], 4) == '[(8, 16, 4)]'" ]
[]
76
Write a python function to count the number of squares in a rectangle.
def count_Squares(m,n): if(n < m): temp = m m = n n = temp return ((m * (m + 1) * (2 * m + 1) / 6 + (n - m) * m * (m + 1) / 2))
[ "assert count_Squares(4,3) == 20", "assert count_Squares(2,2) == 5", "assert count_Squares(1,1) == 1" ]
[]
77
Write a python function to find the difference between sum of even and odd digits.
def is_Diff(n): return (n % 11 == 0)
[ "assert is_Diff (12345) == False", "assert is_Diff(1212112) == True", "assert is_Diff(1212) == False" ]
[]
78
Write a python function to find number of integers with odd number of set bits.
def count_With_Odd_SetBits(n): if (n % 2 != 0): return (n + 1) / 2 count = bin(n).count('1') ans = n / 2 if (count % 2 != 0): ans += 1 return ans
[ "assert count_With_Odd_SetBits(5) == 3", "assert count_With_Odd_SetBits(10) == 5", "assert count_With_Odd_SetBits(15) == 8" ]
[]
79
Write a python function to check whether the length of the word is odd or not.
def word_len(s): s = s.split(' ') for word in s: if len(word)%2!=0: return True else: return False
[ "assert word_len(\"Hadoop\") == False", "assert word_len(\"great\") == True", "assert word_len(\"structure\") == True" ]
[]
80
Write a function to find the nth tetrahedral number.
def tetrahedral_number(n): return (n * (n + 1) * (n + 2)) / 6
[ "assert tetrahedral_number(5) == 35.0", "assert tetrahedral_number(6) == 56.0", "assert tetrahedral_number(7) == 84.0" ]
[]
81
Write a function to zip the two given tuples.
def zip_tuples(test_tup1, test_tup2): res = [] for i, j in enumerate(test_tup1): res.append((j, test_tup2[i % len(test_tup2)])) return (res)
[ "assert zip_tuples((7, 8, 4, 5, 9, 10),(1, 5, 6) ) == [(7, 1), (8, 5), (4, 6), (5, 1), (9, 5), (10, 6)]", "assert zip_tuples((8, 9, 5, 6, 10, 11),(2, 6, 7) ) == [(8, 2), (9, 6), (5, 7), (6, 2), (10, 6), (11, 7)]", "assert zip_tuples((9, 10, 6, 7, 11, 12),(3, 7, 8) ) == [(9, 3), (10, 7), (6, 8), (7, 3), (11, 7), (12, 8)]" ]
[]
82
Write a function to find the volume of a sphere.
import math def volume_sphere(r): volume=(4/3)*math.pi*r*r*r return volume
[ "assert volume_sphere(10)==4188.790204786391", "assert volume_sphere(25)==65449.84694978735", "assert volume_sphere(20)==33510.32163829113" ]
[]
83
Write a python function to find the character made by adding all the characters of the given string.
def get_Char(strr): summ = 0 for i in range(len(strr)): summ += (ord(strr[i]) - ord('a') + 1) if (summ % 26 == 0): return ord('z') else: summ = summ % 26 return chr(ord('a') + summ - 1)
[ "assert get_Char(\"abc\") == \"f\"", "assert get_Char(\"gfg\") == \"t\"", "assert get_Char(\"ab\") == \"c\"" ]
[]
84
Write a function to find the n-th number in newman conway sequence.
def sequence(n): if n == 1 or n == 2: return 1 else: return sequence(sequence(n-1)) + sequence(n-sequence(n-1))
[ "assert sequence(10) == 6", "assert sequence(2) == 1", "assert sequence(3) == 2" ]
[]
85
Write a function to find the surface area of a sphere.
import math def surfacearea_sphere(r): surfacearea=4*math.pi*r*r return surfacearea
[ "assert surfacearea_sphere(10)==1256.6370614359173", "assert surfacearea_sphere(15)==2827.4333882308138", "assert surfacearea_sphere(20)==5026.548245743669" ]
[]
86
Write a function to find nth centered hexagonal number.
def centered_hexagonal_number(n): return 3 * n * (n - 1) + 1
[ "assert centered_hexagonal_number(10) == 271", "assert centered_hexagonal_number(2) == 7", "assert centered_hexagonal_number(9) == 217" ]
[]
87
Write a function to merge three dictionaries into a single expression.
import collections as ct def merge_dictionaries_three(dict1,dict2, dict3): merged_dict = dict(ct.ChainMap({},dict1,dict2,dict3)) return merged_dict
[ "assert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" },{ \"O\": \"Orange\", \"W\": \"White\", \"B\": \"Black\" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White', 'O': 'Orange'}", "assert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" },{\"L\":\"lavender\",\"B\":\"Blue\"})=={'W': 'White', 'P': 'Pink', 'B': 'Black', 'R': 'Red', 'G': 'Green', 'L': 'lavender'}", "assert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" },{\"L\":\"lavender\",\"B\":\"Blue\"},{ \"G\": \"Green\", \"W\": \"White\" })=={'B': 'Black', 'P': 'Pink', 'R': 'Red', 'G': 'Green', 'L': 'lavender', 'W': 'White'}" ]
[]
88
Write a function to get the frequency of the elements in a list.
import collections def freq_count(list1): freq_count= collections.Counter(list1) return freq_count
[ "assert freq_count([10,10,10,10,20,20,20,20,40,40,50,50,30])==({10: 4, 20: 4, 40: 2, 50: 2, 30: 1}) ", "assert freq_count([1,2,3,4,3,2,4,1,3,1,4])==({1:3, 2:2,3:3,4:3}) ", "assert freq_count([5,6,7,4,9,10,4,5,6,7,9,5])==({10:1,5:3,6:2,7:2,4:2,9:2}) " ]
[]
89
Write a function to find the closest smaller number than n.
def closest_num(N): return (N - 1)
[ "assert closest_num(11) == 10", "assert closest_num(7) == 6", "assert closest_num(12) == 11" ]
[]
90
Write a python function to find the length of the longest word.
def len_log(list1): max=len(list1[0]) for i in list1: if len(i)>max: max=len(i) return max
[ "assert len_log([\"python\",\"PHP\",\"bigdata\"]) == 7", "assert len_log([\"a\",\"ab\",\"abc\"]) == 3", "assert len_log([\"small\",\"big\",\"tall\"]) == 5" ]
[]
91
Write a function to check if a substring is present in a given list of string values.
def find_substring(str1, sub_str): if any(sub_str in s for s in str1): return True return False
[ "assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ack\")==True", "assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"abc\")==False", "assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ange\")==True" ]
[]
92
Write a function to check whether the given number is undulating or not.
def is_undulating(n): if (len(n) <= 2): return False for i in range(2, len(n)): if (n[i - 2] != n[i]): return False return True
[ "assert is_undulating(\"1212121\") == True", "assert is_undulating(\"1991\") == False", "assert is_undulating(\"121\") == True" ]
[]
93
Write a function to calculate the value of 'a' to the power 'b'.
def power(a,b): if b==0: return 1 elif a==0: return 0 elif b==1: return a else: return a*power(a,b-1)
[ "assert power(3,4) == 81", "assert power(2,3) == 8", "assert power(5,5) == 3125" ]
[]
94
Write a function to extract the index minimum value record from the given tuples.
from operator import itemgetter def index_minimum(test_list): res = min(test_list, key = itemgetter(1))[0] return (res)
[ "assert index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]) == 'Varsha'", "assert index_minimum([('Yash', 185), ('Dawood', 125), ('Sanya', 175)]) == 'Dawood'", "assert index_minimum([('Sai', 345), ('Salman', 145), ('Ayesha', 96)]) == 'Ayesha'" ]
[]
95
Write a python function to find the minimum length of sublist.
def Find_Min_Length(lst): minLength = min(len(x) for x in lst ) return minLength
[ "assert Find_Min_Length([[1],[1,2]]) == 1", "assert Find_Min_Length([[1,2],[1,2,3],[1,2,3,4]]) == 2", "assert Find_Min_Length([[3,3,3],[4,4,4,4]]) == 3" ]
[]
96
Write a python function to find the number of divisors of a given integer.
def divisor(n): for i in range(n): x = len([i for i in range(1,n+1) if not n % i]) return x
[ "assert divisor(15) == 4 ", "assert divisor(12) == 6", "assert divisor(9) == 3" ]
[]
97
Write a function to find frequency count of list of lists.
def frequency_lists(list1): list1 = [item for sublist in list1 for item in sublist] dic_data = {} for num in list1: if num in dic_data.keys(): dic_data[num] += 1 else: key = num value = 1 dic_data[key] = value return dic_data
[ "assert frequency_lists([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]])=={1: 1, 2: 3, 3: 1, 4: 1, 5: 2, 6: 1, 7: 1, 8: 1, 9: 1}", "assert frequency_lists([[1,2,3,4],[5,6,7,8],[9,10,11,12]])=={1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1,10:1,11:1,12:1}", "assert frequency_lists([[20,30,40,17],[18,16,14,13],[10,20,30,40]])=={20:2,30:2,40:2,17: 1,18:1, 16: 1,14: 1,13: 1, 10: 1}" ]
[]
98
Write a function to multiply all the numbers in a list and divide with the length of the list.
def multiply_num(numbers): total = 1 for x in numbers: total *= x return total/len(numbers)
[ "assert multiply_num((8, 2, 3, -1, 7))==-67.2", "assert multiply_num((-10,-20,-30))==-2000.0", "assert multiply_num((19,15,18))==1710.0" ]
[]
99
Write a function to convert the given decimal number to its binary equivalent.
def decimal_to_binary(n): return bin(n).replace("0b","")
[ "assert decimal_to_binary(8) == '1000'", "assert decimal_to_binary(18) == '10010'", "assert decimal_to_binary(7) == '111' " ]
[]
100
Write a function to find the next smallest palindrome of a specified number.
import sys def next_smallest_palindrome(num): numstr = str(num) for i in range(num+1,sys.maxsize): if str(i) == str(i)[::-1]: return i
[ "assert next_smallest_palindrome(99)==101", "assert next_smallest_palindrome(1221)==1331", "assert next_smallest_palindrome(120)==121" ]
[]
End of preview (truncated to 100 rows)

Dataset Card for Mostly Basic Python Problems (mbpp)

Dataset Summary

The benchmark consists of around 1,000 crowd-sourced Python programming problems, designed to be solvable by entry level programmers, covering programming fundamentals, standard library functionality, and so on. Each problem consists of a task description, code solution and 3 automated test cases. As described in the paper, a subset of the data has been hand-verified by us.

Released here as part of Program Synthesis with Large Language Models, Austin et. al., 2021.

Supported Tasks and Leaderboards

This dataset is used to evaluate code generations.

Languages

English - Python code

Dataset Structure

dataset_full = load_dataset("mbpp")
DatasetDict({
    test: Dataset({
        features: ['task_id', 'text', 'code', 'test_list', 'test_setup_code', 'challenge_test_list'],
        num_rows: 974
    })
})

dataset_sanitized = load_dataset("mbpp", "sanitized")
DatasetDict({
    test: Dataset({
        features: ['source_file', 'task_id', 'prompt', 'code', 'test_imports', 'test_list'],
        num_rows: 427
    })
})

Data Instances

mbpp - full

{
    'task_id': 1,
    'text': 'Write a function to find the minimum cost path to reach (m, n) from (0, 0) for the given cost matrix cost[][] and a position (m, n) in cost[][].',
    'code': 'R = 3\r\nC = 3\r\ndef min_cost(cost, m, n): \r\n\ttc = [[0 for x in range(C)] for x in range(R)] \r\n\ttc[0][0] = cost[0][0] \r\n\tfor i in range(1, m+1): \r\n\t\ttc[i][0] = tc[i-1][0] + cost[i][0] \r\n\tfor j in range(1, n+1): \r\n\t\ttc[0][j] = tc[0][j-1] + cost[0][j] \r\n\tfor i in range(1, m+1): \r\n\t\tfor j in range(1, n+1): \r\n\t\t\ttc[i][j] = min(tc[i-1][j-1], tc[i-1][j], tc[i][j-1]) + cost[i][j] \r\n\treturn tc[m][n]',
    'test_list': [
        'assert min_cost([[1, 2, 3], [4, 8, 2], [1, 5, 3]], 2, 2) == 8',
        'assert min_cost([[2, 3, 4], [5, 9, 3], [2, 6, 4]], 2, 2) == 12',
        'assert min_cost([[3, 4, 5], [6, 10, 4], [3, 7, 5]], 2, 2) == 16'],
    'test_setup_code': '',
    'challenge_test_list': []
}

mbpp - sanitized

{
    'source_file': 'Benchmark Questions Verification V2.ipynb',
    'task_id': 2,
    'prompt': 'Write a function to find the shared elements from the given two lists.',
    'code': 'def similar_elements(test_tup1, test_tup2):\n  res = tuple(set(test_tup1) & set(test_tup2))\n  return (res) ',
    'test_imports': [],
    'test_list': [
        'assert set(similar_elements((3, 4, 5, 6),(5, 7, 4, 10))) == set((4, 5))',
        'assert set(similar_elements((1, 2, 3, 4),(5, 4, 3, 7))) == set((3, 4))',
        'assert set(similar_elements((11, 12, 14, 13),(17, 15, 14, 13))) == set((13, 14))'
        ]
}

Data Fields

  • source_file: unknown
  • text/prompt: description of programming task
  • code: solution for programming task
  • test_setup_code/test_imports: necessary code imports to execute tests
  • test_list: list of tests to verify solution
  • challenge_test_list: list of more challenging test to further probe solution

Data Splits

There are two version of the dataset (full and sanitized) which only one split each (test).

Dataset Creation

See section 2.1 of original paper.

Curation Rationale

In order to evaluate code generation functions a set of simple programming tasks as well as solutions is necessary which this dataset provides.

Source Data

Initial Data Collection and Normalization

The dataset was manually created from scratch.

Who are the source language producers?

The dataset was created with an internal crowdsourcing effort at Google.

Annotations

Annotation process

The full dataset was created first and a subset then underwent a second round to improve the task descriptions.

Who are the annotators?

The dataset was created with an internal crowdsourcing effort at Google.

Personal and Sensitive Information

None.

Considerations for Using the Data

Make sure you execute generated Python code in a safe environment when evauating against this dataset as generated code could be harmful.

Social Impact of Dataset

With this dataset code generating models can be better evaluated which leads to fewer issues introduced when using such models.

Discussion of Biases

Other Known Limitations

Since the task descriptions might not be expressive enough to solve the task. The sanitized split aims at addressing this issue by having a second round of annotators improve the dataset.

Additional Information

Dataset Curators

Google Research

Licensing Information

CC-BY-4.0

Citation Information

@article{austin2021program,
  title={Program Synthesis with Large Language Models},
  author={Austin, Jacob and Odena, Augustus and Nye, Maxwell and Bosma, Maarten and Michalewski, Henryk and Dohan, David and Jiang, Ellen and Cai, Carrie and Terry, Michael and Le, Quoc and others},
  journal={arXiv preprint arXiv:2108.07732},
  year={2021}

Contributions

Thanks to @lvwerra for adding this dataset.

Update on GitHub