Dataset Viewer
source_file
string | task_id
int64 | prompt
string | code
string | test_imports
sequence | test_list
sequence |
---|---|---|---|---|---|
Benchmark Questions Verification V2.ipynb
| 232 |
Write a function that takes in a list and an integer n and returns a list containing the n largest items from the list.
|
import heapq
def larg_nnum(list1,n):
largest=heapq.nlargest(n,list1)
return largest
|
[] |
[
"assert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2))==set([100,90])",
"assert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5))==set([100,90,80,70,60])",
"assert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3))==set([100,90,80])"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 102 |
Write a function to convert a snake case string to camel case string.
|
def snake_to_camel(word):
import re
return ''.join(x.capitalize() or '_' for x in word.split('_'))
|
[] |
[
"assert snake_to_camel('python_program')=='PythonProgram'",
"assert snake_to_camel('python_language')==('PythonLanguage')",
"assert snake_to_camel('programming_language')==('ProgrammingLanguage')"
] |
Benchmark Questions Verification V2.ipynb
| 224 |
Write a python function to count the number of set bits (binary digits with value 1) in a given number.
|
def count_Set_Bits(n):
count = 0
while (n):
count += n & 1
n >>= 1
return count
|
[] |
[
"assert count_Set_Bits(2) == 1",
"assert count_Set_Bits(4) == 1",
"assert count_Set_Bits(6) == 2"
] |
Benchmark Questions Verification V2.ipynb
| 276 |
Write a function that takes in the radius and height of a cylinder and returns the the volume.
|
def volume_cylinder(r,h):
volume=3.1415*r*r*h
return volume
|
[
"import math"
] |
[
"assert math.isclose(volume_cylinder(10,5), 1570.7500000000002, rel_tol=0.001)",
"assert math.isclose(volume_cylinder(4,5), 251.32000000000002, rel_tol=0.001)",
"assert math.isclose(volume_cylinder(4,10), 502.64000000000004, rel_tol=0.001)"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 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
|
[
"import math"
] |
[
"assert math.isclose(surfacearea_sphere(10), 1256.6370614359173, rel_tol=0.001)",
"assert math.isclose(surfacearea_sphere(15), 2827.4333882308138, rel_tol=0.001)",
"assert math.isclose(surfacearea_sphere(20), 5026.548245743669, rel_tol=0.001)"
] |
Benchmark Questions Verification V2.ipynb
| 410 |
Write a function to find the minimum value in a given heterogeneous list.
|
def min_val(listval):
min_val = min(i for i in listval if isinstance(i, int))
return min_val
|
[] |
[
"assert min_val(['Python', 3, 2, 4, 5, 'version'])==2",
"assert min_val(['Python', 15, 20, 25])==15",
"assert min_val(['Python', 30, 20, 40, 50, 'version'])==20"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 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
|
[
"import math"
] |
[
"assert math.isclose(volume_sphere(10), 4188.790204786391, rel_tol=0.001)",
"assert math.isclose(volume_sphere(25), 65449.84694978735, rel_tol=0.001)",
"assert math.isclose(volume_sphere(20), 33510.32163829113, rel_tol=0.001)"
] |
Benchmark Questions Verification V2.ipynb
| 230 |
Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string.
|
def replace_blank(str1,char):
str2 = str1.replace(' ', char)
return str2
|
[] |
[
"assert replace_blank(\"hello people\",'@')==(\"hello@people\")",
"assert replace_blank(\"python program language\",'$')==(\"python$program$language\")",
"assert replace_blank(\"blank space\",\"-\")==(\"blank-space\")"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 124 |
Write a function to get the angle of a complex number.
|
import cmath
def angle_complex(a,b):
cn=complex(a,b)
angle=cmath.phase(a+b)
return angle
|
[
"import math"
] |
[
"assert math.isclose(angle_complex(0,1j), 1.5707963267948966, rel_tol=0.001)",
"assert math.isclose(angle_complex(2,1j), 0.4636476090008061, rel_tol=0.001)",
"assert math.isclose(angle_complex(0,2j), 1.5707963267948966, rel_tol=0.001)"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb
| 293 |
Write a function to find the third side of a right angled triangle.
|
import math
def otherside_rightangle(w,h):
s=math.sqrt((w*w)+(h*h))
return s
|
[] |
[
"assert otherside_rightangle(7,8)==10.63014581273465",
"assert otherside_rightangle(3,4)==5",
"assert otherside_rightangle(7,15)==16.55294535724685"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 120 |
Write a function to find the maximum absolute product between numbers in pairs of tuples within a given list.
|
def max_product_tuple(list1):
result_max = max([abs(x * y) for x, y in list1] )
return result_max
|
[] |
[
"assert max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==36",
"assert max_product_tuple([(10,20), (15,2), (5,10)] )==200",
"assert max_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==484"
] |
Benchmark Questions Verification V2.ipynb
| 166 |
Write a function that counts the number of pairs of integers in a list that xor to an even number.
|
def find_even_pair(A):
count = 0
for i in range(0, len(A)):
for j in range(i+1, len(A)):
if ((A[i] ^ A[j]) % 2 == 0):
count += 1
return count
|
[] |
[
"assert find_even_pair([5, 4, 7, 2, 1]) == 4",
"assert find_even_pair([7, 2, 8, 1, 0, 5, 11]) == 9",
"assert find_even_pair([1, 2, 3]) == 1"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 440 |
Write a function to find the first adverb and their positions in a given sentence.
|
import re
def find_adverb_position(text):
for m in re.finditer(r"\w+ly", text):
return (m.start(), m.end(), m.group(0))
|
[] |
[
"assert find_adverb_position(\"clearly!! we can see the sky\")==(0, 7, 'clearly')",
"assert find_adverb_position(\"seriously!! there are many roses\")==(0, 9, 'seriously')",
"assert find_adverb_position(\"unfortunately!! sita is going to home\")==(0, 13, 'unfortunately')"
] |
Benchmark Questions Verification V2.ipynb
| 242 |
Write a function to count the total number of characters in a string.
|
def count_charac(str1):
total = 0
for i in str1:
total = total + 1
return total
|
[] |
[
"assert count_charac(\"python programming\")==18",
"assert count_charac(\"language\")==8",
"assert count_charac(\"words\")==5"
] |
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"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb
| 305 |
Write a function to return two words from a list of words starting with letter 'p'.
|
import re
def start_withp(words):
for w in words:
m = re.match("(P\w+)\W(P\w+)", w)
if m:
return m.groups()
|
[] |
[
"assert start_withp([\"Python PHP\", \"Java JavaScript\", \"c c++\"])==('Python', 'PHP')",
"assert start_withp([\"Python Programming\",\"Java Programming\"])==('Python','Programming')",
"assert start_withp([\"Pqrst Pqr\",\"qrstuv\"])==('Pqrst','Pqr')"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 97 |
Write a function to find frequency of each element in a flattened list of lists, returned in a dictionary.
|
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}"
] |
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
| 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"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 117 |
Write a function to convert all possible convertible elements in a list of lists to floats.
|
def list_to_float(test_list):
res = []
for tup in test_list:
temp = []
for ele in tup:
if ele.isalpha():
temp.append(ele)
else:
temp.append(float(ele))
res.append((temp[0],temp[1]))
return res
|
[] |
[
"assert list_to_float( [(\"3\", \"4\"), (\"1\", \"26.45\"), (\"7.32\", \"8\"), (\"4\", \"8\")] ) == [(3.0, 4.0), (1.0, 26.45), (7.32, 8.0), (4.0, 8.0)]",
"assert list_to_float( [(\"4\", \"4\"), (\"2\", \"27\"), (\"4.12\", \"9\"), (\"7\", \"11\")] ) == [(4.0, 4.0), (2.0, 27.0), (4.12, 9.0), (7.0, 11.0)]",
"assert list_to_float( [(\"6\", \"78\"), (\"5\", \"26.45\"), (\"1.33\", \"4\"), (\"82\", \"13\")] ) == [(6.0, 78.0), (5.0, 26.45), (1.33, 4.0), (82.0, 13.0)]"
] |
Benchmark Questions Verification V2.ipynb
| 249 |
Write a function to find the intersection of two arrays.
|
def intersection_array(array_nums1,array_nums2):
result = list(filter(lambda x: x in array_nums1, array_nums2))
return result
|
[] |
[
"assert intersection_array([1, 2, 3, 5, 7, 8, 9, 10],[1, 2, 4, 8, 9])==[1, 2, 8, 9]",
"assert intersection_array([1, 2, 3, 5, 7, 8, 9, 10],[3,5,7,9])==[3,5,7,9]",
"assert intersection_array([1, 2, 3, 5, 7, 8, 9, 10],[10,20,30,40])==[10]"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 436 |
Write a python function to return the negative numbers in a list.
|
def neg_nos(list1):
out = []
for num in list1:
if num < 0:
out.append(num)
return out
|
[] |
[
"assert neg_nos([-1,4,5,-6]) == [-1,-6]",
"assert neg_nos([-1,-2,3,4]) == [-1,-2]",
"assert neg_nos([-7,-6,8,9]) == [-7,-6]"
] |
Benchmark Questions Verification V2.ipynb
| 160 |
Write a function that returns integers x and y that satisfy ax + by = n as a tuple, or return None if no solution exists.
|
def find_solution(a, b, n):
i = 0
while i * a <= n:
if (n - (i * a)) % b == 0:
return (i, (n - (i * a)) // b)
i = i + 1
return None
|
[] |
[
"assert find_solution(2, 3, 7) == (2, 1)",
"assert find_solution(4, 2, 7) == None",
"assert find_solution(1, 13, 17) == (4, 1)"
] |
Benchmark Questions Verification V2.ipynb
| 239 |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m,n):
T=[[0 for i in range(n+1)] for i in range(m+1)]
for i in range(m+1):
for j in range(n+1):
if i==0 or j==0:
T[i][j]=0
elif i<j:
T[i][j]=0
elif j==1:
T[i][j]=i
else:
T[i][j]=T[i-1][j]+T[i//2][j-1]
return T[m][n]
|
[] |
[
"assert get_total_number_of_sequences(10, 4) == 4",
"assert get_total_number_of_sequences(5, 2) == 6",
"assert get_total_number_of_sequences(16, 3) == 84"
] |
Benchmark Questions Verification V2.ipynb
| 395 |
Write a python function to find the first non-repeated character in a given string.
|
def first_non_repeating_character(str1):
char_order = []
ctr = {}
for c in str1:
if c in ctr:
ctr[c] += 1
else:
ctr[c] = 1
char_order.append(c)
for c in char_order:
if ctr[c] == 1:
return c
return None
|
[] |
[
"assert first_non_repeating_character(\"abcabc\") == None",
"assert first_non_repeating_character(\"abc\") == \"a\"",
"assert first_non_repeating_character(\"ababc\") == \"c\""
] |
Benchmark Questions Verification V2.ipynb
| 270 |
Write a python function to find the sum of even numbers at even positions of a list.
|
def sum_even_and_even_index(arr):
i = 0
sum = 0
for i in range(0, len(arr),2):
if (arr[i] % 2 == 0) :
sum += arr[i]
return sum
|
[] |
[
"assert sum_even_and_even_index([5, 6, 12, 1, 18, 8]) == 30",
"assert sum_even_and_even_index([3, 20, 17, 9, 2, 10, 18, 13, 6, 18]) == 26",
"assert sum_even_and_even_index([5, 6, 12, 1]) == 12"
] |
Benchmark Questions Verification V2.ipynb
| 233 |
Write a function to find the lateral surface area of a cylinder.
|
def lateralsuface_cylinder(r,h):
lateralsurface= 2*3.1415*r*h
return lateralsurface
|
[
"import math"
] |
[
"assert math.isclose(lateralsuface_cylinder(10,5), 314.15000000000003, rel_tol=0.001)",
"assert math.isclose(lateralsuface_cylinder(4,5), 125.66000000000001, rel_tol=0.001)",
"assert math.isclose(lateralsuface_cylinder(4,10), 251.32000000000002, rel_tol=0.001)"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 476 |
Write a python function to find the sum of the largest and smallest value in a given array.
|
def big_sum(nums):
sum= max(nums)+min(nums)
return sum
|
[] |
[
"assert big_sum([1,2,3]) == 4",
"assert big_sum([-1,2,3,4]) == 3",
"assert big_sum([2,3,6]) == 8"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 140 |
Write a function to flatten the list of lists into a single set of numbers.
|
def extract_singly(test_list):
res = []
temp = set()
for inner in test_list:
for ele in inner:
if not ele in temp:
temp.add(ele)
res.append(ele)
return (res)
|
[] |
[
"assert set(extract_singly([(3, 4, 5), (4, 5, 7), (1, 4)])) == set([3, 4, 5, 7, 1])",
"assert set(extract_singly([(1, 2, 3), (4, 2, 3), (7, 8)])) == set([1, 2, 3, 4, 7, 8])",
"assert set(extract_singly([(7, 8, 9), (10, 11, 12), (10, 11)])) == set([7, 8, 9, 10, 11, 12])"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 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"
] |
Benchmark Questions Verification V2.ipynb
| 227 |
Write a function to find minimum of three numbers.
|
def min_of_three(a,b,c):
if (a <= b) and (a <= c):
smallest = a
elif (b <= a) and (b <= c):
smallest = b
else:
smallest = c
return smallest
|
[] |
[
"assert min_of_three(10,20,0)==0",
"assert min_of_three(19,15,18)==15",
"assert min_of_three(-10,-20,-30)==-30"
] |
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
| 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
| 443 |
Write a python function to find the largest negative number from the given list.
|
def largest_neg(list1):
max = list1[0]
for x in list1:
if x < max :
max = x
return max
|
[] |
[
"assert largest_neg([1,2,3,-4,-6]) == -6",
"assert largest_neg([1,2,3,-8,-9]) == -9",
"assert largest_neg([1,2,3,4,-1]) == -1"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 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"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 431 |
Write a function that takes two lists and returns true if they have at least one common element.
|
def common_element(list1, list2):
result = False
for x in list1:
for y in list2:
if x == y:
result = True
return result
|
[] |
[
"assert common_element([1,2,3,4,5], [5,6,7,8,9])==True",
"assert common_element([1,2,3,4,5], [6,7,8,9])==None",
"assert common_element(['a','b','c'], ['d','b','e'])==True"
] |
Benchmark Questions Verification V2.ipynb
| 17 |
Write a function that returns the perimeter of a square given its side length as input.
|
def square_perimeter(a):
perimeter=4*a
return perimeter
|
[] |
[
"assert square_perimeter(10)==40",
"assert square_perimeter(5)==20",
"assert square_perimeter(4)==16"
] |
Benchmark Questions Verification V2.ipynb
| 222 |
Write a function to check if all the elements in tuple have same data type or not.
|
def check_type(test_tuple):
res = True
for ele in test_tuple:
if not isinstance(ele, type(test_tuple[0])):
res = False
break
return (res)
|
[] |
[
"assert check_type((5, 6, 7, 3, 5, 6) ) == True",
"assert check_type((1, 2, \"4\") ) == False",
"assert check_type((3, 2, 1, 4, 5) ) == True"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 70 |
Write a function to find whether all the given tuples have equal length or not.
|
def find_equal_tuple(Input):
k = 0 if not Input else len(Input[0])
flag = 1
for tuple in Input:
if len(tuple) != k:
flag = 0
break
return flag
def get_equal(Input):
return find_equal_tuple(Input) == 1
|
[] |
[
"assert get_equal([(11, 22, 33), (44, 55, 66)]) == True",
"assert get_equal([(1, 2, 3), (4, 5, 6, 7)]) == False",
"assert get_equal([(1, 2), (3, 4)]) == True"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 94 |
Given a list of tuples, write a function that returns the first value of the tuple with the smallest second value.
|
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'"
] |
Benchmark Questions Verification V2.ipynb
| 171 |
Write a function to find the perimeter of a regular pentagon from the length of its sides.
|
import math
def perimeter_pentagon(a):
perimeter=(5*a)
return perimeter
|
[] |
[
"assert perimeter_pentagon(5) == 25",
"assert perimeter_pentagon(10) == 50",
"assert perimeter_pentagon(15) == 75"
] |
Benchmark Questions Verification V2.ipynb
| 246 |
Write a function for computing square roots using the babylonian method.
|
def babylonian_squareroot(number):
if(number == 0):
return 0;
g = number/2.0;
g2 = g + 1;
while(g != g2):
n = number/ g;
g2 = g;
g = (g + n)/2;
return g;
|
[
"import math"
] |
[
"assert math.isclose(babylonian_squareroot(10), 3.162277660168379, rel_tol=0.001)",
"assert math.isclose(babylonian_squareroot(2), 1.414213562373095, rel_tol=0.001)",
"assert math.isclose(babylonian_squareroot(9), 3.0, rel_tol=0.001)"
] |
Benchmark Questions Verification V2.ipynb
| 265 |
Write a function that takes in a list and an integer n and splits a list for every nth element, returning a list of the resulting lists.
|
def list_split(S, step):
return [S[i::step] for i in range(step)]
|
[] |
[
"assert list_split(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'],3)==[['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']]",
"assert list_split([1,2,3,4,5,6,7,8,9,10,11,12,13,14],3)==[[1,4,7,10,13], [2,5,8,11,14], [3,6,9,12]]",
"assert list_split(['python','java','C','C++','DBMS','SQL'],2)==[['python', 'C', 'DBMS'], ['java', 'C++', 'SQL']]"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 442 |
Write a function to find the ration of positive numbers in an array of integers.
|
from array import array
def positive_count(nums):
n = len(nums)
n1 = 0
for x in nums:
if x > 0:
n1 += 1
else:
None
return round(n1/n,2)
|
[] |
[
"assert positive_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8])==0.54",
"assert positive_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==0.69",
"assert positive_count([2, 4, -6, -9, 11, -12, 14, -5, 17])==0.56"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb
| 312 |
Write a function to find the volume of a cone.
|
import math
def volume_cone(r,h):
volume = (1.0/3) * math.pi * r * r * h
return volume
|
[
"import math"
] |
[
"assert math.isclose(volume_cone(5,12), 314.15926535897927, rel_tol=0.001)",
"assert math.isclose(volume_cone(10,15), 1570.7963267948965, rel_tol=0.001)",
"assert math.isclose(volume_cone(19,17), 6426.651371693521, rel_tol=0.001)"
] |
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"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb
| 290 |
Write a function to find the list of maximum length in a list of lists.
|
def max_length(list1):
max_length = max(len(x) for x in list1 )
max_list = max((x) for x in list1)
return(max_length, max_list)
|
[] |
[
"assert max_length([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])",
"assert max_length([[1], [5, 7], [10, 12, 14,15]])==(4, [10, 12, 14,15])",
"assert max_length([[5], [15,20,25]])==(3, [15,20,25])"
] |
Benchmark Questions Verification V2.ipynb
| 257 |
Write a function that takes in two numbers and returns a tuple with the second number and then the first number.
|
def swap_numbers(a,b):
temp = a
a = b
b = temp
return (a,b)
|
[] |
[
"assert swap_numbers(10,20)==(20,10)",
"assert swap_numbers(15,17)==(17,15)",
"assert swap_numbers(100,200)==(200,100)"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb
| 299 |
Write a function to calculate the maximum aggregate from the list of tuples.
|
from collections import defaultdict
def max_aggregate(stdata):
temp = defaultdict(int)
for name, marks in stdata:
temp[name] += marks
return max(temp.items(), key=lambda x: x[1])
|
[] |
[
"assert max_aggregate([('Juan Whelan',90),('Sabah Colley',88),('Peter Nichols',7),('Juan Whelan',122),('Sabah Colley',84)])==('Juan Whelan', 212)",
"assert max_aggregate([('Juan Whelan',50),('Sabah Colley',48),('Peter Nichols',37),('Juan Whelan',22),('Sabah Colley',14)])==('Juan Whelan', 72)",
"assert max_aggregate([('Juan Whelan',10),('Sabah Colley',20),('Peter Nichols',30),('Juan Whelan',40),('Sabah Colley',50)])==('Sabah Colley', 70)"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 465 |
Write a function to drop empty items from a given dictionary.
|
def drop_empty(dict1):
dict1 = {key:value for (key, value) in dict1.items() if value is not None}
return dict1
|
[] |
[
"assert drop_empty({'c1': 'Red', 'c2': 'Green', 'c3':None})=={'c1': 'Red', 'c2': 'Green'}",
"assert drop_empty({'c1': 'Red', 'c2': None, 'c3':None})=={'c1': 'Red'}",
"assert drop_empty({'c1': None, 'c2': 'Green', 'c3':None})=={ 'c2': 'Green'}"
] |
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"
] |
Benchmark Questions Verification V2.ipynb
| 253 |
Write a python function that returns the number of integer elements in a given list.
|
def count_integer(list1):
ctr = 0
for i in list1:
if isinstance(i, int):
ctr = ctr + 1
return ctr
|
[] |
[
"assert count_integer([1,2,'abc',1.2]) == 2",
"assert count_integer([1,2,3]) == 3",
"assert count_integer([1,1.2,4,5.1]) == 2"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 429 |
Write a function to extract the elementwise and tuples from the given two tuples.
|
def and_tuples(test_tup1, test_tup2):
res = tuple(ele1 & ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res)
|
[] |
[
"assert and_tuples((10, 4, 6, 9), (5, 2, 3, 3)) == (0, 0, 2, 1)",
"assert and_tuples((1, 2, 3, 4), (5, 6, 7, 8)) == (1, 2, 3, 0)",
"assert and_tuples((8, 9, 11, 12), (7, 13, 14, 17)) == (0, 9, 10, 0)"
] |
Benchmark Questions Verification V2.ipynb
| 280 |
Write a function that takes in an array and element and returns a tuple containing a boolean that indicates if the element is in the array and the index position of the element (or -1 if the element is not found).
|
def sequential_search(dlist, item):
pos = 0
found = False
while pos < len(dlist) and not found:
if dlist[pos] == item:
found = True
else:
pos = pos + 1
return found, pos
|
[] |
[
"assert sequential_search([11,23,58,31,56,77,43,12,65,19],31) == (True, 3)",
"assert sequential_search([12, 32, 45, 62, 35, 47, 44, 61],61) == (True, 7)",
"assert sequential_search([9, 10, 17, 19, 22, 39, 48, 56],48) == (True, 6)"
] |
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
| 455 |
Write a function to check whether the given month number contains 31 days or not.
|
def check_monthnumb_number(monthnum2):
if(monthnum2==1 or monthnum2==3 or monthnum2==5 or monthnum2==7 or monthnum2==8 or monthnum2==10 or monthnum2==12):
return True
else:
return False
|
[] |
[
"assert check_monthnumb_number(5)==True",
"assert check_monthnumb_number(2)==False",
"assert check_monthnumb_number(6)==False"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 475 |
Write a function to sort a dictionary by value.
|
from collections import Counter
def sort_counter(dict1):
x = Counter(dict1)
sort_counter=x.most_common()
return sort_counter
|
[] |
[
"assert sort_counter({'Math':81, 'Physics':83, 'Chemistry':87})==[('Chemistry', 87), ('Physics', 83), ('Math', 81)]",
"assert sort_counter({'Math':400, 'Physics':300, 'Chemistry':250})==[('Math', 400), ('Physics', 300), ('Chemistry', 250)]",
"assert sort_counter({'Math':900, 'Physics':1000, 'Chemistry':1250})==[('Chemistry', 1250), ('Physics', 1000), ('Math', 900)]"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 135 |
Write a function to find the nth hexagonal number.
|
def hexagonal_num(n):
return n*(2*n - 1)
|
[] |
[
"assert hexagonal_num(10) == 190",
"assert hexagonal_num(5) == 45",
"assert hexagonal_num(7) == 91"
] |
Benchmark Questions Verification V2.ipynb
| 226 |
Write a python function to remove the characters which have odd index values of a given string.
|
def odd_values_string(str):
result = ""
for i in range(len(str)):
if i % 2 == 0:
result = result + str[i]
return result
|
[] |
[
"assert odd_values_string('abcdef') == 'ace'",
"assert odd_values_string('python') == 'pto'",
"assert odd_values_string('data') == 'dt'",
"assert odd_values_string('lambs') == 'lms'"
] |
Benchmark Questions Verification V2.ipynb
| 256 |
Write a python function that takes in a non-negative number and returns the number of prime numbers less than the given non-negative number.
|
def count_Primes_nums(n):
ctr = 0
for num in range(n):
if num <= 1:
continue
for i in range(2,num):
if (num % i) == 0:
break
else:
ctr += 1
return ctr
|
[] |
[
"assert count_Primes_nums(5) == 2",
"assert count_Primes_nums(10) == 4",
"assert count_Primes_nums(100) == 25"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 87 |
Write a function to merge three dictionaries into a single dictionary.
|
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'}"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 451 |
Write a function to remove all whitespaces from the given string.
|
import re
def remove_whitespaces(text1):
return (re.sub(r'\s+', '',text1))
|
[] |
[
"assert remove_whitespaces(' Google Flutter ') == 'GoogleFlutter'",
"assert remove_whitespaces(' Google Dart ') == 'GoogleDart'",
"assert remove_whitespaces(' iOS Swift ') == 'iOSSwift'"
] |
Benchmark Questions Verification V2.ipynb
| 277 |
Write a function that takes in a dictionary and integer n and filters the dictionary to only include entries with values greater than or equal to n.
|
def dict_filter(dict,n):
result = {key:value for (key, value) in dict.items() if value >=n}
return result
|
[] |
[
"assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},170)=={'Cierra Vega': 175, 'Alden Cantrell': 180, 'Pierre Cox': 190}",
"assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},180)=={ 'Alden Cantrell': 180, 'Pierre Cox': 190}",
"assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},190)=={ 'Pierre Cox': 190}"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 432 |
Write a function to find the median length of a trapezium.
|
def median_trapezium(base1,base2,height):
median = 0.5 * (base1+ base2)
return median
|
[] |
[
"assert median_trapezium(15,25,35)==20",
"assert median_trapezium(10,20,30)==15",
"assert median_trapezium(6,9,4)==7.5"
] |
Benchmark Questions Verification V2.ipynb
| 272 |
Write a function that takes in a list of tuples and returns a list containing the rear element of each tuple.
|
def rear_extract(test_list):
res = [lis[-1] for lis in test_list]
return (res)
|
[] |
[
"assert rear_extract([(1, 'Rash', 21), (2, 'Varsha', 20), (3, 'Kil', 19)]) == [21, 20, 19]",
"assert rear_extract([(1, 'Sai', 36), (2, 'Ayesha', 25), (3, 'Salman', 45)]) == [36, 25, 45]",
"assert rear_extract([(1, 'Sudeep', 14), (2, 'Vandana', 36), (3, 'Dawood', 56)]) == [14, 36, 56]"
] |
Benchmark Questions Verification V2.ipynb
| 172 |
Write a function to count the number of occurence of the string 'std' in a given string.
|
def count_occurance(s):
count = 0
for i in range(len(s) - 2):
if (s[i] == 's' and s[i+1] == 't' and s[i+2] == 'd'):
count = count + 1
return count
|
[] |
[
"assert count_occurance(\"letstdlenstdporstd\") == 3",
"assert count_occurance(\"truststdsolensporsd\") == 1",
"assert count_occurance(\"makestdsostdworthit\") == 2",
"assert count_occurance(\"stds\") == 1",
"assert count_occurance(\"\") == 0"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 101 |
Write a function to find the kth element in the given array using 1-based indexing.
|
def kth_element(arr, k):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] == arr[j+1], arr[j]
return arr[k-1]
|
[] |
[
"assert kth_element([12,3,5,7,19], 2) == 3",
"assert kth_element([17,24,8,23], 3) == 8",
"assert kth_element([16,21,25,36,4], 4) == 36"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 424 |
Write a function to extract only the rear index element of each string in the given tuple.
|
def extract_rear(test_tuple):
res = list(sub[len(sub) - 1] for sub in test_tuple)
return (res)
|
[] |
[
"assert extract_rear(('Mers', 'for', 'Vers') ) == ['s', 'r', 's']",
"assert extract_rear(('Avenge', 'for', 'People') ) == ['e', 'r', 'e']",
"assert extract_rear(('Gotta', 'get', 'go') ) == ['a', 't', 'o']"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb
| 311 |
Write a python function to set the left most unset bit.
|
def set_left_most_unset_bit(n):
if not (n & (n + 1)):
return n
pos, temp, count = 0, n, 0
while temp:
if not (temp & 1):
pos = count
count += 1; temp>>=1
return (n | (1 << (pos)))
|
[] |
[
"assert set_left_most_unset_bit(10) == 14",
"assert set_left_most_unset_bit(12) == 14",
"assert set_left_most_unset_bit(15) == 15"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 437 |
Write a function to remove odd characters in a string.
|
def remove_odd(str1):
str2 = ''
for i in range(1, len(str1) + 1):
if(i % 2 == 0):
str2 = str2 + str1[i - 1]
return str2
|
[] |
[
"assert remove_odd(\"python\")==(\"yhn\")",
"assert remove_odd(\"program\")==(\"rga\")",
"assert remove_odd(\"language\")==(\"agae\")"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 108 |
Write a function to merge three lists into a single sorted list.
|
import heapq
def merge_sorted_list(num1,num2,num3):
num1=sorted(num1)
num2=sorted(num2)
num3=sorted(num3)
result = heapq.merge(num1,num2,num3)
return list(result)
|
[] |
[
"assert merge_sorted_list([25, 24, 15, 4, 5, 29, 110],[19, 20, 11, 56, 25, 233, 154],[24, 26, 54, 48])==[4, 5, 11, 15, 19, 20, 24, 24, 25, 25, 26, 29, 48, 54, 56, 110, 154, 233]",
"assert merge_sorted_list([1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12])==[1, 1, 2, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 11, 12]",
"assert merge_sorted_list([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1],[25, 35, 22, 85, 14, 65, 75, 25, 58],[12, 74, 9, 50, 61, 41])==[1, 2, 3, 4, 7, 8, 9, 9, 9, 10, 12, 14, 14, 18, 22, 25, 25, 35, 41, 50, 58, 61, 65, 74, 75, 85]"
] |
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']"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 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",
"assert opposite_Signs(-2,2) == True"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 142 |
Write a function to count number items that are identical in the same position of three given lists.
|
def count_samepair(list1,list2,list3):
result = sum(m == n == o for m, n, o in zip(list1,list2,list3))
return result
|
[] |
[
"assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,9],[2,1,3,1,2,6,7,9])==3",
"assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==4",
"assert count_samepair([1,2,3,4,2,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==5"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb
| 292 |
Write a python function to find quotient of two numbers (rounded down to the nearest integer).
|
def find(n,m):
q = n//m
return (q)
|
[] |
[
"assert find(10,3) == 3",
"assert find(4,2) == 2",
"assert find(20,5) == 4"
] |
Benchmark Questions Verification V2.ipynb
| 244 |
Write a python function to find the next perfect square greater than a given number.
|
import math
def next_Perfect_Square(N):
nextN = math.floor(math.sqrt(N)) + 1
return nextN * nextN
|
[] |
[
"assert next_Perfect_Square(35) == 36",
"assert next_Perfect_Square(6) == 9",
"assert next_Perfect_Square(9) == 16"
] |
Benchmark Questions Verification V2.ipynb
| 283 |
Write a python function takes in an integer and check whether the frequency of each digit in the integer is less than or equal to the digit itself.
|
def validate(n):
for i in range(10):
temp = n;
count = 0;
while (temp):
if (temp % 10 == i):
count+=1;
if (count > i):
return False
temp //= 10;
return True
|
[] |
[
"assert validate(1234) == True",
"assert validate(51241) == False",
"assert validate(321) == True"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 100 |
Write a function to find the next smallest palindrome of a specified integer, returned as an integer.
|
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"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 125 |
Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string.
|
def find_length(string):
n = len(string)
current_sum = 0
max_sum = 0
for i in range(n):
current_sum += (1 if string[i] == '0' else -1)
if current_sum < 0:
current_sum = 0
max_sum = max(current_sum, max_sum)
return max_sum if max_sum else 0
|
[] |
[
"assert find_length(\"11000010001\") == 6",
"assert find_length(\"10111\") == 1",
"assert find_length(\"11011101100101\") == 2"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 84 |
Write a function to find the nth number in the 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"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 91 |
Write a function to check if a string is present as a substring 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"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 137 |
Write a function to find the ratio of zeroes to non-zeroes in an array of integers.
|
from array import array
def zero_count(nums):
n = len(nums)
n1 = 0
for x in nums:
if x == 0:
n1 += 1
else:
None
return n1/(n-n1)
|
[
"import math"
] |
[
"assert math.isclose(zero_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8]), 0.181818, rel_tol=0.001)",
"assert math.isclose(zero_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8]), 0.00, rel_tol=0.001)",
"assert math.isclose(zero_count([2, 4, -6, -9, 11, -12, 14, -5, 17]), 0.00, rel_tol=0.001)"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 439 |
Write a function to join a list of multiple integers into a single integer.
|
def multiple_to_single(L):
x = int("".join(map(str, L)))
return x
|
[] |
[
"assert multiple_to_single([11, 33, 50])==113350",
"assert multiple_to_single([-1,2,3,4,5,6])==-123456",
"assert multiple_to_single([10,15,20,25])==10152025"
] |
Benchmark Questions Verification V2.ipynb
| 284 |
Write a function that takes in a list and element and checks whether all items in the list are equal to the given element.
|
def check_element(list,element):
check_element=all(v== element for v in list)
return check_element
|
[] |
[
"assert check_element([\"green\", \"orange\", \"black\", \"white\"],'blue')==False",
"assert check_element([1,2,3,4],7)==False",
"assert check_element([\"green\", \"green\", \"green\", \"green\"],'green')==True"
] |
Benchmark Questions Verification V2.ipynb
| 260 |
Write a function to find the nth newman–shanks–williams prime number.
|
def newman_prime(n):
if n == 0 or n == 1:
return 1
return 2 * newman_prime(n - 1) + newman_prime(n - 2)
|
[] |
[
"assert newman_prime(3) == 7",
"assert newman_prime(4) == 17",
"assert newman_prime(5) == 41"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 118 |
Write a function to convert a string to a list of strings split on the space character.
|
def string_to_list(string):
lst = list(string.split(" "))
return lst
|
[] |
[
"assert string_to_list(\"python programming\")==['python','programming']",
"assert string_to_list(\"lists tuples strings\")==['lists','tuples','strings']",
"assert string_to_list(\"write a program\")==['write','a','program']"
] |
Benchmark Questions Verification V2.ipynb
| 240 |
Write a function that takes in two lists and replaces the last element of the first list with the elements of the second list.
|
def replace_list(list1,list2):
list1[-1:] = list2
replace_list=list1
return replace_list
|
[] |
[
"assert replace_list([1, 3, 5, 7, 9, 10],[2, 4, 6, 8])==[1, 3, 5, 7, 9, 2, 4, 6, 8]",
"assert replace_list([1,2,3,4,5],[5,6,7,8])==[1,2,3,4,5,6,7,8]",
"assert replace_list([\"red\",\"blue\",\"green\"],[\"yellow\"])==[\"red\",\"blue\",\"yellow\"]"
] |
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)"
] |
Benchmark Questions Verification V2.ipynb
| 279 |
Write a function to find the nth decagonal number.
|
def is_num_decagonal(n):
return 4 * n * n - 3 * n
|
[] |
[
"assert is_num_decagonal(3) == 27",
"assert is_num_decagonal(7) == 175",
"assert is_num_decagonal(10) == 370"
] |
Benchmark Questions Verification V2.ipynb
| 247 |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n+1):
for i in range(n-cl+1):
j = i+cl-1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i+1][j-1] + 2
else:
L[i][j] = max(L[i][j-1], L[i+1][j]);
return L[0][n-1]
|
[] |
[
"assert lps(\"TENS FOR TENS\") == 5",
"assert lps(\"CARDIO FOR CARDS\") == 7",
"assert lps(\"PART OF THE JOURNEY IS PART\") == 9"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 132 |
Write a function to convert a tuple to a string.
|
def tup_string(tup1):
str = ''.join(tup1)
return str
|
[] |
[
"assert tup_string(('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's'))==(\"exercises\")",
"assert tup_string(('p','y','t','h','o','n'))==(\"python\")",
"assert tup_string(('p','r','o','g','r','a','m'))==(\"program\")"
] |
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'"
] |
Ellen's Copy of Benchmark Questions Verification V2.ipynb
| 308 |
Write a function to find the specified number of largest products from two given lists, selecting one factor from each list.
|
def large_product(nums1, nums2, N):
result = sorted([x*y for x in nums1 for y in nums2], reverse=True)[:N]
return result
|
[] |
[
"assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],3)==[60, 54, 50]",
"assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],4)==[60, 54, 50, 48]",
"assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],5)==[60, 54, 50, 48, 45]"
] |
Mike's Copy of Benchmark Questions Verification V2.ipynb
| 143 |
Write a function to find number of lists present in the given tuple.
|
def find_lists(Input):
if isinstance(Input, list):
return 1
else:
return len(Input)
|
[] |
[
"assert find_lists(([1, 2, 3, 4], [5, 6, 7, 8])) == 2",
"assert find_lists(([1, 2], [3, 4], [5, 6])) == 3",
"assert find_lists(([9, 8, 7, 6, 5, 4, 3, 2, 1])) == 1"
] |
charlessutton@: Benchmark Questions Verification V2.ipynb
| 444 |
Write a function to trim each tuple by k in the given tuple list.
|
def trim_tuple(test_list, K):
res = []
for ele in test_list:
N = len(ele)
res.append(tuple(list(ele)[K: N - K]))
return (str(res))
|
[] |
[
"assert trim_tuple([(5, 3, 2, 1, 4), (3, 4, 9, 2, 1),(9, 1, 2, 3, 5), (4, 8, 2, 1, 7)], 2) == '[(2,), (9,), (2,), (2,)]'",
"assert trim_tuple([(5, 3, 2, 1, 4), (3, 4, 9, 2, 1), (9, 1, 2, 3, 5), (4, 8, 2, 1, 7)], 1) == '[(3, 2, 1), (4, 9, 2), (1, 2, 3), (8, 2, 1)]'",
"assert trim_tuple([(7, 8, 4, 9), (11, 8, 12, 4),(4, 1, 7, 8), (3, 6, 9, 7)], 1) == '[(8, 4), (8, 12), (1, 7), (6, 9)]'"
] |
Benchmark Questions Verification V2.ipynb
| 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"
] |
Benchmark Questions Verification V2.ipynb
| 250 |
Write a python function that takes in a tuple and an element and counts the occcurences of the element in the tuple.
|
def count_X(tup, x):
count = 0
for ele in tup:
if (ele == x):
count = count + 1
return count
|
[] |
[
"assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),4) == 0",
"assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),10) == 3",
"assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),8) == 4"
] |
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]"
] |
Benchmark Questions Verification V2.ipynb
| 269 |
Write a function to find the ascii value of a character.
|
def ascii_value(k):
ch=k
return ord(ch)
|
[] |
[
"assert ascii_value('A')==65",
"assert ascii_value('R')==82",
"assert ascii_value('S')==83"
] |
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"
] |
End of preview. Expand
in Data Studio
README.md exists but content is empty.
- Downloads last month
- 127