Dataset Viewer
Auto-converted to Parquet
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
remove_Occ
def remove_Occ(s, ch): for i in range(len(s)): if s[i] == ch: s = s[0:i] + s[i + 1:] break for i in range(len(s) - 1, -1, -1): if s[i] == ch: s = s[0:i] + s[i + 1:] break return s
code_generation
[]
python
[]
null
[]
[ [ "\"hello\",\"l\"", "\"heo\"" ], [ "\"abcda\",\"a\"", "\"bcd\"" ], [ "\"PHP\",\"P\"", "\"H\"" ] ]
11
Write a python function to remove first and last occurrence of a given character from the string.
MBPP_sanitized
sort_matrix
def sort_matrix(M): result = sorted(M, key=sum) return result
code_generation
[]
python
[]
null
[]
[ [ "[[1, 2, 3], [2, 4, 5], [1, 1, 1]]", "[[1, 1, 1], [1, 2, 3], [2, 4, 5]]" ], [ "[[1, 2, 3], [-2, 4, -5], [1, -1, 1]]", "[[-2, 4, -5], [1, -1, 1], [1, 2, 3]]" ], [ "[[5,8,9],[6,4,3],[2,1,4]]", "[[2, 1, 4], [6, 4, 3], [5, 8, 9]]" ] ]
12
Write a function to sort a given matrix in ascending order according to the sum of its rows.
MBPP_sanitized
find_Volume
def find_Volume(l, b, h): return l * b * h / 2
code_generation
[]
python
[]
null
[]
[ [ "10,8,6", "240" ], [ "3,2,2", "6" ], [ "1,2,1", "1" ] ]
14
Write a python function to find the volume of a triangular prism.
MBPP_sanitized
text_lowercase_underscore
import re def text_lowercase_underscore(text): patterns = '^[a-z]+_[a-z]+$' if re.search(patterns, text): return True else: return False
code_generation
[]
python
[ "import re" ]
null
[]
[ [ "\"aab_cbbbc\"", "(True)" ], [ "\"aab_Abbbc\"", "(False)" ], [ "\"Aaab_abbbc\"", "(False)" ] ]
16
Write a function to that returns true if the input string contains sequences of lowercase letters joined with an underscore and false otherwise.
MBPP_sanitized
square_perimeter
def square_perimeter(a): perimeter = 4 * a return perimeter
code_generation
[]
python
[]
null
[]
[ [ "10", "40" ], [ "5", "20" ], [ "4", "16" ] ]
17
Write a function that returns the perimeter of a square given its side length as input.
MBPP_sanitized
remove_dirty_chars
NO_OF_CHARS = 256 def str_to_list(string): temp = [] for x in string: temp.append(x) return temp def lst_to_string(List): return ''.join(List) def get_char_count_array(string): count = [0] * NO_OF_CHARS for i in string: count[ord(i)] += 1 return count def remove_dirty_chars(string, second_string): count = get_char_count_array(second_string) ip_ind = 0 res_ind = 0 temp = '' str_list = str_to_list(string) while ip_ind != len(str_list): temp = str_list[ip_ind] if count[ord(temp)] == 0: str_list[res_ind] = str_list[ip_ind] res_ind += 1 ip_ind += 1 return lst_to_string(str_list[0:res_ind])
code_generation
[]
python
[]
null
[]
[ [ "\"probasscurve\", \"pros\"", "'bacuve'" ], [ "\"digitalindia\", \"talent\"", "'digiidi'" ], [ "\"exoticmiles\", \"toxic\"", "'emles'" ] ]
18
Write a function to remove characters from the first string which are present in the second string.
MBPP_sanitized
test_duplicate
def test_duplicate(arraynums): nums_set = set(arraynums) return len(arraynums) != len(nums_set)
code_generation
[]
python
[]
null
[]
[ [ "([1,2,3,4,5])", "False" ], [ "([1,2,3,4, 4])", "True" ], [ "[1,1,2,2,3,3,4,4,5]", "True" ] ]
19
Write a function to find whether a given array of integers contains any duplicate element.
MBPP_sanitized
is_woodall
def is_woodall(x): if x % 2 == 0: return False if x == 1: return True x = x + 1 p = 0 while x % 2 == 0: x = x / 2 p = p + 1 if p == x: return True return False
code_generation
[]
python
[]
null
[]
[ [ "383", "True" ], [ "254", "False" ], [ "200", "False" ] ]
20
Write a function to check if the given number is woodball or not.
MBPP_sanitized
check
def rev(num): rev_num = 0 while num > 0: rev_num = rev_num * 10 + num % 10 num = num // 10 return rev_num def check(n): return 2 * rev(n) == n + 1
code_generation
[]
python
[]
null
[]
[ [ "70", "False" ], [ "23", "False" ], [ "73", "True" ] ]
56
Write a python function to check if a given number is one less than twice its reverse.
MBPP_sanitized
find_Max_Num
def find_Max_Num(arr): n = len(arr) arr.sort(reverse=True) num = arr[0] for i in range(1, n): num = num * 10 + arr[i] return num
code_generation
[]
python
[]
null
[]
[ [ "[1,2,3]", "321" ], [ "[4,5,6,1]", "6541" ], [ "[1,2,3,9]", "9321" ] ]
57
Write a python function to find the largest number that can be formed with the given list of digits.
MBPP_sanitized
opposite_Signs
def opposite_Signs(x, y): return x ^ y < 0
code_generation
[]
python
[]
null
[]
[ [ "1,-2", "True" ], [ "3,2", "False" ], [ "-10,-10", "False" ], [ "-2,2", "True" ] ]
58
Write a python function to check whether the given two integers have opposite sign or not.
MBPP_sanitized
is_octagonal
def is_octagonal(n): return 3 * n * n - 2 * n
code_generation
[]
python
[]
null
[]
[ [ "5", "65" ], [ "10", "280" ], [ "15", "645" ] ]
59
Write a function to find the nth octagonal number.
MBPP_sanitized
count_Substrings
from collections import defaultdict def count_Substrings(s): n = len(s) (count, sum) = (0, 0) mp = defaultdict(lambda : 0) mp[0] += 1 for i in range(n): sum += ord(s[i]) - ord('0') count += mp[sum - (i + 1)] mp[sum - (i + 1)] += 1 return count
code_generation
[]
python
[ "from collections import defaultdict" ]
null
[]
[ [ "'112112'", "6" ], [ "'111'", "6" ], [ "'1101112'", "12" ] ]
61
Write a python function to count the number of substrings with the sum of digits equal to their length.
MBPP_sanitized
smallest_num
def smallest_num(xs): return min(xs)
code_generation
[]
python
[]
null
[]
[ [ "[10, 20, 1, 45, 99]", "1" ], [ "[1, 2, 3]", "1" ], [ "[45, 46, 50, 60]", "45" ] ]
62
Write a python function to find smallest number in a list.
MBPP_sanitized
max_difference
def max_difference(test_list): temp = [abs(b - a) for (a, b) in test_list] res = max(temp) return res
code_generation
[]
python
[]
null
[]
[ [ "[(3, 5), (1, 7), (10, 3), (1, 2)]", "7" ], [ "[(4, 6), (2, 17), (9, 13), (11, 12)]", "15" ], [ "[(12, 35), (21, 27), (13, 23), (41, 22)]", "23" ] ]
63
Write a function to find the maximum difference between available pairs in the given tuple list.
MBPP_sanitized
subject_marks
def subject_marks(subjectmarks): subjectmarks.sort(key=lambda x: x[1]) return subjectmarks
code_generation
[]
python
[]
null
[]
[ [ "[('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]", "[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)]" ], [ "[('Telugu',49),('Hindhi',54),('Social',33)]", "([('Social',33),('Telugu',49),('Hindhi',54)])" ], [ "[('Physics',96),('Chemistry',97),('Biology',45)]", "([('Biology',45),('Physics',96),('Chemistry',97)])" ] ]
64
Write a function to sort a list of tuples using the second value of each tuple.
MBPP_sanitized
recursive_list_sum
def recursive_list_sum(data_list): total = 0 for element in data_list: if type(element) == type([]): total = total + recursive_list_sum(element) else: total = total + element return total
code_generation
[]
python
[]
null
[]
[ [ "([1, 2, [3,4],[5,6]])", "21" ], [ "([7, 10, [15,14],[19,41]])", "106" ], [ "([10, 20, [30,40],[50,60]])", "210" ] ]
65
Write a function to flatten a list and sum all of its elements.
MBPP_sanitized
pos_count
def pos_count(list): pos_count = 0 for num in list: if num >= 0: pos_count += 1 return pos_count
code_generation
[]
python
[]
null
[]
[ [ "[1,-2,3,-4]", "2" ], [ "[3,4,5,-1]", "3" ], [ "[1,2,3,4]", "4" ] ]
66
Write a python function to count the number of positive numbers in a list.
MBPP_sanitized
bell_number
def bell_number(n): bell = [[0 for i in range(n + 1)] for j in range(n + 1)] bell[0][0] = 1 for i in range(1, n + 1): bell[i][0] = bell[i - 1][i - 1] for j in range(1, i + 1): bell[i][j] = bell[i - 1][j - 1] + bell[i][j - 1] return bell[n][0]
code_generation
[]
python
[]
null
[]
[ [ "2", "2" ], [ "10", "115975" ], [ "56", "6775685320645824322581483068371419745979053216268760300" ] ]
67
Write a function to find the number of ways to partition a set of Bell numbers.
MBPP_sanitized
is_Monotonic
def is_Monotonic(A): return all((A[i] <= A[i + 1] for i in range(len(A) - 1))) or all((A[i] >= A[i + 1] for i in range(len(A) - 1)))
code_generation
[]
python
[]
null
[]
[ [ "[6, 5, 4, 4]", "True" ], [ "[1, 2, 2, 3]", "True" ], [ "[1, 3, 2]", "False" ] ]
68
Write a python function to check whether the given array is monotonic or not.
MBPP_sanitized
is_sublist
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
code_generation
[]
python
[]
null
[]
[ [ "[2,4,3,5,7],[3,7]", "False" ], [ "[2,4,3,5,7],[4,3]", "True" ], [ "[2,4,3,5,7],[1,6]", "False" ] ]
69
Write a function to check whether a list contains the given sublist or not.
MBPP_sanitized
get_equal
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
code_generation
[]
python
[]
null
[]
[ [ "[(11, 22, 33), (44, 55, 66)]", "True" ], [ "[(1, 2, 3), (4, 5, 6, 7)]", "False" ], [ "[(1, 2), (3, 4)]", "True" ] ]
70
Write a function to find whether all the given tuples have equal length or not.
MBPP_sanitized
comb_sort
def comb_sort(nums): shrink_fact = 1.3 gaps = len(nums) swapped = True i = 0 while gaps > 1 or swapped: gaps = int(float(gaps) / shrink_fact) swapped = False i = 0 while gaps + i < len(nums): if nums[i] > nums[i + gaps]: (nums[i], nums[i + gaps]) = (nums[i + gaps], nums[i]) swapped = True i += 1 return nums
code_generation
[]
python
[]
null
[]
[ [ "[5, 15, 37, 25, 79]", "[5, 15, 25, 37, 79]" ], [ "[41, 32, 15, 19, 22]", "[15, 19, 22, 32, 41]" ], [ "[99, 15, 13, 47]", "[13, 15, 47, 99]" ] ]
71
Write a function to sort a list of elements.
MBPP_sanitized
dif_Square
def dif_Square(n): if n % 4 != 2: return True return False
code_generation
[]
python
[]
null
[]
[ [ "5", "True" ], [ "10", "False" ], [ "15", "True" ] ]
72
Write a python function to check whether the given number can be represented as the difference of two squares or not.
MBPP_sanitized
is_samepatterns
def is_samepatterns(colors, patterns): if len(colors) != len(patterns): return False sdict = {} pset = set() sset = set() for i in range(len(patterns)): pset.add(patterns[i]) sset.add(colors[i]) if patterns[i] not in sdict.keys(): sdict[patterns[i]] = [] keys = sdict[patterns[i]] keys.append(colors[i]) sdict[patterns[i]] = keys if len(pset) != len(sset): return False for values in sdict.values(): for i in range(len(values) - 1): if values[i] != values[i + 1]: return False return True
code_generation
[]
python
[]
null
[]
[ [ "[\"red\",\"green\",\"green\"], [\"a\", \"b\", \"b\"]", "True" ], [ "[\"red\",\"green\",\"greenn\"], [\"a\",\"b\",\"b\"]", "False" ], [ "[\"red\",\"green\",\"greenn\"], [\"a\",\"b\"]", "False" ] ]
74
Write a function to check whether it follows the sequence given in the patterns array.
MBPP_sanitized
find_tuples
def find_tuples(test_list, K): res = [sub for sub in test_list if all((ele % K == 0 for ele in sub))] return res
code_generation
[]
python
[]
null
[]
[ [ "[(6, 24, 12), (7, 9, 6), (12, 18, 21)], 6", "[(6, 24, 12)]" ], [ "[(5, 25, 30), (4, 2, 3), (7, 8, 9)], 5", "[(5, 25, 30)]" ], [ "[(7, 9, 16), (8, 16, 4), (19, 17, 18)], 4", "[(8, 16, 4)]" ] ]
75
Write a function to find tuples which have all elements divisible by k from the given list of tuples.
MBPP_sanitized
is_Diff
def is_Diff(n): return n % 11 == 0
code_generation
[]
python
[]
null
[]
[ [ "1212112", "True" ], [ "1212", "False" ] ]
77
Write a python function to find whether a number is divisible by 11.
MBPP_sanitized
word_len
def word_len(s): s = s.split(' ') for word in s: if len(word) % 2 != 0: return True else: return False
code_generation
[]
python
[]
null
[]
[ [ "\"Hadoop\"", "False" ], [ "\"great\"", "True" ], [ "\"structure\"", "True" ] ]
79
Write a python function to check whether the length of the word is odd or not.
MBPP_sanitized
tetrahedral_number
def tetrahedral_number(n): return n * (n + 1) * (n + 2) / 6
code_generation
[]
python
[]
null
[]
[ [ "5", "35" ], [ "6", "56" ], [ "7", "84" ] ]
80
Write a function to find the nth tetrahedral number.
MBPP_sanitized
volume_sphere
import math def volume_sphere(r): volume = 4 / 3 * math.pi * r * r * r return volume
code_generation
[]
python
[ "import math" ]
null
[]
[]
82
Write a function to find the volume of a sphere.
MBPP_sanitized
get_Char
def get_Char(strr): summ = 0 for i in range(len(strr)): summ += ord(strr[i]) - ord('a') + 1 if summ % 26 == 0: return ord('z') else: summ = summ % 26 return chr(ord('a') + summ - 1)
code_generation
[]
python
[]
null
[]
[ [ "\"abc\"", "\"f\"" ], [ "\"gfg\"", "\"t\"" ], [ "\"ab\"", "\"c\"" ] ]
83
Write a python function to find the character made by adding the ASCII value of all the characters of the given string modulo 26.
MBPP_sanitized
sequence
def sequence(n): if n == 1 or n == 2: return 1 else: return sequence(sequence(n - 1)) + sequence(n - sequence(n - 1))
code_generation
[]
python
[]
null
[]
[ [ "10", "6" ], [ "2", "1" ], [ "3", "2" ] ]
84
Write a function to find the nth number in the newman conway sequence.
MBPP_sanitized
surfacearea_sphere
import math def surfacearea_sphere(r): surfacearea = 4 * math.pi * r * r return surfacearea
code_generation
[]
python
[ "import math" ]
null
[]
[]
85
Write a function to find the surface area of a sphere.
MBPP_sanitized
centered_hexagonal_number
def centered_hexagonal_number(n): return 3 * n * (n - 1) + 1
code_generation
[]
python
[]
null
[]
[ [ "10", "271" ], [ "2", "7" ], [ "9", "217" ] ]
86
Write a function to find nth centered hexagonal number.
MBPP_sanitized
merge_dictionaries_three
import collections as ct def merge_dictionaries_three(dict1, dict2, dict3): merged_dict = dict(ct.ChainMap({}, dict1, dict2, dict3)) return merged_dict
code_generation
[]
python
[ "import collections as ct" ]
null
[]
[ [ "{ \"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'}" ], [ "{ \"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'}" ], [ "{ \"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'}" ] ]
87
Write a function to merge three dictionaries into a single dictionary.
MBPP_sanitized
freq_count
import collections def freq_count(list1): freq_count = collections.Counter(list1) return freq_count
code_generation
[]
python
[ "import collections" ]
null
[]
[ [ "[10,10,10,10,20,20,20,20,40,40,50,50,30]", "({10: 4, 20: 4, 40: 2, 50: 2, 30: 1})" ], [ "[1,2,3,4,3,2,4,1,3,1,4]", "({1:3, 2:2,3:3,4:3})" ], [ "[5,6,7,4,9,10,4,5,6,7,9,5]", "({10:1,5:3,6:2,7:2,4:2,9:2})" ] ]
88
Write a function to get the frequency of all the elements in a list, returned as a dictionary.
MBPP_sanitized
closest_num
def closest_num(N): return N - 1
code_generation
[]
python
[]
null
[]
[ [ "11", "10" ], [ "7", "6" ], [ "12", "11" ] ]
89
Write a function to find the closest smaller number than n.
MBPP_sanitized
len_log
def len_log(list1): max = len(list1[0]) for i in list1: if len(i) > max: max = len(i) return max
code_generation
[]
python
[]
null
[]
[ [ "[\"python\",\"PHP\",\"bigdata\"]", "7" ], [ "[\"a\",\"ab\",\"abc\"]", "3" ], [ "[\"small\",\"big\",\"tall\"]", "5" ] ]
90
Write a python function to find the length of the longest word.
MBPP_sanitized
find_substring
def find_substring(str1, sub_str): if any((sub_str in s for s in str1)): return True return False
code_generation
[]
python
[]
null
[]
[ [ "[\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ack\"", "True" ], [ "[\"red\", \"black\", \"white\", \"green\", \"orange\"],\"abc\"", "False" ], [ "[\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ange\"", "True" ] ]
91
Write a function to check if a string is present as a substring in a given list of string values.
MBPP_sanitized
is_undulating
def is_undulating(n): n = str(n) if len(n) <= 2: return False for i in range(2, len(n)): if n[i - 2] != n[i]: return False return True
code_generation
[]
python
[]
null
[]
[ [ "1212121", "True" ], [ "1991", "False" ], [ "121", "True" ] ]
92
Write a function to check whether the given number is undulating or not.
MBPP_sanitized
power
def power(a, b): if b == 0: return 1 elif a == 0: return 0 elif b == 1: return a else: return a * power(a, b - 1)
code_generation
[]
python
[]
null
[]
[ [ "3,4", "81" ], [ "2,3", "8" ], [ "5,5", "3125" ] ]
93
Write a function to calculate the value of 'a' to the power 'b'.
MBPP_sanitized
index_minimum
from operator import itemgetter def index_minimum(test_list): res = min(test_list, key=itemgetter(1))[0] return res
code_generation
[]
python
[ "from operator import itemgetter " ]
null
[]
[ [ "[('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]", "'Varsha'" ], [ "[('Yash', 185), ('Dawood', 125), ('Sanya', 175)]", "'Dawood'" ], [ "[('Sai', 345), ('Salman', 145), ('Ayesha', 96)]", "'Ayesha'" ] ]
94
Given a list of tuples, write a function that returns the first value of the tuple with the smallest second value.
MBPP_sanitized
Find_Min_Length
def Find_Min_Length(lst): minLength = min((len(x) for x in lst)) return minLength
code_generation
[]
python
[]
null
[]
[ [ "[[1],[1,2]]", "1" ], [ "[[1,2],[1,2,3],[1,2,3,4]]", "2" ], [ "[[3,3,3],[4,4,4,4]]", "3" ] ]
95
Write a python function to find the length of the smallest list in a list of lists.
MBPP_sanitized
divisor
def divisor(n): for i in range(n): x = len([i for i in range(1, n + 1) if not n % i]) return x
code_generation
[]
python
[]
null
[]
[ [ "15", "4" ], [ "12", "6" ], [ "9", "3" ] ]
96
Write a python function to find the number of divisors of a given integer.
MBPP_sanitized
frequency_lists
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
code_generation
[]
python
[]
null
[]
[ [ "[[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}" ], [ "[[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}" ], [ "[[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}" ] ]
97
Write a function to find frequency of each element in a flattened list of lists, returned in a dictionary.
MBPP_sanitized
multiply_num
def multiply_num(numbers): total = 1 for x in numbers: total *= x return total / len(numbers)
code_generation
[]
python
[]
null
[]
[]
98
Write a function to multiply all the numbers in a list and divide with the length of the list.
MBPP_sanitized
decimal_to_binary
def decimal_to_binary(n): return bin(n).replace('0b', '')
code_generation
[]
python
[]
null
[]
[ [ "8", "'1000'" ], [ "18", "'10010'" ], [ "7", "'111'" ] ]
99
Write a function to convert the given decimal number to its binary equivalent, represented as a string with no leading zeros.
MBPP_sanitized
next_smallest_palindrome
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
code_generation
[]
python
[ "import sys" ]
null
[]
[ [ "99", "101" ], [ "1221", "1331" ], [ "120", "121" ] ]
100
Write a function to find the next smallest palindrome of a specified integer, returned as an integer.
MBPP_sanitized
kth_element
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]
code_generation
[]
python
[]
null
[]
[ [ "[12,3,5,7,19], 2", "3" ], [ "[17,24,8,23], 3", "8" ], [ "[16,21,25,36,4], 4", "36" ] ]
101
Write a function to find the kth element in the given array using 1-based indexing.
MBPP_sanitized
snake_to_camel
def snake_to_camel(word): import re return ''.join((x.capitalize() or '_' for x in word.split('_')))
code_generation
[]
python
[ "import re" ]
null
[]
[ [ "'python_program'", "'PythonProgram'" ], [ "'python_language'", "('PythonLanguage')" ], [ "'programming_language'", "('ProgrammingLanguage')" ] ]
102
Write a function to convert a snake case string to camel case string.
MBPP_sanitized
eulerian_num
def eulerian_num(n, m): if m >= n or n == 0: return 0 if m == 0: return 1 return (n - m) * eulerian_num(n - 1, m - 1) + (m + 1) * eulerian_num(n - 1, m)
code_generation
[]
python
[]
null
[]
[ [ "3, 1", "4" ], [ "4, 1", "11" ], [ "5, 3", "26" ] ]
103
Write a function to find the Eulerian number a(n, m).
MBPP_sanitized
sort_sublists
def sort_sublists(input_list): result = [sorted(x, key=lambda x: x[0]) for x in input_list] return result
code_generation
[]
python
[]
null
[]
[ [ "([\"green\", \"orange\"], [\"black\", \"white\"], [\"white\", \"black\", \"orange\"])", "[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]" ], [ "([\" red \",\"green\" ],[\"blue \",\" black\"],[\" orange\",\"brown\"])", "[[' red ', 'green'], [' black', 'blue '], [' orange', 'brown']]" ], [ "([\"zilver\",\"gold\"], [\"magnesium\",\"aluminium\"], [\"steel\", \"bronze\"])", "[['gold', 'zilver'],['aluminium', 'magnesium'], ['bronze', 'steel']]" ] ]
104
Write a function to sort each sublist of strings in a given list of lists.
MBPP_sanitized
count
def count(lst): return sum(lst)
code_generation
[]
python
[]
null
[]
[ [ "[True,False,True]", "2" ], [ "[False,False]", "0" ], [ "[True,True,True]", "3" ] ]
105
Write a python function to count true booleans in the given list.
MBPP_sanitized
add_lists
def add_lists(test_list, test_tup): res = tuple(list(test_tup) + test_list) return res
code_generation
[]
python
[]
null
[]
[ [ "[5, 6, 7], (9, 10)", "(9, 10, 5, 6, 7)" ], [ "[6, 7, 8], (10, 11)", "(10, 11, 6, 7, 8)" ], [ "[7, 8, 9], (11, 12)", "(11, 12, 7, 8, 9)" ] ]
106
Write a function to append the given list to the given tuples.
MBPP_sanitized
merge_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)
code_generation
[]
python
[ "import heapq" ]
null
[]
[ [ "[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]" ], [ "[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]" ], [ "[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]" ] ]
108
Write a function to merge three lists into a single sorted list.
MBPP_sanitized
odd_Equivalent
def odd_Equivalent(s, n): count = 0 for i in range(0, n): if s[i] == '1': count = count + 1 return count
code_generation
[]
python
[]
null
[]
[ [ "\"011001\",6", "3" ], [ "\"11011\",5", "4" ], [ "\"1010\",4", "2" ] ]
109
Write a python function to find the number of numbers with an odd value when rotating a binary string the given number of times.
MBPP_sanitized
common_in_nested_lists
def common_in_nested_lists(nestedlist): result = list(set.intersection(*map(set, nestedlist))) return result
code_generation
[]
python
[]
null
[]
[ [ "[[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]]", "set([18, 12])" ], [ "[[12, 5, 23, 25, 45], [7, 11, 5, 23, 28], [1, 5, 8, 18, 23, 16]]", "set([5,23])" ], [ "[[2, 3,4, 1], [4, 5], [6,4, 8],[4, 5], [6, 8,4]]", "set([4])" ] ]
111
Write a function to find the common elements in given nested lists.
MBPP_sanitized
check_integer
def check_integer(text): text = text.strip() if len(text) < 1: return None elif all((text[i] in '0123456789' for i in range(len(text)))): return True elif text[0] in '+-' and all((text[i] in '0123456789' for i in range(1, len(text)))): return True else: return False
code_generation
[]
python
[]
null
[]
[ [ "\"python\"", "False" ], [ "\"1\"", "True" ], [ "\"12345\"", "True" ] ]
113
Write a function to check if a string represents an integer or not.
MBPP_sanitized
empty_dit
def empty_dit(list1): empty_dit = all((not d for d in list1)) return empty_dit
code_generation
[]
python
[]
null
[]
[ [ "[{},{},{}]", "True" ], [ "[{1,2},{},{}]", "False" ], [ "{}", "True" ] ]
115
Write a function to check whether all dictionaries in a list are empty or not.
MBPP_sanitized
tuple_to_int
def tuple_to_int(nums): result = int(''.join(map(str, nums))) return result
code_generation
[]
python
[]
null
[]
[ [ "(1,2,3)", "123" ], [ "(4,5,6)", "456" ], [ "(5,6,7)", "567" ] ]
116
Write a function to convert a given tuple of positive integers into a single integer.
MBPP_sanitized
list_to_float
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
code_generation
[]
python
[]
null
[]
[ [ " [(\"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)]" ], [ " [(\"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)]" ], [ " [(\"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)]" ] ]
117
Write a function to convert all possible convertible elements in a list of lists to floats.
MBPP_sanitized
string_to_list
def string_to_list(string): lst = list(string.split(' ')) return lst
code_generation
[]
python
[]
null
[]
[ [ "\"python programming\"", "['python','programming']" ], [ "\"lists tuples strings\"", "['lists','tuples','strings']" ], [ "\"write a program\"", "['write','a','program']" ] ]
118
Write a function to convert a string to a list of strings split on the space character.
MBPP_sanitized
search
def search(arr): n = len(arr) XOR = 0 for i in range(n): XOR = XOR ^ arr[i] return XOR
code_generation
[]
python
[]
null
[]
[ [ "[1,1,2,2,3]", "3" ], [ "[1,1,3,3,4,4,5,5,7,7,8]", "8" ], [ "[1,2,2,3,3,4,4]", "1" ] ]
119
Write a python function to find the element that appears only once in a sorted array.
MBPP_sanitized
max_product_tuple
def max_product_tuple(list1): result_max = max([abs(x * y) for (x, y) in list1]) return result_max
code_generation
[]
python
[]
null
[]
[ [ "[(2, 7), (2, 6), (1, 8), (4, 9)] ", "36" ], [ "[(10,20), (15,2), (5,10)] ", "200" ], [ "[(11,44), (10,15), (20,5), (12, 9)] ", "484" ] ]
120
Write a function to find the maximum absolute product between numbers in pairs of tuples within a given list.
MBPP_sanitized
amicable_numbers_sum
def amicable_numbers_sum(limit): if not isinstance(limit, int): return 'Input is not an integer!' if limit < 1: return 'Input must be bigger than 0!' amicables = set() for num in range(2, limit + 1): if num in amicables: continue sum_fact = sum([fact for fact in range(1, num) if num % fact == 0]) sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0]) if num == sum_fact2 and num != sum_fact: amicables.add(num) amicables.add(sum_fact2) return sum(amicables)
code_generation
[]
python
[]
null
[]
[ [ "999", "504" ], [ "9999", "31626" ], [ "99", "0" ] ]
123
Write a function to sum all amicable numbers from 1 to a specified number.
MBPP_sanitized
angle_complex
import cmath def angle_complex(a, b): cn = complex(a, b) angle = cmath.phase(a + b) return angle
code_generation
[]
python
[ "import cmath" ]
null
[]
[]
124
Write a function to get the angle of a complex number.
MBPP_sanitized
find_length
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
code_generation
[]
python
[]
null
[]
[ [ "\"11000010001\"", "6" ], [ "\"10111\"", "1" ], [ "\"11011101100101\"", "2" ] ]
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.
MBPP_sanitized
sum
def sum(a, b): sum = 0 for i in range(1, min(a, b)): if a % i == 0 and b % i == 0: sum += i return sum
code_generation
[]
python
[]
null
[]
[ [ "10,15", "6" ], [ "100,150", "93" ], [ "4,6", "3" ] ]
126
Write a python function to find the sum of common divisors of two given numbers.
MBPP_sanitized
multiply_int
def multiply_int(x, y): if y < 0: return -multiply_int(x, -y) elif y == 0: return 0 elif y == 1: return x else: return x + multiply_int(x, y - 1)
code_generation
[]
python
[]
null
[]
[ [ "10,20", "200" ], [ "5,10", "50" ], [ "4,8", "32" ] ]
127
Write a function to multiply two integers.
MBPP_sanitized
long_words
def long_words(n, str): word_len = [] txt = str.split(' ') for x in txt: if len(x) > n: word_len.append(x) return word_len
code_generation
[]
python
[]
null
[]
[ [ "3,\"python is a programming language\"", "['python','programming','language']" ], [ "2,\"writing a program\"", "['writing','program']" ], [ "5,\"sorting list\"", "['sorting']" ] ]
128
Write a function to find words that are longer than n characters from a given list of words.
MBPP_sanitized
magic_square_test
def magic_square_test(my_matrix): iSize = len(my_matrix[0]) sum_list = [] sum_list.extend([sum(lines) for lines in my_matrix]) for col in range(iSize): sum_list.append(sum((row[col] for row in my_matrix))) result1 = 0 for i in range(0, iSize): result1 += my_matrix[i][i] sum_list.append(result1) result2 = 0 for i in range(iSize - 1, -1, -1): result2 += my_matrix[i][i] sum_list.append(result2) if len(set(sum_list)) > 1: return False return True
code_generation
[]
python
[]
null
[]
[ [ "[[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]]", "True" ], [ "[[2, 7, 6], [9, 5, 1], [4, 3, 8]]", "True" ], [ "[[2, 7, 6], [9, 5, 1], [4, 3, 7]]", "False" ] ]
129
Write a function to calculate whether the matrix is a magic square.
MBPP_sanitized
max_occurrences
from collections import defaultdict def max_occurrences(nums): dict = defaultdict(int) for i in nums: dict[i] += 1 result = max(dict.items(), key=lambda x: x[1]) return result[0]
code_generation
[]
python
[ "from collections import defaultdict" ]
null
[]
[ [ "[2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2]", "2" ], [ "[2,3,8,4,7,9,8,7,9,15,14,10,12,13,16,18]", "8" ], [ "[10,20,20,30,40,90,80,50,30,20,50,10]", "20" ] ]
130
Write a function to find the item with maximum frequency in a given list.
MBPP_sanitized
reverse_vowels
def reverse_vowels(str1): vowels = '' for char in str1: if char in 'aeiouAEIOU': vowels += char result_string = '' for char in str1: if char in 'aeiouAEIOU': result_string += vowels[-1] vowels = vowels[:-1] else: result_string += char return result_string
code_generation
[]
python
[]
null
[]
[ [ "\"Python\"", "\"Python\"" ], [ "\"USA\"", "\"ASU\"" ], [ "\"ab\"", "\"ab\"" ] ]
131
Write a python function to reverse only the vowels of a given string (where y is not a vowel).
MBPP_sanitized
tup_string
def tup_string(tup1): str = ''.join(tup1) return str
code_generation
[]
python
[]
null
[]
[ [ "('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's')", "(\"exercises\")" ], [ "('p','y','t','h','o','n')", "(\"python\")" ], [ "('p','r','o','g','r','a','m')", "(\"program\")" ] ]
132
Write a function to convert a tuple to a string.
MBPP_sanitized
sum_negativenum
def sum_negativenum(nums): sum_negativenum = list(filter(lambda nums: nums < 0, nums)) return sum(sum_negativenum)
code_generation
[]
python
[]
null
[]
[ [ "[2, 4, -6, -9, 11, -12, 14, -5, 17]", "-32" ], [ "[10,15,-14,13,-18,12,-20]", "-52" ], [ "[19, -65, 57, 39, 152,-639, 121, 44, 90, -190]", "-894" ] ]
133
Write a function to calculate the sum of the negative numbers of a given list of numbers.
MBPP_sanitized
hexagonal_num
def hexagonal_num(n): return n * (2 * n - 1)
code_generation
[]
python
[]
null
[]
[ [ "10", "190" ], [ "5", "45" ], [ "7", "91" ] ]
135
Write a function to find the nth hexagonal number.
MBPP_sanitized
zero_count
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)
code_generation
[]
python
[ "from array import array" ]
null
[]
[]
137
Write a function to find the ratio of zeroes to non-zeroes in an array of integers.
MBPP_sanitized
is_Sum_Of_Powers_Of_Two
def is_Sum_Of_Powers_Of_Two(n): if n % 2 == 1: return False else: return True
code_generation
[]
python
[]
null
[]
[ [ "10", "True" ], [ "7", "False" ], [ "14", "True" ] ]
138
Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.
MBPP_sanitized
circle_circumference
def circle_circumference(r): perimeter = 2 * 3.1415 * r return perimeter
code_generation
[]
python
[]
null
[]
[]
139
Write a function to find the circumference of a circle.
MBPP_sanitized
extract_singly
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
code_generation
[]
python
[]
null
[]
[ [ "[(3, 4, 5), (4, 5, 7), (1, 4)]", "set([3, 4, 5, 7, 1])" ], [ "[(1, 2, 3), (4, 2, 3), (7, 8)]", "set([1, 2, 3, 4, 7, 8])" ], [ "[(7, 8, 9), (10, 11, 12), (10, 11)]", "set([7, 8, 9, 10, 11, 12])" ] ]
140
Write a function to flatten the list of lists into a single set of numbers.
MBPP_sanitized
pancake_sort
def pancake_sort(nums): arr_len = len(nums) while arr_len > 1: mi = nums.index(max(nums[0:arr_len])) nums = nums[mi::-1] + nums[mi + 1:len(nums)] nums = nums[arr_len - 1::-1] + nums[arr_len:len(nums)] arr_len -= 1 return nums
code_generation
[]
python
[]
null
[]
[ [ "[15, 79, 25, 38, 69]", "[15, 25, 38, 69, 79]" ], [ "[98, 12, 54, 36, 85]", "[12, 36, 54, 85, 98]" ], [ "[41, 42, 32, 12, 23]", "[12, 23, 32, 41, 42]" ] ]
141
Write a function to sort a list of elements.
MBPP_sanitized
count_samepair
def count_samepair(list1, list2, list3): result = sum((m == n == o for (m, n, o) in zip(list1, list2, list3))) return result
code_generation
[]
python
[]
null
[]
[ [ "[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" ], [ "[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" ], [ "[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" ] ]
142
Write a function to count number items that are identical in the same position of three given lists.
MBPP_sanitized
find_lists
def find_lists(Input): if isinstance(Input, list): return 1 else: return len(Input)
code_generation
[]
python
[]
null
[]
[ [ "([1, 2, 3, 4], [5, 6, 7, 8])", "2" ], [ "([1, 2], [3, 4], [5, 6])", "3" ], [ "([9, 8, 7, 6, 5, 4, 3, 2, 1])", "1" ] ]
143
Write a function to find number of lists present in the given tuple.
MBPP_sanitized
max_Abs_Diff
def max_Abs_Diff(arr): n = len(arr) minEle = arr[0] maxEle = arr[0] for i in range(1, n): minEle = min(minEle, arr[i]) maxEle = max(maxEle, arr[i]) return maxEle - minEle
code_generation
[]
python
[]
null
[]
[ [ "(2,1,5,3)", "4" ], [ "(9,3,2,5,1)", "8" ], [ "(3,2,1)", "2" ] ]
145
Write a python function to find the maximum difference between any two elements in a given array.
MBPP_sanitized
find_solution
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
code_generation
[]
python
[]
null
[]
[ [ "2, 3, 7", "(2, 1)" ], [ "4, 2, 7", null ], [ "1, 13, 17", "(4, 1)" ] ]
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.
MBPP_sanitized
remove_elements
def remove_elements(list1, list2): result = [x for x in list1 if x not in list2] return result
code_generation
[]
python
[]
null
[]
[ [ "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 4, 6, 8]", "[1, 3, 5, 7, 9, 10]" ], [ "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 3, 5, 7]", "[2, 4, 6, 8, 9, 10]" ], [ "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [5, 7]", "[1, 2, 3, 4, 6, 8, 9, 10]" ] ]
161
Write a function to remove all elements from a given list present in another list.
MBPP_sanitized
sum_series
def sum_series(n): if n < 1: return 0 else: return n + sum_series(n - 2)
code_generation
[]
python
[]
null
[]
[ [ "6", "12" ], [ "10", "30" ], [ "9", "25" ] ]
162
Write a function to calculate the sum (n - 2*i) from i=0 to n // 2, for instance n + (n-2) + (n-4)... (until n-x =< 0).
MBPP_sanitized
area_polygon
from math import tan, pi def area_polygon(s, l): area = s * l ** 2 / (4 * tan(pi / s)) return area
code_generation
[]
python
[ "from math import tan, pi" ]
null
[]
[]
163
Write a function to calculate the area of a regular polygon given the length and number of its sides.
MBPP_sanitized
are_equivalent
import math def div_sum(n): total = 1 i = 2 while i * i <= n: if n % i == 0: total = total + i + math.floor(n / i) i += 1 return total def are_equivalent(num1, num2): return div_sum(num1) == div_sum(num2)
code_generation
[]
python
[ "import math " ]
null
[]
[ [ "36, 57", "False" ], [ "2, 4", "False" ], [ "23, 47", "True" ] ]
164
Write a function to determine if the sum of the divisors of two integers are the same.
MBPP_sanitized
count_char_position
def count_char_position(str1): count_chars = 0 for i in range(len(str1)): if i == ord(str1[i]) - ord('A') or i == ord(str1[i]) - ord('a'): count_chars += 1 return count_chars
code_generation
[]
python
[]
null
[]
[ [ "\"xbcefg\"", "2" ], [ "\"ABcED\"", "3" ], [ "\"AbgdeF\"", "5" ] ]
165
Write a function to count the number of characters in a string that occur at the same position in the string as in the English alphabet (case insensitive).
MBPP_sanitized
find_even_pair
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
code_generation
[]
python
[]
null
[]
[ [ "[5, 4, 7, 2, 1]", "4" ], [ "[7, 2, 8, 1, 0, 5, 11]", "9" ], [ "[1, 2, 3]", "1" ] ]
166
Write a function that counts the number of pairs of integers in a list that xor to an even number.
MBPP_sanitized
next_power_of_2
def next_power_of_2(n): if n and (not n & n - 1): return n count = 0 while n != 0: n >>= 1 count += 1 return 1 << count
code_generation
[]
python
[]
null
[]
[ [ "0", "1" ], [ "5", "8" ], [ "17", "32" ] ]
167
Write a python function to find the smallest power of 2 greater than or equal to n.
MBPP_sanitized
frequency
def frequency(a, x): count = 0 for i in a: if i == x: count += 1 return count
code_generation
[]
python
[]
null
[]
[ [ "[1,2,3], 4", "0" ], [ "[1,2,2,3,3,3,4], 3", "3" ], [ "[0,1,2,3,1,2], 1", "2" ] ]
168
Write a function to count the number of occurrences of a number in a given list.
MBPP_sanitized
sum_range_list
def sum_range_list(list1, m, n): sum_range = 0 for i in range(m, n + 1, 1): sum_range += list1[i] return sum_range
code_generation
[]
python
[]
null
[]
[ [ "[2,1,5,6,8,3,4,9,10,11,8,12], 8, 10", "29" ], [ "[2,1,5,6,8,3,4,9,10,11,8,12], 5, 7", "16" ], [ "[2,1,5,6,8,3,4,9,10,11,8,12], 7, 10", "38" ] ]
170
Write a function to find the sum of numbers in a list within a range specified by two indices.
MBPP_sanitized
perimeter_pentagon
import math def perimeter_pentagon(a): perimeter = 5 * a return perimeter
code_generation
[]
python
[ "import math" ]
null
[]
[ [ "5", "25" ], [ "10", "50" ], [ "15", "75" ] ]
171
Write a function to find the perimeter of a regular pentagon from the length of its sides.
MBPP_sanitized
count_occurance
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
code_generation
[]
python
[]
null
[]
[ [ "\"letstdlenstdporstd\"", "3" ], [ "\"truststdsolensporsd\"", "1" ], [ "\"makestdsostdworthit\"", "2" ], [ "\"stds\"", "1" ], [ "\"\"", "0" ] ]
172
Write a function to count the number of occurence of the string 'std' in a given string.
MBPP_sanitized
check_type
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
code_generation
[]
python
[]
null
[]
[ [ "(5, 6, 7, 3, 5, 6) ", "True" ], [ "(1, 2, \"4\") ", "False" ], [ "(3, 2, 1, 4, 5) ", "True" ] ]
222
Write a function to check if all the elements in tuple have same data type or not.
MBPP_sanitized
is_majority
def is_majority(arr, n, x): i = binary_search(arr, 0, n - 1, x) if i == -1: return False if i + n // 2 <= n - 1 and arr[i + n // 2] == x: return True else: return False def binary_search(arr, low, high, x): if high >= low: mid = (low + high) // 2 if (mid == 0 or x > arr[mid - 1]) and arr[mid] == x: return mid elif x > arr[mid]: return binary_search(arr, mid + 1, high, x) else: return binary_search(arr, low, mid - 1, x) return -1
code_generation
[]
python
[]
null
[]
[ [ "[1, 2, 3, 3, 3, 3, 10], 7, 3", "True" ], [ "[1, 1, 2, 4, 4, 4, 6, 6], 8, 4", "False" ], [ "[1, 1, 1, 2, 2], 5, 1", "True" ], [ "[1, 1, 2, 2], 5, 1", "False" ] ]
223
Write a function that takes in a sorted array, its length (n), and an element and returns whether the element is the majority element in the given sorted array. (The majority element is the element that occurs more than n/2 times.)
MBPP_sanitized
count_Set_Bits
def count_Set_Bits(n): count = 0 while n: count += n & 1 n >>= 1 return count
code_generation
[]
python
[]
null
[]
[ [ "2", "1" ], [ "4", "1" ], [ "6", "2" ] ]
224
Write a python function to count the number of set bits (binary digits with value 1) in a given number.
MBPP_sanitized
odd_values_string
def odd_values_string(str): result = '' for i in range(len(str)): if i % 2 == 0: result = result + str[i] return result
code_generation
[]
python
[]
null
[]
[ [ "'abcdef'", "'ace'" ], [ "'python'", "'pto'" ], [ "'data'", "'dt'" ], [ "'lambs'", "'lms'" ] ]
226
Write a python function to remove the characters which have odd index values of a given string.
MBPP_sanitized
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
108