source_file string | task_id int64 | prompt string | code string | test_imports list | test_list list |
|---|---|---|---|---|---|
Ellen's Copy of Benchmark Questions Verification V2.ipynb | 300 | Write a function to find the count of all binary sequences of length 2n such that sum of first n bits is same as sum of last n bits. | def count_binary_seq(n):
nCr = 1
res = 1
for r in range(1, n + 1):
nCr = (nCr * (n + 1 - r)) / r
res += nCr * nCr
return res | [
"import math"
] | [
"assert math.isclose(count_binary_seq(1), 2.0, rel_tol=0.001)",
"assert math.isclose(count_binary_seq(2), 6.0, rel_tol=0.001)",
"assert math.isclose(count_binary_seq(3), 20.0, rel_tol=0.001)"
] |
Benchmark Questions Verification V2.ipynb | 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):... | [] | [
"assert remove_dirty_chars(\"probasscurve\", \"pros\") == 'bacuve'",
"assert remove_dirty_chars(\"digitalindia\", \"talent\") == 'digiidi'",
"assert remove_dirty_chars(\"exoticmiles\", \"toxic\") == 'emles'"
] |
Benchmark Questions Verification V2.ipynb | 400 | Write a function to extract the number of unique tuples in the given list. | def extract_freq(test_list):
res = len(list(set(tuple(sorted(sub)) for sub in test_list)))
return (res) | [] | [
"assert extract_freq([(3, 4), (1, 2), (4, 3), (5, 6)] ) == 3",
"assert extract_freq([(4, 15), (2, 3), (5, 4), (6, 7)] ) == 4",
"assert extract_freq([(5, 16), (2, 3), (6, 5), (6, 9)] ) == 4"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb | 309 | Write a python function to find the maximum of two numbers. | def maximum(a,b):
if a >= b:
return a
else:
return b | [] | [
"assert maximum(5,10) == 10",
"assert maximum(-1,-2) == -1",
"assert maximum(9,7) == 9"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb | 301 | Write a function to find the depth of a dictionary. | def dict_depth(d):
if isinstance(d, dict):
return 1 + (max(map(dict_depth, d.values())) if d else 0)
return 0 | [] | [
"assert dict_depth({'a':1, 'b': {'c': {'d': {}}}})==4",
"assert dict_depth({'a':1, 'b': {'c':'python'}})==2",
"assert dict_depth({1: 'Sun', 2: {3: {4:'Mon'}}})==3"
] |
Benchmark Questions Verification V2.ipynb | 234 | Write a function to find the volume of a cube given its side length. | def volume_cube(l):
volume = l * l * l
return volume | [] | [
"assert volume_cube(3)==27",
"assert volume_cube(2)==8",
"assert volume_cube(5)==125"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb | 307 | Write a function to get a colon of a tuple. | from copy import deepcopy
def colon_tuplex(tuplex,m,n):
tuplex_colon = deepcopy(tuplex)
tuplex_colon[m].append(n)
return tuplex_colon | [] | [
"assert colon_tuplex((\"HELLO\", 5, [], True) ,2,50)==(\"HELLO\", 5, [50], True)",
"assert colon_tuplex((\"HELLO\", 5, [], True) ,2,100)==((\"HELLO\", 5, [100],True))",
"assert colon_tuplex((\"HELLO\", 5, [], True) ,2,500)==(\"HELLO\", 5, [500], True)"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 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"
] |
Benchmark Questions Verification V2.ipynb | 248 | Write a function that takes in an integer n and calculates the harmonic sum of n-1. | def harmonic_sum(n):
if n < 2:
return 1
else:
return 1 / n + (harmonic_sum(n - 1)) | [
"import math"
] | [
"assert math.isclose(harmonic_sum(7), 2.5928571428571425, rel_tol=0.001)",
"assert math.isclose(harmonic_sum(4), 2.083333333333333, rel_tol=0.001)",
"assert math.isclose(harmonic_sum(19), 3.547739657143682, rel_tol=0.001)"
] |
Benchmark Questions Verification V2.ipynb | 238 | Write a python function to count the number of non-empty substrings of a given string. | def number_of_substrings(str):
str_len = len(str);
return int(str_len * (str_len + 1) / 2); | [] | [
"assert number_of_substrings(\"abc\") == 6",
"assert number_of_substrings(\"abcd\") == 10",
"assert number_of_substrings(\"abcde\") == 15"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 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 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)]"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 433 | Write a function to check whether the entered number is greater than the elements of the given array. | def check_greater(arr, number):
arr.sort()
return number > arr[-1] | [] | [
"assert check_greater([1, 2, 3, 4, 5], 4) == False",
"assert check_greater([2, 3, 4, 5, 6], 8) == True",
"assert check_greater([9, 7, 4, 8, 6, 1], 11) == True"
] |
Benchmark Questions Verification V2.ipynb | 391 | Write a function to convert more than one list to nested dictionary. | def convert_list_dictionary(l1, l2, l3):
result = [{x: {y: z}} for (x, y, z) in zip(l1, l2, l3)]
return result | [] | [
"assert convert_list_dictionary([\"S001\", \"S002\", \"S003\", \"S004\"],[\"Adina Park\", \"Leyton Marsh\", \"Duncan Boyle\", \"Saim Richards\"] ,[85, 98, 89, 92])==[{'S001': {'Adina Park': 85}}, {'S002': {'Leyton Marsh': 98}}, {'S003': {'Duncan Boyle': 89}}, {'S004': {'Saim Richards': 92}}]",
"assert convert_lis... |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 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"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 106 | Write a function to append the given list to the given tuples. | def add_lists(test_list, test_tup):
res = tuple(list(test_tup) + test_list)
return (res) | [] | [
"assert add_lists([5, 6, 7], (9, 10)) == (9, 10, 5, 6, 7)",
"assert add_lists([6, 7, 8], (10, 11)) == (10, 11, 6, 7, 8)",
"assert add_lists([7, 8, 9], (11, 12)) == (11, 12, 7, 8, 9)"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 419 | Write a function to round every number of a given list of numbers and print the total sum multiplied by the length of the list. | def round_and_sum(list1):
lenght=len(list1)
round_and_sum=sum(list(map(round,list1))* lenght)
return round_and_sum | [] | [
"assert round_and_sum([22.4, 4.0, -16.22, -9.10, 11.00, -12.22, 14.20, -5.20, 17.50])==243",
"assert round_and_sum([5,2,9,24.3,29])==345",
"assert round_and_sum([25.0,56.7,89.2])==513"
] |
Benchmark Questions Verification V2.ipynb | 229 | Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved. | def re_arrange_array(arr, n):
j=0
for i in range(0, n):
if (arr[i] < 0):
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
j = j + 1
return arr | [] | [
"assert re_arrange_array([-1, 2, -3, 4, 5, 6, -7, 8, 9], 9) == [-1, -3, -7, 4, 5, 6, 2, 8, 9]",
"assert re_arrange_array([12, -14, -26, 13, 15], 5) == [-14, -26, 12, 13, 15]",
"assert re_arrange_array([10, 24, 36, -42, -39, -78, 85], 7) == [-42, -39, -78, 10, 24, 36, 85]"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 468 | Write a function to find the maximum product formed by multiplying numbers of an increasing subsequence of that array. | def max_product(arr):
n = len(arr)
mpis = arr[:]
for i in range(n):
current_prod = arr[i]
j = i + 1
while j < n:
if arr[j-1] > arr[j]:
break
current_prod *= arr[j]
if current_prod > mpis[j]:
mpis[j] = current_prod
j = j + 1
return max(mpis) | [] | [
"assert max_product([3, 100, 4, 5, 150, 6]) == 3000",
"assert max_product([4, 42, 55, 68, 80]) == 50265600",
"assert max_product([10, 22, 9, 33, 21, 50, 41, 60]) == 2460"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 478 | Write a function to remove lowercase substrings from a given string. | import re
def remove_lowercase(str1):
return re.sub('[a-z]', '', str1) | [] | [
"assert remove_lowercase(\"PYTHon\")==('PYTH')",
"assert remove_lowercase(\"FInD\")==('FID')",
"assert remove_lowercase(\"STRinG\")==('STRG')"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 413 | Write a function to extract the nth element from a given list of tuples. | def extract_nth_element(list1, n):
result = [x[n] for x in list1]
return result | [] | [
"assert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,0)==['Greyson Fulton', 'Brady Kent', 'Wyatt Knott', 'Beau Turnbull']",
"assert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('B... |
charlessutton@: Benchmark Questions Verification V2.ipynb | 435 | Write a python function to find the last digit of a given number. | def last_Digit(n) :
return (n % 10) | [] | [
"assert last_Digit(123) == 3",
"assert last_Digit(25) == 5",
"assert last_Digit(30) == 0"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb | 294 | Write a function to find the maximum value in a given heterogeneous list. | def max_val(listval):
max_val = max(i for i in listval if isinstance(i, int))
return(max_val) | [] | [
"assert max_val(['Python', 3, 2, 4, 5, 'version'])==5",
"assert max_val(['Python', 15, 20, 25])==25",
"assert max_val(['Python', 30, 20, 40, 50, 'version'])==50"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 104 | Write a function to sort each sublist of strings in a given list of lists. | def sort_sublists(input_list):
result = [sorted(x, key = lambda x:x[0]) for x in input_list]
return result
| [] | [
"assert sort_sublists(([\"green\", \"orange\"], [\"black\", \"white\"], [\"white\", \"black\", \"orange\"]))==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]",
"assert sort_sublists(([\" red \",\"green\" ],[\"blue \",\" black\"],[\" orange\",\"brown\"]))==[[' red ', 'green'], [' black', 'b... |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 138 | Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not. | def is_Sum_Of_Powers_Of_Two(n):
if (n % 2 == 1):
return False
else:
return True | [] | [
"assert is_Sum_Of_Powers_Of_Two(10) == True",
"assert is_Sum_Of_Powers_Of_Two(7) == False",
"assert is_Sum_Of_Powers_Of_Two(14) == True"
] |
Benchmark Questions Verification V2.ipynb | 389 | Write a function to find the n'th lucas number. | def find_lucas(n):
if (n == 0):
return 2
if (n == 1):
return 1
return find_lucas(n - 1) + find_lucas(n - 2) | [] | [
"assert find_lucas(9) == 76",
"assert find_lucas(4) == 7",
"assert find_lucas(3) == 4"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 452 | Write a function that gives loss amount on a sale if the given amount has loss else return 0. | def loss_amount(actual_cost,sale_amount):
if(sale_amount > actual_cost):
amount = sale_amount - actual_cost
return amount
else:
return 0 | [] | [
"assert loss_amount(1500,1200)==0",
"assert loss_amount(100,200)==100",
"assert loss_amount(2000,5000)==3000"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 463 | Write a function to find the maximum product subarray of the given array. | def max_subarray_product(arr):
n = len(arr)
max_ending_here = 1
min_ending_here = 1
max_so_far = 0
flag = 0
for i in range(0, n):
if arr[i] > 0:
max_ending_here = max_ending_here * arr[i]
min_ending_here = min (min_ending_here * arr[i], 1)
flag = 1
elif arr[i] == 0:
max_ending_here = 1
min_endi... | [] | [
"assert max_subarray_product([1, -2, -3, 0, 7, -8, -2]) == 112",
"assert max_subarray_product([6, -3, -10, 0, 2]) == 180",
"assert max_subarray_product([-2, -40, 0, -2, -3]) == 80"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 83 | Write a python function to find the character made by adding the ASCII value of all the characters of the given string modulo 26. | 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\""
] |
Benchmark Questions Verification V2.ipynb | 264 | Write a function to calculate a dog's age in dog's years. | def dog_age(h_age):
if h_age < 0:
exit()
elif h_age <= 2:
d_age = h_age * 10.5
else:
d_age = 21 + (h_age - 2)*4
return d_age | [] | [
"assert dog_age(12)==61",
"assert dog_age(15)==73",
"assert dog_age(24)==109"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 123 | Write a function to sum all amicable numbers from 1 to a specified number. | def amicable_numbers_sum(limit):
if not isinstance(limit, int):
return "Input is not an integer!"
if limit < 1:
return "Input must be bigger than 0!"
amicables = set()
for num in range(2, limit+1):
if num in amicables:
continue
sum_fact = sum([fact for fact in... | [] | [
"assert amicable_numbers_sum(999)==504",
"assert amicable_numbers_sum(9999)==31626",
"assert amicable_numbers_sum(99)==0"
] |
Benchmark Questions Verification V2.ipynb | 287 | Write a python function takes in an integer n and returns the sum of squares of first n even natural numbers. | def square_Sum(n):
return int(2*n*(n+1)*(2*n+1)/3) | [] | [
"assert square_Sum(2) == 20",
"assert square_Sum(3) == 56",
"assert square_Sum(4) == 120"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 396 | Write a function to check whether the given string starts and ends with the same character or not. | import re
regex = r'^[a-z]$|^([a-z]).*\1$'
def check_char(string):
if(re.search(regex, string)):
return "Valid"
else:
return "Invalid" | [] | [
"assert check_char(\"abba\") == \"Valid\"",
"assert check_char(\"a\") == \"Valid\"",
"assert check_char(\"abcd\") == \"Invalid\""
] |
Benchmark Questions Verification V2.ipynb | 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\""
] |
Benchmark Questions Verification V2.ipynb | 404 | Write a python function to find the minimum of two numbers. | def minimum(a,b):
if a <= b:
return a
else:
return b | [] | [
"assert minimum(1,2) == 1",
"assert minimum(-5,-4) == -5",
"assert minimum(0,0) == 0"
] |
Benchmark Questions Verification V2.ipynb | 401 | Write a function to perform index wise addition of tuple elements in the given two nested tuples. | def add_nested_tuples(test_tup1, test_tup2):
res = tuple(tuple(a + b for a, b in zip(tup1, tup2))
for tup1, tup2 in zip(test_tup1, test_tup2))
return (res) | [] | [
"assert add_nested_tuples(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((7, 10), (7, 14), (3, 10), (8, 13))",
"assert add_nested_tuples(((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))) == ((9, 12), (9, 16), (5, 12), (10, 15))",
"assert add_nested_tuples(((3, 5), ... |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 128 | Write a function to find words that are longer than n characters from a given list of words. | def long_words(n, str):
word_len = []
txt = str.split(" ")
for x in txt:
if len(x) > n:
word_len.append(x)
return word_len | [] | [
"assert long_words(3,\"python is a programming language\")==['python','programming','language']",
"assert long_words(2,\"writing a program\")==['writing','program']",
"assert long_words(5,\"sorting list\")==['sorting']"
] |
Benchmark Questions Verification V2.ipynb | 409 | Write a function to find the minimum product from the pairs of tuples within a given list. | def min_product_tuple(list1):
result_min = min([abs(x * y) for x, y in list1] )
return result_min | [] | [
"assert min_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==8",
"assert min_product_tuple([(10,20), (15,2), (5,10)] )==30",
"assert min_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==100"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 438 | Write a function to count bidirectional tuple pairs. | def count_bidirectional(test_list):
res = 0
for idx in range(0, len(test_list)):
for iidx in range(idx + 1, len(test_list)):
if test_list[iidx][0] == test_list[idx][1] and test_list[idx][1] == test_list[iidx][0]:
res += 1
return res | [] | [
"assert count_bidirectional([(5, 6), (1, 2), (6, 5), (9, 1), (6, 5), (2, 1)] ) == 3",
"assert count_bidirectional([(5, 6), (1, 3), (6, 5), (9, 1), (6, 5), (2, 1)] ) == 2",
"assert count_bidirectional([(5, 6), (1, 2), (6, 5), (9, 2), (6, 5), (2, 1)] ) == 4"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 65 | Write a function to flatten a list and sum all of its elements. | 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"
] |
Benchmark Questions Verification V2.ipynb | 408 | Write a function to find k number of smallest pairs which consist of one element from the first array and one element from the second array. | import heapq
def k_smallest_pairs(nums1, nums2, k):
queue = []
def push(i, j):
if i < len(nums1) and j < len(nums2):
heapq.heappush(queue, [nums1[i] + nums2[j], i, j])
push(0, 0)
pairs = []
while queue and len(pairs) < k:
_, i, j = heapq.heappop(queue)
pairs.append([nums1[... | [] | [
"assert k_smallest_pairs([1,3,7],[2,4,6],2)==[[1, 2], [1, 4]]",
"assert k_smallest_pairs([1,3,7],[2,4,6],1)==[[1, 2]]",
"assert k_smallest_pairs([1,3,7],[2,4,6],7)==[[1, 2], [1, 4], [3, 2], [1, 6], [3, 4], [3, 6], [7, 2]]"
] |
Benchmark Questions Verification V2.ipynb | 390 | Write a function to apply a given format string to all of the elements in a list. | def add_string(list_, string):
add_string=[string.format(i) for i in list_]
return add_string | [] | [
"assert add_string([1,2,3,4],'temp{0}')==['temp1', 'temp2', 'temp3', 'temp4']",
"assert add_string(['a','b','c','d'], 'python{0}')==[ 'pythona', 'pythonb', 'pythonc', 'pythond']",
"assert add_string([5,6,7,8],'string{0}')==['string5', 'string6', 'string7', 'string8']"
] |
Benchmark Questions Verification V2.ipynb | 397 | Write a function to find the median of three numbers. | def median_numbers(a,b,c):
if a > b:
if a < c:
median = a
elif b > c:
median = b
else:
median = c
else:
if a > c:
median = a
elif b < c:
median = b
else:
median = c
return median | [] | [
"assert median_numbers(25,55,65)==55.0",
"assert median_numbers(20,10,30)==20.0",
"assert median_numbers(15,45,75)==45.0"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb | 304 | Write a python function to find element at a given index after number of rotations. | def find_Element(arr,ranges,rotations,index) :
for i in range(rotations - 1,-1,-1 ) :
left = ranges[i][0]
right = ranges[i][1]
if (left <= index and right >= index) :
if (index == left) :
index = right
else :
index = index - 1 ... | [] | [
"assert find_Element([1,2,3,4,5],[[0,2],[0,3]],2,1) == 3",
"assert find_Element([1,2,3,4],[[0,1],[0,2]],1,2) == 3",
"assert find_Element([1,2,3,4,5,6],[[0,1],[0,2]],1,1) == 1"
] |
Benchmark Questions Verification V2.ipynb | 161 | Write a function to remove all elements from a given list present in another list. | def remove_elements(list1, list2):
result = [x for x in list1 if x not in list2]
return result | [] | [
"assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 4, 6, 8]) == [1, 3, 5, 7, 9, 10]",
"assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 3, 5, 7]) == [2, 4, 6, 8, 9, 10]",
"assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [5, 7]) == [1, 2, 3, 4, 6, 8, 9, 10]"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 445 | Write a function to perform index wise multiplication of tuple elements in the given two tuples. | def index_multiplication(test_tup1, test_tup2):
res = tuple(tuple(a * b for a, b in zip(tup1, tup2))
for tup1, tup2 in zip(test_tup1, test_tup2))
return (res) | [] | [
"assert index_multiplication(((1, 3), (4, 5), (2, 9), (1, 10)),((6, 7), (3, 9), (1, 1), (7, 3)) ) == ((6, 21), (12, 45), (2, 9), (7, 30))",
"assert index_multiplication(((2, 4), (5, 6), (3, 10), (2, 11)),((7, 8), (4, 10), (2, 2), (8, 4)) ) == ((14, 32), (20, 60), (6, 20), (16, 44))",
"assert index_multiplicatio... |
charlessutton@: Benchmark Questions Verification V2.ipynb | 470 | Write a function to find the pairwise addition of the neighboring elements of the given tuple. | def add_pairwise(test_tup):
res = tuple(i + j for i, j in zip(test_tup, test_tup[1:]))
return (res) | [] | [
"assert add_pairwise((1, 5, 7, 8, 10)) == (6, 12, 15, 18)",
"assert add_pairwise((2, 6, 8, 9, 11)) == (8, 14, 17, 20)",
"assert add_pairwise((3, 7, 9, 10, 12)) == (10, 16, 19, 22)"
] |
Benchmark Questions Verification V2.ipynb | 228 | Write a python function to check whether all the bits are unset in the given range or not. | def all_Bits_Set_In_The_Given_Range(n,l,r):
num = (((1 << r) - 1) ^ ((1 << (l - 1)) - 1))
new_num = n & num
if (new_num == 0):
return True
return False | [] | [
"assert all_Bits_Set_In_The_Given_Range(4,1,2) == True",
"assert all_Bits_Set_In_The_Given_Range(17,2,4) == True",
"assert all_Bits_Set_In_The_Given_Range(39,4,6) == False"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 427 | Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format. | import re
def change_date_format(dt):
return re.sub(r'(\d{4})-(\d{1,2})-(\d{1,2})', '\\3-\\2-\\1', dt) | [] | [
"assert change_date_format(\"2026-01-02\") == '02-01-2026'",
"assert change_date_format(\"2020-11-13\") == '13-11-2020'",
"assert change_date_format(\"2021-04-26\") == '26-04-2021'"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 430 | Write a function to find the directrix of a parabola. | def parabola_directrix(a, b, c):
directrix=((int)(c - ((b * b) + 1) * 4 * a ))
return directrix | [] | [
"assert parabola_directrix(5,3,2)==-198",
"assert parabola_directrix(9,8,4)==-2336",
"assert parabola_directrix(2,4,6)==-130"
] |
Benchmark Questions Verification V2.ipynb | 268 | Write a function to find the n'th star number. | def find_star_num(n):
return (6 * n * (n - 1) + 1) | [] | [
"assert find_star_num(3) == 37",
"assert find_star_num(4) == 73",
"assert find_star_num(5) == 121"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 473 | Write a function to find the tuple intersection of elements in the given tuple list irrespective of their order. | def tuple_intersection(test_list1, test_list2):
res = set([tuple(sorted(ele)) for ele in test_list1]) & set([tuple(sorted(ele)) for ele in test_list2])
return (res) | [] | [
"assert tuple_intersection([(3, 4), (5, 6), (9, 10), (4, 5)] , [(5, 4), (3, 4), (6, 5), (9, 11)]) == {(4, 5), (3, 4), (5, 6)}",
"assert tuple_intersection([(4, 1), (7, 4), (11, 13), (17, 14)] , [(1, 4), (7, 4), (16, 12), (10, 13)]) == {(4, 7), (1, 4)}",
"assert tuple_intersection([(2, 1), (3, 2), (1, 3), (1, 4)... |
charlessutton@: Benchmark Questions Verification V2.ipynb | 462 | Write a function to find all possible combinations of the elements of a given list. | def combinations_list(list1):
if len(list1) == 0:
return [[]]
result = []
for el in combinations_list(list1[1:]):
result += [el, el+[list1[0]]]
return result | [] | [
"assert combinations_list(['orange', 'red', 'green', 'blue'])==[[], ['orange'], ['red'], ['red', 'orange'], ['green'], ['green', 'orange'], ['green', 'red'], ['green', 'red', 'orange'], ['blue'], ['blue', 'orange'], ['blue', 'red'], ['blue', 'red', 'orange'], ['blue', 'green'], ['blue', 'green', 'orange'], ['blue',... |
Benchmark Questions Verification V2.ipynb | 16 | Write a function to that returns true if the input string contains sequences of lowercase letters joined with an underscore and false otherwise. | import re
def text_lowercase_underscore(text):
patterns = '^[a-z]+_[a-z]+$'
if re.search(patterns, text):
return True
else:
return False | [] | [
"assert text_lowercase_underscore(\"aab_cbbbc\")==(True)",
"assert text_lowercase_underscore(\"aab_Abbbc\")==(False)",
"assert text_lowercase_underscore(\"Aaab_abbbc\")==(False)"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 459 | Write a function to remove uppercase substrings from a given string. | import re
def remove_uppercase(str1):
return re.sub('[A-Z]', '', str1) | [] | [
"assert remove_uppercase('cAstyoUrFavoRitETVshoWs') == 'cstyoravoitshos'",
"assert remove_uppercase('wAtchTheinTernEtrAdIo') == 'wtchheinerntrdo'",
"assert remove_uppercase('VoicESeaRchAndreComMendaTionS') == 'oiceachndreomendaion'"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb | 310 | Write a function to convert a given string to a tuple of characters. | def string_to_tuple(str1):
result = tuple(x for x in str1 if not x.isspace())
return result | [] | [
"assert string_to_tuple(\"python 3.0\")==('p', 'y', 't', 'h', 'o', 'n', '3', '.', '0')",
"assert string_to_tuple(\"item1\")==('i', 't', 'e', 'm', '1')",
"assert string_to_tuple(\"15.10\")==('1', '5', '.', '1', '0')"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 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"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 131 | Write a python function to reverse only the vowels of a given string (where y is not a vowel). | def reverse_vowels(str1):
vowels = ""
for char in str1:
if char in "aeiouAEIOU":
vowels += char
result_string = ""
for char in str1:
if char in "aeiouAEIOU":
result_string += vowels[-1]
vowels = vowels[:-1]
else:
result_string += char
return result_string | [] | [
"assert reverse_vowels(\"Python\") == \"Python\"",
"assert reverse_vowels(\"USA\") == \"ASU\"",
"assert reverse_vowels(\"ab\") == \"ab\""
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 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"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 115 | Write a function to check whether all dictionaries in a list are empty or not. | def empty_dit(list1):
empty_dit=all(not d for d in list1)
return empty_dit | [] | [
"assert empty_dit([{},{},{}])==True",
"assert empty_dit([{1,2},{},{}])==False",
"assert empty_dit({})==True"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb | 295 | Write a function to return the sum of all divisors of a number. | def sum_div(number):
divisors = [1]
for i in range(2, number):
if (number % i)==0:
divisors.append(i)
return sum(divisors) | [] | [
"assert sum_div(8)==7",
"assert sum_div(12)==16",
"assert sum_div(7)==1"
] |
Benchmark Questions Verification V2.ipynb | 255 | Write a function that takes in a list and length n, and generates all combinations (with repetition) of the elements of the list and returns a list with a tuple for each combination. | from itertools import combinations_with_replacement
def combinations_colors(l, n):
return list(combinations_with_replacement(l,n))
| [] | [
"assert combinations_colors( [\"Red\",\"Green\",\"Blue\"],1)==[('Red',), ('Green',), ('Blue',)]",
"assert combinations_colors( [\"Red\",\"Green\",\"Blue\"],2)==[('Red', 'Red'), ('Red', 'Green'), ('Red', 'Blue'), ('Green', 'Green'), ('Green', 'Blue'), ('Blue', 'Blue')]",
"assert combinations_colors( [\"Red\",\"G... |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 133 | Write a function to calculate the sum of the negative numbers of a given list of numbers. | def sum_negativenum(nums):
sum_negativenum = list(filter(lambda nums:nums<0,nums))
return sum(sum_negativenum) | [] | [
"assert sum_negativenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==-32",
"assert sum_negativenum([10,15,-14,13,-18,12,-20])==-52",
"assert sum_negativenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==-894"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 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",
"assert tetrahedral_number(6) == 56",
"assert tetrahedral_number(7) == 84"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 127 | Write a function to multiply two integers. | def multiply_int(x, y):
if y < 0:
return -multiply_int(x, -y)
elif y == 0:
return 0
elif y == 1:
return x
else:
return x + multiply_int(x, y - 1) | [] | [
"assert multiply_int(10,20)==200",
"assert multiply_int(5,10)==50",
"assert multiply_int(4,8)==32"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 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"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 66 | Write a python function to count the number of 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"
] |
Benchmark Questions Verification V2.ipynb | 261 | Write a function that takes in two tuples and performs mathematical division operation element-wise across the given tuples. | def division_elements(test_tup1, test_tup2):
res = tuple(ele1 // ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res) | [] | [
"assert division_elements((10, 4, 6, 9),(5, 2, 3, 3)) == (2, 2, 2, 3)",
"assert division_elements((12, 6, 8, 16),(6, 3, 4, 4)) == (2, 2, 2, 4)",
"assert division_elements((20, 14, 36, 18),(5, 7, 6, 9)) == (4, 2, 6, 2)"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 57 | Write a python function to find the largest number that can be formed with the given list of digits. | def find_Max_Num(arr) :
n = len(arr)
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]) == 321",
"assert find_Max_Num([4,5,6,1]) == 6541",
"assert find_Max_Num([1,2,3,9]) == 9321"
] |
Benchmark Questions Verification V2.ipynb | 252 | Write a python function to convert complex numbers to polar coordinates. | import cmath
def convert(numbers):
num = cmath.polar(numbers)
return (num) | [] | [
"assert convert(1) == (1.0, 0.0)",
"assert convert(4) == (4.0,0.0)",
"assert convert(5) == (5.0,0.0)"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 141 | Write a function to sort a list of elements. | def pancake_sort(nums):
arr_len = len(nums)
while arr_len > 1:
mi = nums.index(max(nums[0:arr_len]))
nums = nums[mi::-1] + nums[mi+1:len(nums)]
nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)]
arr_len -= 1
return nums | [] | [
"assert pancake_sort([15, 79, 25, 38, 69]) == [15, 25, 38, 69, 79]",
"assert pancake_sort([98, 12, 54, 36, 85]) == [12, 36, 54, 85, 98]",
"assert pancake_sort([41, 42, 32, 12, 23]) == [12, 23, 32, 41, 42]"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb | 296 | Write a python function to count inversions in an array. | def get_Inv_Count(arr):
inv_count = 0
for i in range(len(arr)):
for j in range(i + 1, len(arr)):
if (arr[i] > arr[j]):
inv_count += 1
return inv_count | [] | [
"assert get_Inv_Count([1,20,6,4,5]) == 5",
"assert get_Inv_Count([1,2,1]) == 1",
"assert get_Inv_Count([1,2,5,6,1]) == 3"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 474 | Write a function to replace characters in a string. | def replace_char(str1,ch,newch):
str2 = str1.replace(ch, newch)
return str2 | [] | [
"assert replace_char(\"polygon\",'y','l')==(\"pollgon\")",
"assert replace_char(\"character\",'c','a')==(\"aharaater\")",
"assert replace_char(\"python\",'l','a')==(\"python\")"
] |
Benchmark Questions Verification V2.ipynb | 266 | Write a function to find the lateral surface area of a cube given its side length. | def lateralsurface_cube(l):
LSA = 4 * (l * l)
return LSA | [] | [
"assert lateralsurface_cube(5)==100",
"assert lateralsurface_cube(9)==324",
"assert lateralsurface_cube(10)==400"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb | 297 | Write a function to flatten a given nested list structure. | def flatten_list(list1):
result_list = []
if not list1: return result_list
stack = [list(list1)]
while stack:
c_num = stack.pop()
next = c_num.pop()
if c_num: stack.append(c_num)
if isinstance(next, list):
if next: stack.append(list(next))
else: result... | [] | [
"assert flatten_list([0, 10, [20, 30], 40, 50, [60, 70, 80], [90, 100, 110, 120]])==[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]",
"assert flatten_list([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])==[10, 20, 40, 30, 56, 25, 10, 20, 33, 40]",
"assert flatten_list([[1,2,3], [4,5,6], [10,11,12], ... |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 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"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 422 | Write a python function to find the average of cubes of first n natural numbers. | def find_Average_Of_Cube(n):
sum = 0
for i in range(1, n + 1):
sum += i * i * i
return round(sum / n, 6) | [] | [
"assert find_Average_Of_Cube(2) == 4.5",
"assert find_Average_Of_Cube(3) == 12",
"assert find_Average_Of_Cube(1) == 1"
] |
Benchmark Questions Verification V2.ipynb | 281 | Write a python function to check if the elements of a given list are unique or not. | def all_unique(test_list):
if len(test_list) > len(set(test_list)):
return False
return True | [] | [
"assert all_unique([1,2,3]) == True",
"assert all_unique([1,2,1,2]) == False",
"assert all_unique([1,2,3,4,5]) == True"
] |
Benchmark Questions Verification V2.ipynb | 271 | Write a python function that takes in an integer n and finds the sum of the first n even natural numbers that are raised to the fifth power. | def even_Power_Sum(n):
sum = 0;
for i in range(1,n+1):
j = 2*i;
sum = sum + (j*j*j*j*j);
return sum; | [] | [
"assert even_Power_Sum(2) == 1056",
"assert even_Power_Sum(3) == 8832",
"assert even_Power_Sum(1) == 32"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 145 | Write a python function to find the maximum difference between any two elements in a given array. | def max_Abs_Diff(arr):
n = len(arr)
minEle = arr[0]
maxEle = arr[0]
for i in range(1, n):
minEle = min(minEle,arr[i])
maxEle = max(maxEle,arr[i])
return (maxEle - minEle) | [] | [
"assert max_Abs_Diff((2,1,5,3)) == 4",
"assert max_Abs_Diff((9,3,2,5,1)) == 8",
"assert max_Abs_Diff((3,2,1)) == 2"
] |
Benchmark Questions Verification V2.ipynb | 259 | Write a function to maximize the given two tuples. | def maximize_elements(test_tup1, test_tup2):
res = tuple(tuple(max(a, b) for a, b in zip(tup1, tup2))
for tup1, tup2 in zip(test_tup1, test_tup2))
return (res) | [] | [
"assert maximize_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((6, 7), (4, 9), (2, 9), (7, 10))",
"assert maximize_elements(((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))) == ((7, 8), (5, 10), (3, 10), (8, 11))",
"assert maximize_elements(((3, 5), (6, 7... |
Benchmark Questions Verification V2.ipynb | 267 | Write a python function that takes in an integer n and returns the sum of the squares of the first n odd natural numbers. | def square_Sum(n):
return int(n*(4*n*n-1)/3) | [] | [
"assert square_Sum(2) == 10",
"assert square_Sum(3) == 35",
"assert square_Sum(4) == 84"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 95 | Write a python function to find the length of the smallest list in a list of lists. | 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"
] |
Benchmark Questions Verification V2.ipynb | 165 | Write a function to count the number of characters in a string that occur at the same position in the string as in the English alphabet (case insensitive). | def count_char_position(str1):
count_chars = 0
for i in range(len(str1)):
if ((i == ord(str1[i]) - ord('A')) or
(i == ord(str1[i]) - ord('a'))):
count_chars += 1
return count_chars | [] | [
"assert count_char_position(\"xbcefg\") == 2",
"assert count_char_position(\"ABcED\") == 3",
"assert count_char_position(\"AbgdeF\") == 5"
] |
Benchmark Questions Verification V2.ipynb | 399 | Write a function to perform the mathematical bitwise xor operation across the given tuples. | def bitwise_xor(test_tup1, test_tup2):
res = tuple(ele1 ^ ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res) | [] | [
"assert bitwise_xor((10, 4, 6, 9), (5, 2, 3, 3)) == (15, 6, 5, 10)",
"assert bitwise_xor((11, 5, 7, 10), (6, 3, 4, 4)) == (13, 6, 3, 14)",
"assert bitwise_xor((12, 6, 8, 11), (7, 4, 5, 6)) == (11, 2, 13, 13)"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 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) | [
"import math"
] | [
"assert math.isclose(multiply_num((8, 2, 3, -1, 7)), -67.2, rel_tol=0.001)",
"assert math.isclose(multiply_num((-10,-20,-30)), -2000.0, rel_tol=0.001)",
"assert math.isclose(multiply_num((19,15,18)), 1710.0, rel_tol=0.001)"
] |
Benchmark Questions Verification V2.ipynb | 251 | Write a function that takes in a list and an element and inserts the element before each element in the list, and returns the resulting list. | def insert_element(list,element):
list = [v for elt in list for v in (element, elt)]
return list | [] | [
"assert insert_element(['Red', 'Green', 'Black'] ,'c')==['c', 'Red', 'c', 'Green', 'c', 'Black']",
"assert insert_element(['python', 'java'] ,'program')==['program', 'python', 'program', 'java']",
"assert insert_element(['happy', 'sad'] ,'laugh')==['laugh', 'happy', 'laugh', 'sad']"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 460 | Write a python function to get the first element of each sublist. | def Extract(lst):
return [item[0] for item in lst] | [] | [
"assert Extract([[1, 2], [3, 4, 5], [6, 7, 8, 9]]) == [1, 3, 6]",
"assert Extract([[1,2,3],[4, 5]]) == [1,4]",
"assert Extract([[9,8,1],[1,2]]) == [9,1]"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 139 | Write a function to find the circumference of a circle. | def circle_circumference(r):
perimeter=2*3.1415*r
return perimeter | [
"import math"
] | [
"assert math.isclose(circle_circumference(10), 62.830000000000005, rel_tol=0.001)",
"assert math.isclose(circle_circumference(5), 31.415000000000003, rel_tol=0.001)",
"assert math.isclose(circle_circumference(4), 25.132, rel_tol=0.001)"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 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"
] |
Benchmark Questions Verification V2.ipynb | 170 | Write a function to find the sum of numbers in a list within a range specified by two indices. | def sum_range_list(list1, m, n):
sum_range = 0 ... | [] | [
"assert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 8, 10) == 29",
"assert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 5, 7) == 16",
"assert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 7, 10) == 38"
] |
Benchmark Questions Verification V2.ipynb | 407 | Write a function to create the next bigger number by rearranging the digits of a given number. | def rearrange_bigger(n):
nums = list(str(n))
for i in range(len(nums)-2,-1,-1):
if nums[i] < nums[i+1]:
z = nums[i:]
y = min(filter(lambda x: x > z[0], z))
z.remove(y)
z.sort()
nums[i:] = [y] + z
return int("".join(nums))
return... | [] | [
"assert rearrange_bigger(12)==21",
"assert rearrange_bigger(10)==False",
"assert rearrange_bigger(102)==120"
] |
Benchmark Questions Verification V2.ipynb | 282 | Write a function to subtract two lists element-wise. | def sub_list(nums1,nums2):
result = map(lambda x, y: x - y, nums1, nums2)
return list(result) | [] | [
"assert sub_list([1, 2, 3],[4,5,6])==[-3,-3,-3]",
"assert sub_list([1,2],[3,4])==[-2,-2]",
"assert sub_list([90,120],[50,70])==[40,50]"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 64 | Write a function to sort a list of tuples using the second value of each tuple. | 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_mark... |
Benchmark Questions Verification V2.ipynb | 274 | Write a python function that takes in a positive integer n and finds the sum of even index binomial coefficients. | import math
def even_binomial_Coeff_Sum( n):
return (1 << (n - 1)) | [] | [
"assert even_binomial_Coeff_Sum(4) == 8",
"assert even_binomial_Coeff_Sum(6) == 32",
"assert even_binomial_Coeff_Sum(2) == 2"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 105 | Write a python function to count true booleans in the given list. | def count(lst):
return sum(lst) | [] | [
"assert count([True,False,True]) == 2",
"assert count([False,False]) == 0",
"assert count([True,True,True]) == 3"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 99 | Write a function to convert the given decimal number to its binary equivalent, represented as a string with no leading zeros. | 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'"
] |
Benchmark Questions Verification V2.ipynb | 168 | Write a function to count the number of occurrences of a number in a given list. | def frequency(a,x):
count = 0
for i in a:
if i == x:
count += 1
return count | [] | [
"assert frequency([1,2,3], 4) == 0",
"assert frequency([1,2,2,3,3,3,4], 3) == 3",
"assert frequency([0,1,2,3,1,2], 1) == 2"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 453 | Write a python function to find the sum of even factors of a number. | import math
def sumofFactors(n) :
if (n % 2 != 0) :
return 0
res = 1
for i in range(2, (int)(math.sqrt(n)) + 1) :
count = 0
curr_sum = 1
curr_term = 1
while (n % i == 0) :
count= count + 1
n = n // i
if (i == 2 and count ==... | [] | [
"assert sumofFactors(18) == 26",
"assert sumofFactors(30) == 48",
"assert sumofFactors(6) == 8"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb | 446 | Write a python function to count the occurence of all elements of list in a tuple. | from collections import Counter
def count_Occurrence(tup, lst):
count = 0
for item in tup:
if item in lst:
count+= 1
return count | [] | [
"assert count_Occurrence(('a', 'a', 'c', 'b', 'd'),['a', 'b'] ) == 3",
"assert count_Occurrence((1, 2, 3, 1, 4, 6, 7, 1, 4),[1, 4, 7]) == 6",
"assert count_Occurrence((1,2,3,4,5,6),[1,2]) == 2"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb | 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"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.