source_file
stringclasses 1
value | task_id
int64 602
809
| prompt
stringlengths 40
410
| code
stringlengths 47
500
| test_imports
listlengths 0
0
| test_list
listlengths 3
7
|
|---|---|---|---|---|---|
Benchmark Questions Verification V2.ipynb
| 632
|
Write a python function to move all zeroes to the end of the given list.
|
def move_zero(num_list):
a = [0 for i in range(num_list.count(0))]
x = [i for i in num_list if i != 0]
return x + a
|
[] |
[
"assert move_zero([1,0,2,0,3,4]) == [1,2,3,4,0,0]",
"assert move_zero([2,3,2,0,0,4,0,5,0]) == [2,3,2,4,5,0,0,0,0]",
"assert move_zero([0,1,0,1,1]) == [1,1,1,0,0]"
] |
Benchmark Questions Verification V2.ipynb
| 796
|
Write function to find the sum of all items in the given dictionary.
|
def return_sum(dict):
sum = 0
for i in dict.values():
sum = sum + i
return sum
|
[] |
[
"assert return_sum({'a': 100, 'b':200, 'c':300}) == 600",
"assert return_sum({'a': 25, 'b':18, 'c':45}) == 88",
"assert return_sum({'a': 36, 'b':39, 'c':49}) == 124"
] |
Benchmark Questions Verification V2.ipynb
| 807
|
Write a python function to find the first odd number in a given list of numbers.
|
def first_odd(nums):
first_odd = next((el for el in nums if el%2!=0),-1)
return first_odd
|
[] |
[
"assert first_odd([1,3,5]) == 1",
"assert first_odd([2,4,1,3]) == 1",
"assert first_odd ([8,9,1]) == 9"
] |
Benchmark Questions Verification V2.ipynb
| 606
|
Write a function to convert degrees to radians.
|
import math
def radian_degree(degree):
radian = degree*(math.pi/180)
return radian
|
[] |
[
"assert radian_degree(90)==1.5707963267948966",
"assert radian_degree(60)==1.0471975511965976",
"assert radian_degree(120)==2.0943951023931953"
] |
Benchmark Questions Verification V2.ipynb
| 739
|
Write a python function to find the index of smallest triangular number with n digits. https://www.geeksforgeeks.org/index-of-smallest-triangular-number-with-n-digits/
|
import math
def find_Index(n):
x = math.sqrt(2 * math.pow(10,(n - 1)))
return round(x)
|
[] |
[
"assert find_Index(2) == 4",
"assert find_Index(3) == 14",
"assert find_Index(4) == 45"
] |
Benchmark Questions Verification V2.ipynb
| 760
|
Write a python function to check whether a list of numbers contains only one distinct element or not.
|
def unique_Element(arr):
s = set(arr)
return len(s) == 1
|
[] |
[
"assert unique_Element([1,1,1]) == True",
"assert unique_Element([1,2,1,2]) == False",
"assert unique_Element([1,2,3,4,5]) == False"
] |
Benchmark Questions Verification V2.ipynb
| 615
|
Write a function which takes a tuple of tuples and returns the average value for each tuple as a list.
|
def average_tuple(nums):
result = [sum(x) / len(x) for x in zip(*nums)]
return result
|
[] |
[
"assert average_tuple(((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4)))==[30.5, 34.25, 27.0, 23.25]",
"assert average_tuple(((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3)))== [25.5, -18.0, 3.75]",
"assert average_tuple( ((100, 100, 100, 120), (300, 450, 560, 450), (810, 800, 390, 320), (10, 20, 30, 40)))==[305.0, 342.5, 270.0, 232.5]"
] |
Benchmark Questions Verification V2.ipynb
| 754
|
We say that an element is common for lists l1, l2, l3 if it appears in all three lists under the same index. Write a function to find common elements from three lists. The function should return a list.
|
def extract_index_list(l1, l2, l3):
result = []
for m, n, o in zip(l1, l2, l3):
if (m == n == o):
result.append(m)
return result
|
[] |
[
"assert extract_index_list([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7])==[1, 7]",
"assert extract_index_list([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 6, 5],[0, 1, 2, 3, 4, 6, 7])==[1, 6]",
"assert extract_index_list([1, 1, 3, 4, 6, 5, 6],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7])==[1, 5]",
"assert extract_index_list([1, 2, 3, 4, 6, 6, 6],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7])==[]"
] |
Benchmark Questions Verification V2.ipynb
| 801
|
Write a python function to count the number of equal numbers from three given integers.
|
def test_three_equal(x,y,z):
result = set([x,y,z])
if len(result)==3:
return 0
else:
return 4-len(result)
|
[] |
[
"assert test_three_equal(1,1,1) == 3",
"assert test_three_equal(-1,-2,-3) == 0",
"assert test_three_equal(1,2,2) == 2"
] |
Benchmark Questions Verification V2.ipynb
| 773
|
Write a function to find the occurrence and position of the substrings within a string. Return None if there is no match.
|
import re
def occurance_substring(text,pattern):
for match in re.finditer(pattern, text):
s = match.start()
e = match.end()
return (text[s:e], s, e)
|
[] |
[
"assert occurance_substring('python programming, python language','python')==('python', 0, 6)",
"assert occurance_substring('python programming,programming language','programming')==('programming', 7, 18)",
"assert occurance_substring('python programming,programming language','language')==('language', 31, 39)",
"assert occurance_substring('c++ programming, c++ language','python')==None"
] |
Benchmark Questions Verification V2.ipynb
| 617
|
Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane.
|
def min_Jumps(steps, d):
(a, b) = steps
temp = a
a = min(a, b)
b = max(temp, b)
if (d >= b):
return (d + b - 1) / b
if (d == 0):
return 0
if (d == a):
return 1
else:
return 2
|
[] |
[
"assert min_Jumps((3,4),11)==3.5",
"assert min_Jumps((3,4),0)==0",
"assert min_Jumps((11,14),11)==1"
] |
Benchmark Questions Verification V2.ipynb
| 806
|
Write a function to find maximum run of uppercase characters in the given string.
|
def max_run_uppercase(test_str):
cnt = 0
res = 0
for idx in range(0, len(test_str)):
if test_str[idx].isupper():
cnt += 1
else:
res = cnt
cnt = 0
if test_str[len(test_str) - 1].isupper():
res = cnt
return (res)
|
[] |
[
"assert max_run_uppercase('GeMKSForGERksISBESt') == 5",
"assert max_run_uppercase('PrECIOusMOVemENTSYT') == 6",
"assert max_run_uppercase('GooGLEFluTTER') == 4"
] |
Benchmark Questions Verification V2.ipynb
| 622
|
Write a function to find the median of two sorted lists of same size.
|
def get_median(arr1, arr2, n):
i = 0
j = 0
m1 = -1
m2 = -1
count = 0
while count < n + 1:
count += 1
if i == n:
m1 = m2
m2 = arr2[0]
break
elif j == n:
m1 = m2
m2 = arr1[0]
break
if arr1[i] <= arr2[j]:
m1 = m2
m2 = arr1[i]
i += 1
else:
m1 = m2
m2 = arr2[j]
j += 1
return (m1 + m2)/2
|
[] |
[
"assert get_median([1, 12, 15, 26, 38], [2, 13, 17, 30, 45], 5) == 16.0",
"assert get_median([2, 4, 8, 9], [7, 13, 19, 28], 4) == 8.5",
"assert get_median([3, 6, 14, 23, 36, 42], [2, 18, 27, 39, 49, 55], 6) == 25.0"
] |
Benchmark Questions Verification V2.ipynb
| 633
|
Write a python function to find the sum of xor of all pairs of numbers in the given list.
|
def pair_xor_Sum(arr,n) :
ans = 0
for i in range(0,n) :
for j in range(i + 1,n) :
ans = ans + (arr[i] ^ arr[j])
return ans
|
[] |
[
"assert pair_xor_Sum([5,9,7,6],4) == 47",
"assert pair_xor_Sum([7,3,5],3) == 12",
"assert pair_xor_Sum([7,3],2) == 4"
] |
Benchmark Questions Verification V2.ipynb
| 638
|
Write a function to calculate the wind chill index rounded to the next integer given the wind velocity in km/h and a temperature in celsius.
|
import math
def wind_chill(v,t):
windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16)
return int(round(windchill, 0))
|
[] |
[
"assert wind_chill(120,35)==40",
"assert wind_chill(40,20)==19",
"assert wind_chill(10,8)==6"
] |
Benchmark Questions Verification V2.ipynb
| 643
|
Write a function that checks if a strings contains 'z', except at the start and end of the word.
|
import re
def text_match_wordz_middle(text):
return bool(re.search(r'\Bz\B', text))
|
[] |
[
"assert text_match_wordz_middle(\"pythonzabc.\")==True",
"assert text_match_wordz_middle(\"zxyabc.\")==False",
"assert text_match_wordz_middle(\" lang .\")==False"
] |
Benchmark Questions Verification V2.ipynb
| 782
|
Write a python function to find the sum of all odd length subarrays. https://www.geeksforgeeks.org/sum-of-all-odd-length-subarrays/
|
def odd_length_sum(arr):
Sum = 0
l = len(arr)
for i in range(l):
Sum += ((((i + 1) *(l - i) + 1) // 2) * arr[i])
return Sum
|
[] |
[
"assert odd_length_sum([1,2,4]) == 14",
"assert odd_length_sum([1,2,1,2]) == 15",
"assert odd_length_sum([1,7]) == 8"
] |
Benchmark Questions Verification V2.ipynb
| 605
|
Write a function to check if the given integer is a prime number.
|
def prime_num(num):
if num >=1:
for i in range(2, num//2):
if (num % i) == 0:
return False
else:
return True
else:
return False
|
[] |
[
"assert prime_num(13)==True",
"assert prime_num(7)==True",
"assert prime_num(-1010)==False"
] |
Benchmark Questions Verification V2.ipynb
| 618
|
Write a function to divide two lists element wise.
|
def div_list(nums1,nums2):
result = map(lambda x, y: x / y, nums1, nums2)
return list(result)
|
[] |
[
"assert div_list([4,5,6],[1, 2, 3])==[4.0,2.5,2.0]",
"assert div_list([3,2],[1,4])==[3.0, 0.5]",
"assert div_list([90,120],[50,70])==[1.8, 1.7142857142857142]"
] |
Benchmark Questions Verification V2.ipynb
| 767
|
Write a python function to count the number of pairs whose sum is equal to ‘sum’. The funtion gets as input a list of numbers and the sum,
|
def get_pairs_count(arr, sum):
count = 0
for i in range(len(arr)):
for j in range(i + 1,len(arr)):
if arr[i] + arr[j] == sum:
count += 1
return count
|
[] |
[
"assert get_pairs_count([1,1,1,1],2) == 6",
"assert get_pairs_count([1,5,7,-1,5],6) == 3",
"assert get_pairs_count([1,-2,3],1) == 1",
"assert get_pairs_count([-1,-2,3],-3) == 1"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.