source_file
string | task_id
int64 | prompt
string | code
string | test_imports
list | test_list
list |
|---|---|---|---|---|---|
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"
] |
Benchmark Questions Verification V2.ipynb
| 392
|
Write a function to find the maximum sum possible by using the given equation f(n) = max( (f(n/2) + f(n/3) + f(n/4) + f(n/5)), n).
|
def get_max_sum (n):
res = list()
res.append(0)
res.append(1)
i = 2
while i<n + 1:
res.append(max(i, (res[int(i / 2)]
+ res[int(i / 3)] +
res[int(i / 4)]
+ res[int(i / 5)])))
i = i + 1
return res[n]
|
[] |
[
"assert get_max_sum(60) == 106",
"assert get_max_sum(10) == 12",
"assert get_max_sum(2) == 2"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 393
|
Write a function to find the list with maximum length.
|
def max_length_list(input_list):
max_length = max(len(x) for x in input_list )
max_list = max(input_list, key = lambda i: len(i))
return(max_length, max_list)
|
[] |
[
"assert max_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])",
"assert max_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(5,[1,2,3,4,5])",
"assert max_length_list([[3,4,5],[6,7,8,9],[10,11,12]])==(4,[6,7,8,9])"
] |
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
| 398
|
Write a function to compute the sum of digits of each number of a given list.
|
def sum_of_digits(nums):
return sum(int(el) for n in nums for el in str(n) if el.isdigit())
|
[] |
[
"assert sum_of_digits([10,2,56])==14",
"assert sum_of_digits([[10,20,4,5,'b',70,'a']])==19",
"assert sum_of_digits([10,20,-4,5,-70])==19"
] |
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
| 406
|
Write a python function to find whether the parity of a given number is odd.
|
def find_Parity(x):
y = x ^ (x >> 1);
y = y ^ (y >> 2);
y = y ^ (y >> 4);
y = y ^ (y >> 8);
y = y ^ (y >> 16);
if (y & 1):
return True
return False
|
[] |
[
"assert find_Parity(12) == False",
"assert find_Parity(7) == True",
"assert find_Parity(10) == False"
] |
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 False
|
[] |
[
"assert rearrange_bigger(12)==21",
"assert rearrange_bigger(10)==False",
"assert rearrange_bigger(102)==120"
] |
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
| 412
|
Write a python function to remove odd numbers from a given list.
|
def remove_odd(l):
for i in l:
if i % 2 != 0:
l.remove(i)
return l
|
[] |
[
"assert remove_odd([1,2,3]) == [2]",
"assert remove_odd([2,4,6]) == [2,4,6]",
"assert remove_odd([10,20,3]) == [10,20]"
] |
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), ('Beau Turnbull', 94, 98)] ,2)==[99, 96, 94, 98]",
"assert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)],1)==[98, 97, 91, 94]"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 414
|
Write a python function to check whether any value in a sequence exists in a sequence or not.
|
def overlapping(list1,list2):
for i in range(len(list1)):
for j in range(len(list2)):
if(list1[i]==list2[j]):
return True
return False
|
[] |
[
"assert overlapping([1,2,3,4,5],[6,7,8,9]) == False",
"assert overlapping([1,2,3],[4,5,6]) == False",
"assert overlapping([1,4,5],[1,4,5]) == True"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 415
|
Write a python function to find a pair with highest product from a given array of integers.
|
def max_Product(arr):
arr_len = len(arr)
if (arr_len < 2):
return ("No pairs exists")
x = arr[0]; y = arr[1]
for i in range(0,arr_len):
for j in range(i + 1,arr_len):
if (arr[i] * arr[j] > x * y):
x = arr[i]; y = arr[j]
return x,y
|
[] |
[
"assert max_Product([1,2,3,4,7,0,8,4]) == (7,8)",
"assert max_Product([0,-1,-2,-4,5,0,-6]) == (-4,-6)",
"assert max_Product([1,2,3]) == (2,3)"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 417
|
Write a function to find common first element in given list of tuple.
|
def group_tuples(Input):
out = {}
for elem in Input:
try:
out[elem[0]].extend(elem[1:])
except KeyError:
out[elem[0]] = list(elem)
return [tuple(values) for values in out.values()]
|
[] |
[
"assert group_tuples([('x', 'y'), ('x', 'z'), ('w', 't')]) == [('x', 'y', 'z'), ('w', 't')]",
"assert group_tuples([('a', 'b'), ('a', 'c'), ('d', 'e')]) == [('a', 'b', 'c'), ('d', 'e')]",
"assert group_tuples([('f', 'g'), ('f', 'g'), ('h', 'i')]) == [('f', 'g', 'g'), ('h', 'i')]"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 418
|
Write a python function to find the element of a list having maximum length.
|
def Find_Max(lst):
maxList = max((x) for x in lst)
return maxList
|
[] |
[
"assert Find_Max([['A'],['A','B'],['A','B','C']]) == ['A','B','C']",
"assert Find_Max([[1],[1,2],[1,2,3]]) == [1,2,3]",
"assert Find_Max([[1,1],[1,2,3],[1,5,6,1]]) == [1,5,6,1]"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 420
|
Write a python function to find the cube sum of first n even natural numbers.
|
def cube_Sum(n):
sum = 0
for i in range(1,n + 1):
sum += (2*i)*(2*i)*(2*i)
return sum
|
[] |
[
"assert cube_Sum(2) == 72",
"assert cube_Sum(3) == 288",
"assert cube_Sum(4) == 800"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 421
|
Write a function to concatenate each element of tuple by the delimiter.
|
def concatenate_tuple(test_tup):
delim = "-"
res = ''.join([str(ele) + delim for ele in test_tup])
res = res[ : len(res) - len(delim)]
return (str(res))
|
[] |
[
"assert concatenate_tuple((\"ID\", \"is\", 4, \"UTS\") ) == 'ID-is-4-UTS'",
"assert concatenate_tuple((\"QWE\", \"is\", 4, \"RTY\") ) == 'QWE-is-4-RTY'",
"assert concatenate_tuple((\"ZEN\", \"is\", 4, \"OP\") ) == 'ZEN-is-4-OP'"
] |
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"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 425
|
Write a function to count the number of sublists containing a particular element.
|
def count_element_in_list(list1, x):
ctr = 0
for i in range(len(list1)):
if x in list1[i]:
ctr+= 1
return ctr
|
[] |
[
"assert count_element_in_list([[1, 3], [5, 7], [1, 11], [1, 15, 7]],1)==3",
"assert count_element_in_list([['A', 'B'], ['A', 'C'], ['A', 'D', 'E'], ['B', 'C', 'D']],'A')==3",
"assert count_element_in_list([['A', 'B'], ['A', 'C'], ['A', 'D', 'E'], ['B', 'C', 'D']],'E')==1"
] |
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
| 428
|
Write a function to sort the given array by using shell sort.
|
def shell_sort(my_list):
gap = len(my_list) // 2
while gap > 0:
for i in range(gap, len(my_list)):
current_item = my_list[i]
j = i
while j >= gap and my_list[j - gap] > current_item:
my_list[j] = my_list[j - gap]
j -= gap
my_list[j] = current_item
gap //= 2
return my_list
|
[] |
[
"assert shell_sort([12, 23, 4, 5, 3, 2, 12, 81, 56, 95]) == [2, 3, 4, 5, 12, 12, 23, 56, 81, 95]",
"assert shell_sort([24, 22, 39, 34, 87, 73, 68]) == [22, 24, 34, 39, 68, 73, 87]",
"assert shell_sort([32, 30, 16, 96, 82, 83, 74]) == [16, 30, 32, 74, 82, 83, 96]"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 434
|
Write a function that matches a string that has an a followed by one or more b's.
|
import re
def text_match_one(text):
patterns = 'ab+?'
if re.search(patterns, text):
return True
else:
return False
|
[] |
[
"assert text_match_one(\"ac\")==False",
"assert text_match_one(\"dc\")==False",
"assert text_match_one(\"abba\")==True"
] |
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"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 448
|
Write a function to calculate the sum of perrin numbers.
|
def cal_sum(n):
a = 3
b = 0
c = 2
if (n == 0):
return 3
if (n == 1):
return 3
if (n == 2):
return 5
sum = 5
while (n > 2):
d = a + b
sum = sum + d
a = b
b = c
c = d
n = n-1
return sum
|
[] |
[
"assert cal_sum(9) == 49",
"assert cal_sum(10) == 66",
"assert cal_sum(11) == 88"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 450
|
Write a function to extract specified size of strings from a given list of string values.
|
def extract_string(str, l):
result = [e for e in str if len(e) == l]
return result
|
[] |
[
"assert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,8)==['practice', 'solution']",
"assert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,6)==['Python']",
"assert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,9)==['exercises']"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 454
|
Write a function that matches a word containing 'z'.
|
import re
def text_match_wordz(text):
patterns = '\w*z.\w*'
if re.search(patterns, text):
return True
else:
return False
|
[] |
[
"assert text_match_wordz(\"pythonz.\")==True",
"assert text_match_wordz(\"xyz.\")==True",
"assert text_match_wordz(\" lang .\")==False"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 456
|
Write a function to reverse each string in a given list of string values.
|
def reverse_string_list(stringlist):
result = [x[::-1] for x in stringlist]
return result
|
[] |
[
"assert reverse_string_list(['Red', 'Green', 'Blue', 'White', 'Black'])==['deR', 'neerG', 'eulB', 'etihW', 'kcalB']",
"assert reverse_string_list(['john','amal','joel','george'])==['nhoj','lama','leoj','egroeg']",
"assert reverse_string_list(['jack','john','mary'])==['kcaj','nhoj','yram']"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 457
|
Write a python function to find the sublist having minimum length.
|
def Find_Min(lst):
return min(lst, key=len)
|
[] |
[
"assert Find_Min([[1],[1,2],[1,2,3]]) == [1]",
"assert Find_Min([[1,1],[1,1,1],[1,2,7,8]]) == [1,1]",
"assert Find_Min([['x'],['x','y'],['x','y','z']]) == ['x']"
] |
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]"
] |
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', 'green', 'red'], ['blue', 'green', 'red', 'orange']]",
"assert combinations_list(['red', 'green', 'blue', 'white', 'black', 'orange'])==[[], ['red'], ['green'], ['green', 'red'], ['blue'], ['blue', 'red'], ['blue', 'green'], ['blue', 'green', 'red'], ['white'], ['white', 'red'], ['white', 'green'], ['white', 'green', 'red'], ['white', 'blue'], ['white', 'blue', 'red'], ['white', 'blue', 'green'], ['white', 'blue', 'green', 'red'], ['black'], ['black', 'red'], ['black', 'green'], ['black', 'green', 'red'], ['black', 'blue'], ['black', 'blue', 'red'], ['black', 'blue', 'green'], ['black', 'blue', 'green', 'red'], ['black', 'white'], ['black', 'white', 'red'], ['black', 'white', 'green'], ['black', 'white', 'green', 'red'], ['black', 'white', 'blue'], ['black', 'white', 'blue', 'red'], ['black', 'white', 'blue', 'green'], ['black', 'white', 'blue', 'green', 'red'], ['orange'], ['orange', 'red'], ['orange', 'green'], ['orange', 'green', 'red'], ['orange', 'blue'], ['orange', 'blue', 'red'], ['orange', 'blue', 'green'], ['orange', 'blue', 'green', 'red'], ['orange', 'white'], ['orange', 'white', 'red'], ['orange', 'white', 'green'], ['orange', 'white', 'green', 'red'], ['orange', 'white', 'blue'], ['orange', 'white', 'blue', 'red'], ['orange', 'white', 'blue', 'green'], ['orange', 'white', 'blue', 'green', 'red'], ['orange', 'black'], ['orange', 'black', 'red'], ['orange', 'black', 'green'], ['orange', 'black', 'green', 'red'], ['orange', 'black', 'blue'], ['orange', 'black', 'blue', 'red'], ['orange', 'black', 'blue', 'green'], ['orange', 'black', 'blue', 'green', 'red'], ['orange', 'black', 'white'], ['orange', 'black', 'white', 'red'], ['orange', 'black', 'white', 'green'], ['orange', 'black', 'white', 'green', 'red'], ['orange', 'black', 'white', 'blue'], ['orange', 'black', 'white', 'blue', 'red'], ['orange', 'black', 'white', 'blue', 'green'], ['orange', 'black', 'white', 'blue', 'green', 'red']]",
"assert combinations_list(['red', 'green', 'black', 'orange'])==[[], ['red'], ['green'], ['green', 'red'], ['black'], ['black', 'red'], ['black', 'green'], ['black', 'green', 'red'], ['orange'], ['orange', 'red'], ['orange', 'green'], ['orange', 'green', 'red'], ['orange', 'black'], ['orange', 'black', 'red'], ['orange', 'black', 'green'], ['orange', 'black', 'green', 'red']]"
] |
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_ending_here = 1
else:
temp = max_ending_here
max_ending_here = max (min_ending_here * arr[i], 1)
min_ending_here = temp * arr[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if flag == 0 and max_so_far == 0:
return 0
return max_so_far
|
[] |
[
"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"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 464
|
Write a function to check if all values are same in a dictionary.
|
def check_value(dict, n):
result = all(x == n for x in dict.values())
return result
|
[] |
[
"assert check_value({'Cierra Vega': 12, 'Alden Cantrell': 12, 'Kierra Gentry': 12, 'Pierre Cox': 12},10)==False",
"assert check_value({'Cierra Vega': 12, 'Alden Cantrell': 12, 'Kierra Gentry': 12, 'Pierre Cox': 12},12)==True",
"assert check_value({'Cierra Vega': 12, 'Alden Cantrell': 12, 'Kierra Gentry': 12, 'Pierre Cox': 12},5)==False"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 471
|
Write a python function to find the product of the array multiplication modulo n.
|
def find_remainder(arr, n):
mul = 1
for i in range(len(arr)):
mul = (mul * (arr[i] % n)) % n
return mul % n
|
[] |
[
"assert find_remainder([ 100, 10, 5, 25, 35, 14 ],11) ==9",
"assert find_remainder([1,1,1],1) == 0",
"assert find_remainder([1,2,1],2) == 0"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 472
|
Write a python function to check whether the given list contains consecutive numbers or not.
|
def check_Consecutive(l):
return sorted(l) == list(range(min(l),max(l)+1))
|
[] |
[
"assert check_Consecutive([1,2,3,4,5]) == True",
"assert check_Consecutive([1,2,3,5,6]) == False",
"assert check_Consecutive([1,2,1]) == False"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.