entry_func
stringlengths 3
31
| solution
stringlengths 35
720
| task_name
stringclasses 1
value | doc_string
stringclasses 1
value | compare_func
sequencelengths 0
0
| tgt_lang
stringclasses 1
value | suffix
stringclasses 1
value | import_str
sequencelengths 0
1
| src_lang
null | demos
sequencelengths 0
0
| test_cases
sequencelengths 0
5
| data_id
int64 11
479
| prefix
stringlengths 39
252
| dataset_name
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
min_of_three | 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 | code_generation | [] | python | [] | null | [] | [
[
"10,20,0",
"0"
],
[
"19,15,18",
"15"
],
[
"-10,-20,-30",
"-30"
]
] | 227 | Write a function to find minimum of three numbers. | MBPP_sanitized |
||
all_Bits_Set_In_The_Given_Range | 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 | code_generation | [] | python | [] | null | [] | [
[
"4,1,2",
"True"
],
[
"17,2,4",
"True"
],
[
"39,4,6",
"False"
]
] | 228 | Write a python function to check whether all the bits are unset in the given range or not. | MBPP_sanitized |
||
re_arrange_array | 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 | code_generation | [] | python | [] | null | [] | [
[
"[-1, 2, -3, 4, 5, 6, -7, 8, 9], 9",
"[-1, -3, -7, 4, 5, 6, 2, 8, 9]"
],
[
"[12, -14, -26, 13, 15], 5",
"[-14, -26, 12, 13, 15]"
],
[
"[10, 24, 36, -42, -39, -78, 85], 7",
"[-42, -39, -78, 10, 24, 36, 85]"
]
] | 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. | MBPP_sanitized |
||
replace_blank | def replace_blank(str1, char):
str2 = str1.replace(' ', char)
return str2 | code_generation | [] | python | [] | null | [] | [
[
"\"hello people\",'@'",
"(\"hello@people\")"
],
[
"\"python program language\",'$'",
"(\"python$program$language\")"
],
[
"\"blank space\",\"-\"",
"(\"blank-space\")"
]
] | 230 | Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string. | MBPP_sanitized |
||
larg_nnum | import heapq
def larg_nnum(list1, n):
largest = heapq.nlargest(n, list1)
return largest | code_generation | [] | python | [
"import heapq"
] | null | [] | [
[
"[10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2",
"set([100,90])"
],
[
"[10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5",
"set([100,90,80,70,60])"
],
[
"[10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3",
"set([100,90,80])"
]
] | 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. | MBPP_sanitized |
||
lateralsuface_cylinder | def lateralsuface_cylinder(r, h):
lateralsurface = 2 * 3.1415 * r * h
return lateralsurface | code_generation | [] | python | [] | null | [] | [] | 233 | Write a function to find the lateral surface area of a cylinder. | MBPP_sanitized |
||
volume_cube | def volume_cube(l):
volume = l * l * l
return volume | code_generation | [] | python | [] | null | [] | [
[
"3",
"27"
],
[
"2",
"8"
],
[
"5",
"125"
]
] | 234 | Write a function to find the volume of a cube given its side length. | MBPP_sanitized |
||
even_bit_set_number | def even_bit_set_number(n):
count = 0
res = 0
temp = n
while temp > 0:
if count % 2 == 1:
res |= 1 << count
count += 1
temp >>= 1
return n | res | code_generation | [] | python | [] | null | [] | [
[
"10",
"10"
],
[
"20",
"30"
],
[
"30",
"30"
]
] | 235 | Write a python function to set all even bits of a given number. | MBPP_sanitized |
||
check_occurences | from collections import Counter
def check_occurences(test_list):
res = dict(Counter((tuple(ele) for ele in map(sorted, test_list))))
return res | code_generation | [] | python | [
"from collections import Counter "
] | null | [] | [
[
"[(3, 1), (1, 3), (2, 5), (5, 2), (6, 3)] ",
"{(1, 3): 2, (2, 5): 2, (3, 6): 1}"
],
[
"[(4, 2), (2, 4), (3, 6), (6, 3), (7, 4)] ",
"{(2, 4): 2, (3, 6): 2, (4, 7): 1}"
],
[
"[(13, 2), (11, 23), (12, 25), (25, 12), (16, 23)] ",
"{(2, 13): 1, (11, 23): 1, (12, 25): 2, (16, 23): 1}"
]
] | 237 | Write a function that takes in a list of tuples and returns a dictionary mapping each unique tuple to the number of times it occurs in the list. | MBPP_sanitized |
||
number_of_substrings | def number_of_substrings(str):
str_len = len(str)
return int(str_len * (str_len + 1) / 2) | code_generation | [] | python | [] | null | [] | [
[
"\"abc\"",
"6"
],
[
"\"abcd\"",
"10"
],
[
"\"abcde\"",
"15"
]
] | 238 | Write a python function to count the number of non-empty substrings of a given string. | MBPP_sanitized |
||
get_total_number_of_sequences | 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] | code_generation | [] | python | [] | null | [] | [
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] | 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. | MBPP_sanitized |
||
replace_list | def replace_list(list1, list2):
list1[-1:] = list2
replace_list = list1
return replace_list | code_generation | [] | python | [] | null | [] | [
[
"[1, 3, 5, 7, 9, 10],[2, 4, 6, 8]",
"[1, 3, 5, 7, 9, 2, 4, 6, 8]"
],
[
"[1,2,3,4,5],[5,6,7,8]",
"[1,2,3,4,5,6,7,8]"
],
[
"[\"red\",\"blue\",\"green\"],[\"yellow\"]",
"[\"red\",\"blue\",\"yellow\"]"
]
] | 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. | MBPP_sanitized |
||
count_charac | def count_charac(str1):
total = 0
for i in str1:
total = total + 1
return total | code_generation | [] | python | [] | null | [] | [
[
"\"python programming\"",
"18"
],
[
"\"language\"",
"8"
],
[
"\"words\"",
"5"
]
] | 242 | Write a function to count the total number of characters in a string. | MBPP_sanitized |
||
next_Perfect_Square | import math
def next_Perfect_Square(N):
nextN = math.floor(math.sqrt(N)) + 1
return nextN * nextN | code_generation | [] | python | [
"import math "
] | null | [] | [
[
"35",
"36"
],
[
"6",
"9"
],
[
"9",
"16"
]
] | 244 | Write a python function to find the next perfect square greater than a given number. | MBPP_sanitized |
||
max_sum | def max_sum(arr):
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum | code_generation | [] | python | [] | null | [] | [
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] | 245 | Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. | MBPP_sanitized |
||
babylonian_squareroot | 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 | code_generation | [] | python | [] | null | [] | [] | 246 | Write a function for computing square roots using the babylonian method. | MBPP_sanitized |
||
lps | 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] | code_generation | [] | python | [] | null | [] | [
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] | 247 | Write a function to find the length of the longest palindromic subsequence in the given string. | MBPP_sanitized |
||
harmonic_sum | def harmonic_sum(n):
if n < 2:
return 1
else:
return 1 / n + harmonic_sum(n - 1) | code_generation | [] | python | [] | null | [] | [] | 248 | Write a function that takes in an integer n and calculates the harmonic sum of n-1. | MBPP_sanitized |
||
intersection_array | def intersection_array(array_nums1, array_nums2):
result = list(filter(lambda x: x in array_nums1, array_nums2))
return result | code_generation | [] | python | [] | null | [] | [
[
"[1, 2, 3, 5, 7, 8, 9, 10],[1, 2, 4, 8, 9]",
"[1, 2, 8, 9]"
],
[
"[1, 2, 3, 5, 7, 8, 9, 10],[3,5,7,9]",
"[3,5,7,9]"
],
[
"[1, 2, 3, 5, 7, 8, 9, 10],[10,20,30,40]",
"[10]"
]
] | 249 | Write a function to find the intersection of two arrays. | MBPP_sanitized |
||
count_X | def count_X(tup, x):
count = 0
for ele in tup:
if ele == x:
count = count + 1
return count | code_generation | [] | python | [] | null | [] | [
[
"(10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),4",
"0"
],
[
"(10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),10",
"3"
],
[
"(10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),8",
"4"
]
] | 250 | Write a python function that takes in a tuple and an element and counts the occcurences of the element in the tuple. | MBPP_sanitized |
||
insert_element | def insert_element(list, element):
list = [v for elt in list for v in (element, elt)]
return list | code_generation | [] | python | [] | null | [] | [
[
"['Red', 'Green', 'Black'] ,'c'",
"['c', 'Red', 'c', 'Green', 'c', 'Black']"
],
[
"['python', 'java'] ,'program'",
"['program', 'python', 'program', 'java']"
],
[
"['happy', 'sad'] ,'laugh'",
"['laugh', 'happy', 'laugh', 'sad']"
]
] | 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. | MBPP_sanitized |
||
convert | import cmath
def convert(numbers):
num = cmath.polar(numbers)
return num | code_generation | [] | python | [
"import cmath "
] | null | [] | [
[
"1",
"(1.0, 0.0)"
],
[
"4",
"(4.0,0.0)"
],
[
"5",
"(5.0,0.0)"
]
] | 252 | Write a python function to convert complex numbers to polar coordinates. | MBPP_sanitized |
||
count_integer | def count_integer(list1):
ctr = 0
for i in list1:
if isinstance(i, int):
ctr = ctr + 1
return ctr | code_generation | [] | python | [] | null | [] | [
[
"[1,2,'abc',1.2]",
"2"
],
[
"[1,2,3]",
"3"
],
[
"[1,1.2,4,5.1]",
"2"
]
] | 253 | Write a python function that returns the number of integer elements in a given list. | MBPP_sanitized |
||
combinations_colors | from itertools import combinations_with_replacement
def combinations_colors(l, n):
return list(combinations_with_replacement(l, n)) | code_generation | [] | python | [
"from itertools import combinations_with_replacement "
] | null | [] | [
[
" [\"Red\",\"Green\",\"Blue\"],1",
"[('Red',), ('Green',), ('Blue',)]"
],
[
" [\"Red\",\"Green\",\"Blue\"],2",
"[('Red', 'Red'), ('Red', 'Green'), ('Red', 'Blue'), ('Green', 'Green'), ('Green', 'Blue'), ('Blue', 'Blue')]"
],
[
" [\"Red\",\"Green\",\"Blue\"],3",
"[('Red', 'Red', 'Red'), ('Red', 'Red', 'Green'), ('Red', 'Red', 'Blue'), ('Red', 'Green', 'Green'), ('Red', 'Green', 'Blue'), ('Red', 'Blue', 'Blue'), ('Green', 'Green', 'Green'), ('Green', 'Green', 'Blue'), ('Green', 'Blue', 'Blue'), ('Blue', 'Blue', 'Blue')]"
]
] | 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. | MBPP_sanitized |
||
count_Primes_nums | 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 | code_generation | [] | python | [] | null | [] | [
[
"5",
"2"
],
[
"10",
"4"
],
[
"100",
"25"
]
] | 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. | MBPP_sanitized |
||
swap_numbers | def swap_numbers(a, b):
temp = a
a = b
b = temp
return (a, b) | code_generation | [] | python | [] | null | [] | [
[
"10,20",
"(20,10)"
],
[
"15,17",
"(17,15)"
],
[
"100,200",
"(200,100)"
]
] | 257 | Write a function that takes in two numbers and returns a tuple with the second number and then the first number. | MBPP_sanitized |
||
maximize_elements | 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 | code_generation | [] | python | [] | null | [] | [
[
"((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))",
"((6, 7), (4, 9), (2, 9), (7, 10))"
],
[
"((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))",
"((7, 8), (5, 10), (3, 10), (8, 11))"
],
[
"((3, 5), (6, 7), (4, 11), (3, 12)), ((8, 9), (5, 11), (3, 3), (9, 5))",
"((8, 9), (6, 11), (4, 11), (9, 12))"
]
] | 259 | Write a function to maximize the given two tuples. | MBPP_sanitized |
||
newman_prime | def newman_prime(n):
if n == 0 or n == 1:
return 1
return 2 * newman_prime(n - 1) + newman_prime(n - 2) | code_generation | [] | python | [] | null | [] | [
[
"3",
"7"
],
[
"4",
"17"
],
[
"5",
"41"
]
] | 260 | Write a function to find the nth newman–shanks–williams prime number. | MBPP_sanitized |
||
division_elements | def division_elements(test_tup1, test_tup2):
res = tuple((ele1 // ele2 for (ele1, ele2) in zip(test_tup1, test_tup2)))
return res | code_generation | [] | python | [] | null | [] | [
[
"(10, 4, 6, 9),(5, 2, 3, 3)",
"(2, 2, 2, 3)"
],
[
"(12, 6, 8, 16),(6, 3, 4, 4)",
"(2, 2, 2, 4)"
],
[
"(20, 14, 36, 18),(5, 7, 6, 9)",
"(4, 2, 6, 2)"
]
] | 261 | Write a function that takes in two tuples and performs mathematical division operation element-wise across the given tuples. | MBPP_sanitized |
||
split_two_parts | def split_two_parts(list1, L):
return (list1[:L], list1[L:]) | code_generation | [] | python | [] | null | [] | [
[
"[1,1,2,3,4,4,5,1],3",
"([1, 1, 2], [3, 4, 4, 5, 1])"
],
[
"['a', 'b', 'c', 'd'],2",
"(['a', 'b'], ['c', 'd'])"
],
[
"['p', 'y', 't', 'h', 'o', 'n'],4",
"(['p', 'y', 't', 'h'], ['o', 'n'])"
]
] | 262 | Write a function that takes in a list and an integer L and splits the given list into two parts where the length of the first part of the list is L, and returns the resulting lists in a tuple. | MBPP_sanitized |
||
dog_age | 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 | code_generation | [] | python | [] | null | [] | [
[
"12",
"61"
],
[
"15",
"73"
],
[
"24",
"109"
]
] | 264 | Write a function to calculate a dog's age in dog's years. | MBPP_sanitized |
||
list_split | def list_split(S, step):
return [S[i::step] for i in range(step)] | code_generation | [] | python | [] | null | [] | [
[
"['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']]"
],
[
"[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]]"
],
[
"['python','java','C','C++','DBMS','SQL'],2",
"[['python', 'C', 'DBMS'], ['java', 'C++', 'SQL']]"
]
] | 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. | MBPP_sanitized |
||
lateralsurface_cube | def lateralsurface_cube(l):
LSA = 4 * (l * l)
return LSA | code_generation | [] | python | [] | null | [] | [
[
"5",
"100"
],
[
"9",
"324"
],
[
"10",
"400"
]
] | 266 | Write a function to find the lateral surface area of a cube given its side length. | MBPP_sanitized |
||
square_Sum | def square_Sum(n):
return int(n * (4 * n * n - 1) / 3) | code_generation | [] | python | [] | null | [] | [
[
"2",
"10"
],
[
"3",
"35"
],
[
"4",
"84"
]
] | 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. | MBPP_sanitized |
||
find_star_num | def find_star_num(n):
return 6 * n * (n - 1) + 1 | code_generation | [] | python | [] | null | [] | [
[
"3",
"37"
],
[
"4",
"73"
],
[
"5",
"121"
]
] | 268 | Write a function to find the n'th star number. | MBPP_sanitized |
||
ascii_value | def ascii_value(k):
ch = k
return ord(ch) | code_generation | [] | python | [] | null | [] | [
[
"'A'",
"65"
],
[
"'R'",
"82"
],
[
"'S'",
"83"
]
] | 269 | Write a function to find the ascii value of a character. | MBPP_sanitized |
||
sum_even_and_even_index | 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 | code_generation | [] | python | [] | null | [] | [
[
"[5, 6, 12, 1, 18, 8]",
"30"
],
[
"[3, 20, 17, 9, 2, 10, 18, 13, 6, 18]",
"26"
],
[
"[5, 6, 12, 1]",
"12"
]
] | 270 | Write a python function to find the sum of even numbers at even positions of a list. | MBPP_sanitized |
||
even_Power_Sum | 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 | code_generation | [] | python | [] | null | [] | [
[
"2",
"1056"
],
[
"3",
"8832"
],
[
"1",
"32"
]
] | 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. | MBPP_sanitized |
||
rear_extract | def rear_extract(test_list):
res = [lis[-1] for lis in test_list]
return res | code_generation | [] | python | [] | null | [] | [
[
"[(1, 'Rash', 21), (2, 'Varsha', 20), (3, 'Kil', 19)]",
"[21, 20, 19]"
],
[
"[(1, 'Sai', 36), (2, 'Ayesha', 25), (3, 'Salman', 45)]",
"[36, 25, 45]"
],
[
"[(1, 'Sudeep', 14), (2, 'Vandana', 36), (3, 'Dawood', 56)]",
"[14, 36, 56]"
]
] | 272 | Write a function that takes in a list of tuples and returns a list containing the rear element of each tuple. | MBPP_sanitized |
||
substract_elements | def substract_elements(test_tup1, test_tup2):
res = tuple(map(lambda i, j: i - j, test_tup1, test_tup2))
return res | code_generation | [] | python | [] | null | [] | [
[
"(10, 4, 5), (2, 5, 18)",
"(8, -1, -13)"
],
[
"(11, 2, 3), (24, 45 ,16)",
"(-13, -43, -13)"
],
[
"(7, 18, 9), (10, 11, 12)",
"(-3, 7, -3)"
]
] | 273 | Write a function that takes in two tuples and subtracts the elements of the first tuple by the elements of the second tuple with the same index. | MBPP_sanitized |
||
even_binomial_Coeff_Sum | import math
def even_binomial_Coeff_Sum(n):
return 1 << n - 1 | code_generation | [] | python | [
"import math "
] | null | [] | [
[
"4",
"8"
],
[
"6",
"32"
],
[
"2",
"2"
]
] | 274 | Write a python function that takes in a positive integer n and finds the sum of even index binomial coefficients. | MBPP_sanitized |
||
volume_cylinder | def volume_cylinder(r, h):
volume = 3.1415 * r * r * h
return volume | code_generation | [] | python | [] | null | [] | [] | 276 | Write a function that takes in the radius and height of a cylinder and returns the the volume. | MBPP_sanitized |
||
dict_filter | def dict_filter(dict, n):
result = {key: value for (key, value) in dict.items() if value >= n}
return result | code_generation | [] | python | [] | null | [] | [
[
"{'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},170",
"{'Cierra Vega': 175, 'Alden Cantrell': 180, 'Pierre Cox': 190}"
],
[
"{'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},180",
"{ 'Alden Cantrell': 180, 'Pierre Cox': 190}"
],
[
"{'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},190",
"{ 'Pierre Cox': 190}"
]
] | 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. | MBPP_sanitized |
||
count_first_elements | def count_first_elements(test_tup):
for (count, ele) in enumerate(test_tup):
if isinstance(ele, tuple):
break
return count | code_generation | [] | python | [] | null | [] | [
[
"(1, 5, 7, (4, 6), 10) ",
"3"
],
[
"(2, 9, (5, 7), 11) ",
"2"
],
[
"(11, 15, 5, 8, (2, 3), 8) ",
"4"
]
] | 278 | Write a function to find the number of elements that occurs before the tuple element in the given tuple. | MBPP_sanitized |
||
is_num_decagonal | def is_num_decagonal(n):
return 4 * n * n - 3 * n | code_generation | [] | python | [] | null | [] | [
[
"3",
"27"
],
[
"7",
"175"
],
[
"10",
"370"
]
] | 279 | Write a function to find the nth decagonal number. | MBPP_sanitized |
||
sequential_search | 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) | code_generation | [] | python | [] | null | [] | [
[
"[11,23,58,31,56,77,43,12,65,19],31",
"(True, 3)"
],
[
"[12, 32, 45, 62, 35, 47, 44, 61],61",
"(True, 7)"
],
[
"[9, 10, 17, 19, 22, 39, 48, 56],48",
"(True, 6)"
]
] | 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). | MBPP_sanitized |
||
all_unique | def all_unique(test_list):
if len(test_list) > len(set(test_list)):
return False
return True | code_generation | [] | python | [] | null | [] | [
[
"[1,2,3]",
"True"
],
[
"[1,2,1,2]",
"False"
],
[
"[1,2,3,4,5]",
"True"
]
] | 281 | Write a python function to check if the elements of a given list are unique or not. | MBPP_sanitized |
||
sub_list | def sub_list(nums1, nums2):
result = map(lambda x, y: x - y, nums1, nums2)
return list(result) | code_generation | [] | python | [] | null | [] | [
[
"[1, 2, 3],[4,5,6]",
"[-3,-3,-3]"
],
[
"[1,2],[3,4]",
"[-2,-2]"
],
[
"[90,120],[50,70]",
"[40,50]"
]
] | 282 | Write a function to subtract two lists element-wise. | MBPP_sanitized |
||
validate | 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 | code_generation | [] | python | [] | null | [] | [
[
"1234",
"True"
],
[
"51241",
"False"
],
[
"321",
"True"
]
] | 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. | MBPP_sanitized |
||
check_element | def check_element(list, element):
check_element = all((v == element for v in list))
return check_element | code_generation | [] | python | [] | null | [] | [
[
"[\"green\", \"orange\", \"black\", \"white\"],'blue'",
"False"
],
[
"[1,2,3,4],7",
"False"
],
[
"[\"green\", \"green\", \"green\", \"green\"],'green'",
"True"
]
] | 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. | MBPP_sanitized |
||
text_match_two_three | import re
def text_match_two_three(text):
patterns = 'ab{2,3}'
if re.search(patterns, text):
return True
else:
return False | code_generation | [] | python | [
"import re"
] | null | [] | [
[
"\"ac\"",
"(False)"
],
[
"\"dc\"",
"(False)"
],
[
"\"abbbba\"",
"(True)"
]
] | 285 | Write a function that checks whether a string contains the 'a' character followed by two or three 'b' characters. | MBPP_sanitized |
||
max_sub_array_sum_repeated | def max_sub_array_sum_repeated(a, n, k):
max_so_far = -2147483648
max_ending_here = 0
for i in range(n * k):
max_ending_here = max_ending_here + a[i % n]
if max_so_far < max_ending_here:
max_so_far = max_ending_here
if max_ending_here < 0:
max_ending_here = 0
return max_so_far | code_generation | [] | python | [] | null | [] | [
[
"[10, 20, -30, -1], 4, 3",
"30"
],
[
"[-1, 10, 20], 3, 2",
"59"
],
[
"[-1, -2, -3], 3, 3",
"-1"
]
] | 286 | Write a function to find the largest sum of a contiguous array in the modified array which is formed by repeating the given array k times. | MBPP_sanitized |
||
square_Sum | def square_Sum(n):
return int(2 * n * (n + 1) * (2 * n + 1) / 3) | code_generation | [] | python | [] | null | [] | [
[
"2",
"20"
],
[
"3",
"56"
],
[
"4",
"120"
]
] | 287 | Write a python function takes in an integer n and returns the sum of squares of first n even natural numbers. | MBPP_sanitized |
||
max_length | 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) | code_generation | [] | python | [] | null | [] | [
[
"[[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]]",
"(3, [13, 15, 17])"
],
[
"[[1], [5, 7], [10, 12, 14,15]]",
"(4, [10, 12, 14,15])"
],
[
"[[5], [15,20,25]]",
"(3, [15,20,25])"
]
] | 290 | Write a function to find the list of maximum length in a list of lists. | MBPP_sanitized |
||
count_no_of_ways | def count_no_of_ways(n, k):
dp = [0] * (n + 1)
total = k
mod = 1000000007
dp[1] = k
dp[2] = k * k
for i in range(3, n + 1):
dp[i] = (k - 1) * (dp[i - 1] + dp[i - 2]) % mod
return dp[n] | code_generation | [] | python | [] | null | [] | [
[
"2, 4",
"16"
],
[
"3, 2",
"6"
],
[
"4, 4",
"228"
]
] | 291 | Write a function to find out the number of ways of painting the fence such that at most 2 adjacent posts have the same color for the given fence with n posts and k colors. | MBPP_sanitized |
||
find | def find(n, m):
q = n // m
return q | code_generation | [] | python | [] | null | [] | [
[
"10,3",
"3"
],
[
"4,2",
"2"
],
[
"20,5",
"4"
]
] | 292 | Write a python function to find quotient of two numbers (rounded down to the nearest integer). | MBPP_sanitized |
||
otherside_rightangle | import math
def otherside_rightangle(w, h):
s = math.sqrt(w * w + h * h)
return s | code_generation | [] | python | [
"import math"
] | null | [] | [
[
"7,8",
"10.63014581273465"
],
[
"3,4",
"5"
],
[
"7,15",
"16.55294535724685"
]
] | 293 | Write a function to find the third side of a right angled triangle. | MBPP_sanitized |
||
max_val | def max_val(listval):
max_val = max((i for i in listval if isinstance(i, int)))
return max_val | code_generation | [] | python | [] | null | [] | [
[
"['Python', 3, 2, 4, 5, 'version']",
"5"
],
[
"['Python', 15, 20, 25]",
"25"
],
[
"['Python', 30, 20, 40, 50, 'version']",
"50"
]
] | 294 | Write a function to find the maximum value in a given heterogeneous list. | MBPP_sanitized |
||
sum_div | def sum_div(number):
divisors = [1]
for i in range(2, number):
if number % i == 0:
divisors.append(i)
return sum(divisors) | code_generation | [] | python | [] | null | [] | [
[
"8",
"7"
],
[
"12",
"16"
],
[
"7",
"1"
]
] | 295 | Write a function to return the sum of all divisors of a number. | MBPP_sanitized |
||
get_Inv_Count | 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 | code_generation | [] | python | [] | null | [] | [
[
"[1,20,6,4,5]",
"5"
],
[
"[1,2,1]",
"1"
],
[
"[1,2,5,6,1]",
"3"
]
] | 296 | Write a python function to count inversions in an array. | MBPP_sanitized |
||
flatten_list | 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_list.append(next)
result_list.reverse()
return result_list | code_generation | [] | python | [] | null | [] | [
[
"[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]"
],
[
"[[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]]",
"[10, 20, 40, 30, 56, 25, 10, 20, 33, 40]"
],
[
"[[1,2,3], [4,5,6], [10,11,12], [7,8,9]]",
"[1, 2, 3, 4, 5, 6, 10, 11, 12, 7, 8, 9]"
]
] | 297 | Write a function to flatten a given nested list structure. | MBPP_sanitized |
||
max_aggregate | 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]) | code_generation | [] | python | [
"from collections import defaultdict"
] | null | [] | [
[
"[('Juan Whelan',90),('Sabah Colley',88),('Peter Nichols',7),('Juan Whelan',122),('Sabah Colley',84)]",
"('Juan Whelan', 212)"
],
[
"[('Juan Whelan',50),('Sabah Colley',48),('Peter Nichols',37),('Juan Whelan',22),('Sabah Colley',14)]",
"('Juan Whelan', 72)"
],
[
"[('Juan Whelan',10),('Sabah Colley',20),('Peter Nichols',30),('Juan Whelan',40),('Sabah Colley',50)]",
"('Sabah Colley', 70)"
]
] | 299 | Write a function to calculate the maximum aggregate from the list of tuples. | MBPP_sanitized |
||
count_binary_seq | 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 | code_generation | [] | python | [] | null | [] | [] | 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. | MBPP_sanitized |
||
dict_depth | def dict_depth(d):
if isinstance(d, dict):
return 1 + (max(map(dict_depth, d.values())) if d else 0)
return 0 | code_generation | [] | python | [] | null | [] | [
[
"{'a':1, 'b': {'c': {'d': {}}}}",
"4"
],
[
"{'a':1, 'b': {'c':'python'}}",
"2"
],
[
"{1: 'Sun', 2: {3: {4:'Mon'}}}",
"3"
]
] | 301 | Write a function to find the depth of a dictionary. | MBPP_sanitized |
||
find_Element | 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
return arr[index] | code_generation | [] | python | [] | null | [] | [
[
"[1,2,3,4,5],[[0,2],[0,3]],2,1",
"3"
],
[
"[1,2,3,4],[[0,1],[0,2]],1,2",
"3"
],
[
"[1,2,3,4,5,6],[[0,1],[0,2]],1,1",
"1"
]
] | 304 | Write a python function to find element at a given index after number of rotations. | MBPP_sanitized |
||
start_withp | import re
def start_withp(words):
for w in words:
m = re.match('(P\\w+)\\W(P\\w+)', w)
if m:
return m.groups() | code_generation | [] | python | [
"import re"
] | null | [] | [
[
"[\"Python PHP\", \"Java JavaScript\", \"c c++\"]",
"('Python', 'PHP')"
],
[
"[\"Python Programming\",\"Java Programming\"]",
"('Python','Programming')"
],
[
"[\"Pqrst Pqr\",\"qrstuv\"]",
"('Pqrst','Pqr')"
]
] | 305 | Write a function to return two words from a list of words starting with letter 'p'. | MBPP_sanitized |
||
max_sum_increasing_subseq | def max_sum_increasing_subseq(a, n, index, k):
dp = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
if a[i] > a[0]:
dp[0][i] = a[i] + a[0]
else:
dp[0][i] = a[i]
for i in range(1, n):
for j in range(n):
if a[j] > a[i] and j > i:
if dp[i - 1][i] + a[j] > dp[i - 1][j]:
dp[i][j] = dp[i - 1][i] + a[j]
else:
dp[i][j] = dp[i - 1][j]
else:
dp[i][j] = dp[i - 1][j]
return dp[index][k] | code_generation | [] | python | [] | null | [] | [
[
"[1, 101, 2, 3, 100, 4, 5 ], 7, 4, 6",
"11"
],
[
"[1, 101, 2, 3, 100, 4, 5 ], 7, 2, 5",
"7"
],
[
"[11, 15, 19, 21, 26, 28, 31], 7, 2, 4",
"71"
]
] | 306 | Write a function to find the maximum sum of increasing subsequence from prefix until ith index and also including a given kth element which is after i, i.e., k > i . | MBPP_sanitized |
||
colon_tuplex | from copy import deepcopy
def colon_tuplex(tuplex, m, n):
tuplex_colon = deepcopy(tuplex)
tuplex_colon[m].append(n)
return tuplex_colon | code_generation | [] | python | [
"from copy import deepcopy"
] | null | [] | [
[
"(\"HELLO\", 5, [], True) ,2,50",
"(\"HELLO\", 5, [50], True)"
],
[
"(\"HELLO\", 5, [], True) ,2,100",
"((\"HELLO\", 5, [100],True))"
],
[
"(\"HELLO\", 5, [], True) ,2,500",
"(\"HELLO\", 5, [500], True)"
]
] | 307 | Write a function to get a colon of a tuple. | MBPP_sanitized |
||
large_product | def large_product(nums1, nums2, N):
result = sorted([x * y for x in nums1 for y in nums2], reverse=True)[:N]
return result | code_generation | [] | python | [] | null | [] | [
[
"[1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],3",
"[60, 54, 50]"
],
[
"[1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],4",
"[60, 54, 50, 48]"
],
[
"[1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],5",
"[60, 54, 50, 48, 45]"
]
] | 308 | Write a function to find the specified number of largest products from two given lists, selecting one factor from each list. | MBPP_sanitized |
||
maximum | def maximum(a, b):
if a >= b:
return a
else:
return b | code_generation | [] | python | [] | null | [] | [
[
"5,10",
"10"
],
[
"-1,-2",
"-1"
],
[
"9,7",
"9"
]
] | 309 | Write a python function to find the maximum of two numbers. | MBPP_sanitized |
||
string_to_tuple | def string_to_tuple(str1):
result = tuple((x for x in str1 if not x.isspace()))
return result | code_generation | [] | python | [] | null | [] | [
[
"\"python 3.0\"",
"('p', 'y', 't', 'h', 'o', 'n', '3', '.', '0')"
],
[
"\"item1\"",
"('i', 't', 'e', 'm', '1')"
],
[
"\"15.10\"",
"('1', '5', '.', '1', '0')"
]
] | 310 | Write a function to convert a given string to a tuple of characters. | MBPP_sanitized |
||
set_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 | code_generation | [] | python | [] | null | [] | [
[
"10",
"14"
],
[
"12",
"14"
],
[
"15",
"15"
]
] | 311 | Write a python function to set the left most unset bit. | MBPP_sanitized |
||
volume_cone | import math
def volume_cone(r, h):
volume = 1.0 / 3 * math.pi * r * r * h
return volume | code_generation | [] | python | [
"import math"
] | null | [] | [] | 312 | Write a function to find the volume of a cone. | MBPP_sanitized |
||
highest_Power_of_2 | def highest_Power_of_2(n):
res = 0
for i in range(n, 0, -1):
if i & i - 1 == 0:
res = i
break
return res | code_generation | [] | python | [] | null | [] | [
[
"10",
"8"
],
[
"19",
"16"
],
[
"32",
"32"
]
] | 388 | Write a python function to find the highest power of 2 that is less than or equal to n. | MBPP_sanitized |
||
find_lucas | def find_lucas(n):
if n == 0:
return 2
if n == 1:
return 1
return find_lucas(n - 1) + find_lucas(n - 2) | code_generation | [] | python | [] | null | [] | [
[
"9",
"76"
],
[
"4",
"7"
],
[
"3",
"4"
]
] | 389 | Write a function to find the n'th lucas number. | MBPP_sanitized |
||
add_string | def add_string(list_, string):
add_string = [string.format(i) for i in list_]
return add_string | code_generation | [] | python | [] | null | [] | [
[
"[1,2,3,4],'temp{0}'",
"['temp1', 'temp2', 'temp3', 'temp4']"
],
[
"['a','b','c','d'], 'python{0}'",
"[ 'pythona', 'pythonb', 'pythonc', 'pythond']"
],
[
"[5,6,7,8],'string{0}'",
"['string5', 'string6', 'string7', 'string8']"
]
] | 390 | Write a function to apply a given format string to all of the elements in a list. | MBPP_sanitized |
||
convert_list_dictionary | def convert_list_dictionary(l1, l2, l3):
result = [{x: {y: z}} for (x, y, z) in zip(l1, l2, l3)]
return result | code_generation | [] | python | [] | null | [] | [
[
"[\"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}}]"
],
[
"[\"abc\",\"def\",\"ghi\",\"jkl\"],[\"python\",\"program\",\"language\",\"programs\"],[100,200,300,400]",
"[{'abc':{'python':100}},{'def':{'program':200}},{'ghi':{'language':300}},{'jkl':{'programs':400}}]"
],
[
"[\"A1\",\"A2\",\"A3\",\"A4\"],[\"java\",\"C\",\"C++\",\"DBMS\"],[10,20,30,40]",
"[{'A1':{'java':10}},{'A2':{'C':20}},{'A3':{'C++':30}},{'A4':{'DBMS':40}}]"
]
] | 391 | Write a function to convert more than one list to nested dictionary. | MBPP_sanitized |
||
get_max_sum | 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] | code_generation | [] | python | [] | null | [] | [
[
"60",
"106"
],
[
"10",
"12"
],
[
"2",
"2"
]
] | 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). | MBPP_sanitized |
||
max_length_list | 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) | code_generation | [] | python | [] | null | [] | [
[
"[[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]]",
"(3, [13, 15, 17])"
],
[
"[[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]]",
"(5,[1,2,3,4,5])"
],
[
"[[3,4,5],[6,7,8,9],[10,11,12]]",
"(4,[6,7,8,9])"
]
] | 393 | Write a function to find the list with maximum length. | MBPP_sanitized |
||
check_distinct | def check_distinct(test_tup):
res = True
temp = set()
for ele in test_tup:
if ele in temp:
res = False
break
temp.add(ele)
return res | code_generation | [] | python | [] | null | [] | [
[
"(1, 4, 5, 6, 1, 4)",
"False"
],
[
"(1, 4, 5, 6)",
"True"
],
[
"(2, 3, 4, 5, 6)",
"True"
]
] | 394 | Write a function to check if given tuple contains no duplicates. | MBPP_sanitized |
||
first_non_repeating_character | 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 | code_generation | [] | python | [] | null | [] | [
[
"\"abcabc\"",
null
],
[
"\"abc\"",
"\"a\""
],
[
"\"ababc\"",
"\"c\""
]
] | 395 | Write a python function to find the first non-repeated character in a given string. | MBPP_sanitized |
||
check_char | import re
regex = '^[a-z]$|^([a-z]).*\\1$'
def check_char(string):
if re.search(regex, string):
return 'Valid'
else:
return 'Invalid' | code_generation | [] | python | [
"import re "
] | null | [] | [
[
"\"abba\"",
"\"Valid\""
],
[
"\"a\"",
"\"Valid\""
],
[
"\"abcd\"",
"\"Invalid\""
]
] | 396 | Write a function to check whether the given string starts and ends with the same character or not. | MBPP_sanitized |
||
median_numbers | def median_numbers(a, b, c):
if a > b:
if a < c:
median = a
elif b > c:
median = b
else:
median = c
elif a > c:
median = a
elif b < c:
median = b
else:
median = c
return median | code_generation | [] | python | [] | null | [] | [
[
"25,55,65",
"55.0"
],
[
"20,10,30",
"20.0"
],
[
"15,45,75",
"45.0"
]
] | 397 | Write a function to find the median of three numbers. | MBPP_sanitized |
||
sum_of_digits | def sum_of_digits(nums):
return sum((int(el) for n in nums for el in str(n) if el.isdigit())) | code_generation | [] | python | [] | null | [] | [
[
"[10,2,56]",
"14"
],
[
"[[10,20,4,5,'b',70,'a']]",
"19"
],
[
"[10,20,-4,5,-70]",
"19"
]
] | 398 | Write a function to compute the sum of digits of each number of a given list. | MBPP_sanitized |
||
bitwise_xor | def bitwise_xor(test_tup1, test_tup2):
res = tuple((ele1 ^ ele2 for (ele1, ele2) in zip(test_tup1, test_tup2)))
return res | code_generation | [] | python | [] | null | [] | [
[
"(10, 4, 6, 9), (5, 2, 3, 3)",
"(15, 6, 5, 10)"
],
[
"(11, 5, 7, 10), (6, 3, 4, 4)",
"(13, 6, 3, 14)"
],
[
"(12, 6, 8, 11), (7, 4, 5, 6)",
"(11, 2, 13, 13)"
]
] | 399 | Write a function to perform the mathematical bitwise xor operation across the given tuples. | MBPP_sanitized |
||
extract_freq | def extract_freq(test_list):
res = len(list(set((tuple(sorted(sub)) for sub in test_list))))
return res | code_generation | [] | python | [] | null | [] | [
[
"[(3, 4), (1, 2), (4, 3), (5, 6)] ",
"3"
],
[
"[(4, 15), (2, 3), (5, 4), (6, 7)] ",
"4"
],
[
"[(5, 16), (2, 3), (6, 5), (6, 9)] ",
"4"
]
] | 400 | Write a function to extract the number of unique tuples in the given list. | MBPP_sanitized |
||
add_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 | code_generation | [] | python | [] | null | [] | [
[
"((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))",
"((7, 10), (7, 14), (3, 10), (8, 13))"
],
[
"((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))",
"((9, 12), (9, 16), (5, 12), (10, 15))"
],
[
"((3, 5), (6, 7), (4, 11), (3, 12)), ((8, 9), (5, 11), (3, 3), (9, 5))",
"((11, 14), (11, 18), (7, 14), (12, 17))"
]
] | 401 | Write a function to perform index wise addition of tuple elements in the given two nested tuples. | MBPP_sanitized |
||
minimum | def minimum(a, b):
if a <= b:
return a
else:
return b | code_generation | [] | python | [] | null | [] | [
[
"1,2",
"1"
],
[
"-5,-4",
"-5"
],
[
"0,0",
"0"
]
] | 404 | Write a python function to find the minimum of two numbers. | MBPP_sanitized |
||
check_tuplex | def check_tuplex(tuplex, tuple1):
if tuple1 in tuplex:
return True
else:
return False | code_generation | [] | python | [] | null | [] | [
[
"(\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),'r'",
"True"
],
[
"(\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),'5'",
"False"
],
[
"(\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\",\"e\"),3",
"True"
]
] | 405 | Write a function to check whether an element exists within a tuple. | MBPP_sanitized |
||
find_Parity | 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 | code_generation | [] | python | [] | null | [] | [
[
"12",
"False"
],
[
"7",
"True"
],
[
"10",
"False"
]
] | 406 | Write a python function to find whether the parity of a given number is odd. | MBPP_sanitized |
||
rearrange_bigger | 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 | code_generation | [] | python | [] | null | [] | [
[
"12",
"21"
],
[
"10",
"False"
],
[
"102",
"120"
]
] | 407 | Write a function to create the next bigger number by rearranging the digits of a given number. | MBPP_sanitized |
||
k_smallest_pairs | 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[i], nums2[j]])
push(i, j + 1)
if j == 0:
push(i + 1, 0)
return pairs | code_generation | [] | python | [
"import heapq"
] | null | [] | [
[
"[1,3,7],[2,4,6],2",
"[[1, 2], [1, 4]]"
],
[
"[1,3,7],[2,4,6],1",
"[[1, 2]]"
],
[
"[1,3,7],[2,4,6],7",
"[[1, 2], [1, 4], [3, 2], [1, 6], [3, 4], [3, 6], [7, 2]]"
]
] | 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. | MBPP_sanitized |
||
min_product_tuple | def min_product_tuple(list1):
result_min = min([abs(x * y) for (x, y) in list1])
return result_min | code_generation | [] | python | [] | null | [] | [
[
"[(2, 7), (2, 6), (1, 8), (4, 9)] ",
"8"
],
[
"[(10,20), (15,2), (5,10)] ",
"30"
],
[
"[(11,44), (10,15), (20,5), (12, 9)] ",
"100"
]
] | 409 | Write a function to find the minimum product from the pairs of tuples within a given list. | MBPP_sanitized |
||
min_val | def min_val(listval):
min_val = min((i for i in listval if isinstance(i, int)))
return min_val | code_generation | [] | python | [] | null | [] | [
[
"['Python', 3, 2, 4, 5, 'version']",
"2"
],
[
"['Python', 15, 20, 25]",
"15"
],
[
"['Python', 30, 20, 40, 50, 'version']",
"20"
]
] | 410 | Write a function to find the minimum value in a given heterogeneous list. | MBPP_sanitized |
||
snake_to_camel | import re
def snake_to_camel(word):
return ''.join((x.capitalize() or '_' for x in word.split('_'))) | code_generation | [] | python | [
"import re"
] | null | [] | [
[
"'android_tv'",
"'AndroidTv'"
],
[
"'google_pixel'",
"'GooglePixel'"
],
[
"'apple_watch'",
"'AppleWatch'"
]
] | 411 | Write a function to convert the given snake case string to camel case string. | MBPP_sanitized |
||
remove_odd | def remove_odd(l):
for i in l:
if i % 2 != 0:
l.remove(i)
return l | code_generation | [] | python | [] | null | [] | [
[
"[1,2,3]",
"[2]"
],
[
"[2,4,6]",
"[2,4,6]"
],
[
"[10,20,3]",
"[10,20]"
]
] | 412 | Write a python function to remove odd numbers from a given list. | MBPP_sanitized |
||
extract_nth_element | def extract_nth_element(list1, n):
result = [x[n] for x in list1]
return result | code_generation | [] | python | [] | null | [] | [
[
"[('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']"
],
[
"[('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,2",
"[99, 96, 94, 98]"
],
[
"[('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)],1",
"[98, 97, 91, 94]"
]
] | 413 | Write a function to extract the nth element from a given list of tuples. | MBPP_sanitized |
||
overlapping | 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 | code_generation | [] | python | [] | null | [] | [
[
"[1,2,3,4,5],[6,7,8,9]",
"False"
],
[
"[1,2,3],[4,5,6]",
"False"
],
[
"[1,4,5],[1,4,5]",
"True"
]
] | 414 | Write a python function to check whether any value in a sequence exists in a sequence or not. | MBPP_sanitized |
||
max_Product | 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) | code_generation | [] | python | [] | null | [] | [
[
"[1,2,3,4,7,0,8,4]",
"(7,8)"
],
[
"[0,-1,-2,-4,5,0,-6]",
"(-4,-6)"
],
[
"[1,2,3]",
"(2,3)"
]
] | 415 | Write a python function to find a pair with highest product from a given array of integers. | MBPP_sanitized |
||
group_tuples | 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()] | code_generation | [] | python | [] | null | [] | [
[
"[('x', 'y'), ('x', 'z'), ('w', 't')]",
"[('x', 'y', 'z'), ('w', 't')]"
],
[
"[('a', 'b'), ('a', 'c'), ('d', 'e')]",
"[('a', 'b', 'c'), ('d', 'e')]"
],
[
"[('f', 'g'), ('f', 'g'), ('h', 'i')]",
"[('f', 'g', 'g'), ('h', 'i')]"
]
] | 417 | Write a function to find common first element in given list of tuple. | MBPP_sanitized |
Subsets and Splits