@infersec/conduit 1.65.0 → 1.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2656 @@
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath as __fileURLToPath } from 'node:url';
3
+ import { dirname as __pathDirname } from 'node:path';
4
+ const __filename = __fileURLToPath(import.meta.url);
5
+ const __dirname = __pathDirname(__filename);
6
+
7
+ var mbppplus = [
8
+ {
9
+ assertions: "\nassert similar_elements((3, 4, 5, 6),(5, 7, 4, 10)) == (4, 5)\nassert similar_elements((1, 2, 3, 4),(5, 4, 3, 7)) == (3, 4)\nassert similar_elements((11, 12, 14, 13),(17, 15, 14, 13)) == (13, 14)\n",
10
+ entryPoint: "similar_elements",
11
+ id: "Mbpp/2",
12
+ prompt: "\"\"\"\nWrite a function to find the shared elements from the given two lists.\nassert set(similar_elements((3, 4, 5, 6),(5, 7, 4, 10))) == set((4, 5))\n\"\"\"\n",
13
+ solution: "\ndef similar_elements(test_tup1, test_tup2):\n return tuple(set(test_tup1) & set(test_tup2))\n"
14
+ },
15
+ {
16
+ assertions: "\nassert is_not_prime(1) == True\nassert is_not_prime(2) == False\nassert is_not_prime(10) == True\nassert is_not_prime(35) == True\nassert is_not_prime(37) == False\n",
17
+ entryPoint: "is_not_prime",
18
+ id: "Mbpp/3",
19
+ prompt: "\"\"\"\nWrite a python function to identify non-prime numbers.\nassert is_not_prime(2) == False\n\"\"\"\n",
20
+ solution: "\nimport math\ndef is_not_prime(n):\n if n == 1:\n return True\n for i in range(2, int(math.sqrt(n))+1):\n if n % i == 0:\n return True\n return False\n"
21
+ },
22
+ {
23
+ assertions: "\nassert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],3)==[85, 75, 65]\nassert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],2)==[85, 75]\nassert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],5)==[85, 75, 65, 58, 35]\n",
24
+ entryPoint: "heap_queue_largest",
25
+ id: "Mbpp/4",
26
+ prompt: "\"\"\"\nWrite a function to find the n largest integers from a given list of numbers, returned in descending order.\nassert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],3)==[85, 75, 65]\n\"\"\"\n",
27
+ solution: "\nimport heapq as hq\ndef heap_queue_largest(nums: list,n: int) -> list:\n largest_nums = hq.nlargest(n, nums)\n return largest_nums\n"
28
+ },
29
+ {
30
+ assertions: "\nassert differ_At_One_Bit_Pos(13,9) == True\nassert differ_At_One_Bit_Pos(15,8) == False\nassert differ_At_One_Bit_Pos(2,4) == False\nassert differ_At_One_Bit_Pos(2, 3) == True\nassert differ_At_One_Bit_Pos(5, 1) == True\nassert differ_At_One_Bit_Pos(1, 5) == True\n",
31
+ entryPoint: "differ_At_One_Bit_Pos",
32
+ id: "Mbpp/6",
33
+ prompt: "\"\"\"\nWrite a python function to check whether the two numbers differ at one bit position only or not.\nassert differ_At_One_Bit_Pos(13,9) == True\n\"\"\"\n",
34
+ solution: "\ndef is_Power_Of_Two(x: int): \n return x > 0 and (x & (x - 1)) == 0\ndef differ_At_One_Bit_Pos(a: int,b: int):\n return is_Power_Of_Two(a ^ b)\n"
35
+ },
36
+ {
37
+ assertions: "\nassert set(find_char_long('Please move back to stream')) == set(['Please', 'move', 'back', 'stream'])\nassert set(find_char_long('Jing Eco and Tech')) == set(['Jing', 'Tech'])\nassert set(find_char_long('Jhingai wulu road Zone 3')) == set(['Jhingai', 'wulu', 'road', 'Zone'])\n",
38
+ entryPoint: "find_char_long",
39
+ id: "Mbpp/7",
40
+ prompt: "\"\"\"\nWrite a function to find all words which are at least 4 characters long in a string.\nassert set(find_char_long('Please move back to stream')) == set(['Please', 'move', 'back', 'stream'])\n\"\"\"\n",
41
+ solution: "\nimport re\ndef find_char_long(text):\n return (re.findall(r\"\\b\\w{4,}\\b\", text))\n"
42
+ },
43
+ {
44
+ assertions: "\nassert square_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\nassert square_nums([10,20,30])==([100,400,900])\nassert square_nums([12,15])==([144,225])\n",
45
+ entryPoint: "square_nums",
46
+ id: "Mbpp/8",
47
+ prompt: "\"\"\"\nWrite a function to find squares of individual elements in a list.\nassert square_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n\"\"\"\n",
48
+ solution: "\ndef square_nums(nums):\n return [i**2 for i in nums]\n"
49
+ },
50
+ {
51
+ assertions: "\nassert find_Rotations(\"aaaa\") == 1\nassert find_Rotations(\"ab\") == 2\nassert find_Rotations(\"abc\") == 3\n",
52
+ entryPoint: "find_Rotations",
53
+ id: "Mbpp/9",
54
+ prompt: "\"\"\"\nWrite a python function to find the minimum number of rotations (greater than 0) required to get the same string.\nassert find_Rotations(\"aaaa\") == 1\n\"\"\"\n",
55
+ solution: "\ndef find_Rotations(s): \n n = len(s)\n s += s\n for i in range(1, n + 1):\n if s[i: i + n] == s[0: n]:\n return i\n return n\n"
56
+ },
57
+ {
58
+ assertions: "\nassert remove_Occ(\"hello\",\"l\") == \"heo\"\nassert remove_Occ(\"abcda\",\"a\") == \"bcd\"\nassert remove_Occ(\"PHP\",\"P\") == \"H\"\n",
59
+ entryPoint: "remove_Occ",
60
+ id: "Mbpp/11",
61
+ prompt: "\"\"\"\nWrite a python function to remove first and last occurrence of a given character from the string.\nassert remove_Occ(\"hello\",\"l\") == \"heo\"\n\"\"\"\n",
62
+ solution: "\ndef remove_Occ(s,ch): \n s = s.replace(ch, '', 1)\n s = s[::-1].replace(ch, '', 1)[::-1]\n return s \n"
63
+ },
64
+ {
65
+ assertions: "\nassert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]]\nassert sort_matrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])==[[-2, 4, -5], [1, -1, 1], [1, 2, 3]]\nassert sort_matrix([[5,8,9],[6,4,3],[2,1,4]])==[[2, 1, 4], [6, 4, 3], [5, 8, 9]]\n",
66
+ entryPoint: "sort_matrix",
67
+ id: "Mbpp/12",
68
+ prompt: "\"\"\"\nWrite a function to sort a given matrix in ascending order according to the sum of its rows.\nassert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]]\n\"\"\"\n",
69
+ solution: "\ndef sort_matrix(M):\n result = sorted(M, key=sum)\n return result\n"
70
+ },
71
+ {
72
+ assertions: "\nassert find_Volume(10,8,6) == 240\nassert find_Volume(3,2,2) == 6\nassert find_Volume(1,2,1) == 1\n",
73
+ entryPoint: "find_Volume",
74
+ id: "Mbpp/14",
75
+ prompt: "\"\"\"\nWrite a python function to find the volume of a triangular prism.\nassert find_Volume(10,8,6) == 240\n\"\"\"\n",
76
+ solution: "\ndef find_Volume(l,b,h) : \n return ((l * b * h) / 2) \n"
77
+ },
78
+ {
79
+ assertions: "\nassert text_lowercase_underscore(\"aab_cbbbc\")==(True)\nassert text_lowercase_underscore(\"aab_Abbbc\")==(False)\nassert text_lowercase_underscore(\"Aaab_abbbc\")==(False)\n",
80
+ entryPoint: "text_lowercase_underscore",
81
+ id: "Mbpp/16",
82
+ prompt: "\"\"\"\nWrite a function to that returns true if the input string contains sequences of lowercase letters joined with an underscore and false otherwise.\nassert text_lowercase_underscore(\"aab_cbbbc\")==(True)\n\"\"\"\n",
83
+ solution: "\nimport re\ndef text_lowercase_underscore(text):\n return bool(re.match('^[a-z]+(_[a-z]+)*$', text))\n"
84
+ },
85
+ {
86
+ assertions: "\nassert square_perimeter(10)==40\nassert square_perimeter(5)==20\nassert square_perimeter(4)==16\n",
87
+ entryPoint: "square_perimeter",
88
+ id: "Mbpp/17",
89
+ prompt: "\"\"\"\nWrite a function that returns the perimeter of a square given its side length as input.\nassert square_perimeter(10)==40\n\"\"\"\n",
90
+ solution: "\ndef square_perimeter(a):\n return 4*a\n"
91
+ },
92
+ {
93
+ assertions: "\nassert remove_dirty_chars(\"probasscurve\", \"pros\") == 'bacuve'\nassert remove_dirty_chars(\"digitalindia\", \"talent\") == 'digiidi'\nassert remove_dirty_chars(\"exoticmiles\", \"toxic\") == 'emles'\n",
94
+ entryPoint: "remove_dirty_chars",
95
+ id: "Mbpp/18",
96
+ prompt: "\"\"\"\nWrite a function to remove characters from the first string which are present in the second string.\nassert remove_dirty_chars(\"probasscurve\", \"pros\") == 'bacuve'\n\"\"\"\n",
97
+ solution: "\ndef remove_dirty_chars(string, second_string): \n\tfor char in second_string:\n\t\tstring = string.replace(char, '')\n\treturn string\n"
98
+ },
99
+ {
100
+ assertions: "\nassert test_duplicate(([1,2,3,4,5]))==False\nassert test_duplicate(([1,2,3,4, 4]))==True\nassert test_duplicate([1,1,2,2,3,3,4,4,5])==True\n",
101
+ entryPoint: "test_duplicate",
102
+ id: "Mbpp/19",
103
+ prompt: "\"\"\"\nWrite a function to find whether a given array of integers contains any duplicate element.\nassert test_duplicate(([1,2,3,4,5]))==False\n\"\"\"\n",
104
+ solution: "\ndef test_duplicate(arraynums):\n return len(arraynums) != len(set(arraynums))\n"
105
+ },
106
+ {
107
+ assertions: "\nassert is_woodall(383) == True\nassert is_woodall(254) == False\nassert is_woodall(200) == False\n",
108
+ entryPoint: "is_woodall",
109
+ id: "Mbpp/20",
110
+ prompt: "\"\"\"\nWrite a function to check if the given number is woodball or not.\nassert is_woodall(383) == True\n\"\"\"\n",
111
+ solution: "\ndef is_woodall(x): \n\tif not isinstance(x, int):\n\t\treturn False\n\tif x <= 0 or x % 2 == 0:\n\t\treturn False\n\tif (x == 1): \n\t\treturn True\n\tx += 1 \n\ti = 0\n\twhile (x % 2 == 0): \n\t\tx /= 2\n\t\ti += 1\n\t\tif (i == x): \n\t\t\treturn True\n\treturn False\n"
112
+ },
113
+ {
114
+ assertions: "\nassert check(70) == False\nassert check(23) == False\nassert check(73) == True\n",
115
+ entryPoint: "check",
116
+ id: "Mbpp/56",
117
+ prompt: "\"\"\"\nWrite a python function to check if a given number is one less than twice its reverse.\nassert check(70) == False\n\"\"\"\n",
118
+ solution: "\ndef check(n): \n return n == 2 * int(str(n)[::-1]) - 1\n"
119
+ },
120
+ {
121
+ assertions: "\nassert find_Max_Num([1,2,3]) == 321\nassert find_Max_Num([4,5,6,1]) == 6541\nassert find_Max_Num([1,2,3,9]) == 9321\n",
122
+ entryPoint: "find_Max_Num",
123
+ id: "Mbpp/57",
124
+ prompt: "\"\"\"\nWrite a python function to find the largest number that can be formed with the given list of digits.\nassert find_Max_Num([1,2,3]) == 321\n\"\"\"\n",
125
+ solution: "\ndef find_Max_Num(arr) : \n arr.sort(reverse = True)\n return int(\"\".join(map(str,arr)))\n"
126
+ },
127
+ {
128
+ assertions: "\nassert opposite_Signs(1,-2) == True\nassert opposite_Signs(3,2) == False\nassert opposite_Signs(-10,-10) == False\nassert opposite_Signs(-2,2) == True\n",
129
+ entryPoint: "opposite_Signs",
130
+ id: "Mbpp/58",
131
+ prompt: "\"\"\"\nWrite a python function to check whether the given two integers have opposite sign or not.\nassert opposite_Signs(1,-2) == True\n\"\"\"\n",
132
+ solution: "\ndef opposite_Signs(x,y): \n return ((x ^ y) < 0) \n"
133
+ },
134
+ {
135
+ assertions: "\nassert is_octagonal(5) == 65\nassert is_octagonal(10) == 280\nassert is_octagonal(15) == 645\n",
136
+ entryPoint: "is_octagonal",
137
+ id: "Mbpp/59",
138
+ prompt: "\"\"\"\nWrite a function to find the nth octagonal number.\nassert is_octagonal(5) == 65\n\"\"\"\n",
139
+ solution: "\ndef is_octagonal(n): \n\treturn 3 * n * n - 2 * n \n"
140
+ },
141
+ {
142
+ assertions: "\nassert count_Substrings('112112') == 6\nassert count_Substrings('111') == 6\nassert count_Substrings('1101112') == 12\n",
143
+ entryPoint: "count_Substrings",
144
+ id: "Mbpp/61",
145
+ prompt: "\"\"\"\nWrite a python function to count the number of substrings with the sum of digits equal to their length.\nassert count_Substrings('112112') == 6\n\"\"\"\n",
146
+ solution: "\nfrom collections import defaultdict\ndef count_Substrings(s):\n n, count, sum = len(s), 0, 0\n mp = defaultdict(lambda : 0)\n mp[0] += 1\n for i in range(n):\n sum += ord(s[i]) - ord('0')\n count += mp[sum - i - 1]\n mp[sum - i - 1] += 1\n return count\n"
147
+ },
148
+ {
149
+ assertions: "\nassert smallest_num([10, 20, 1, 45, 99]) == 1\nassert smallest_num([1, 2, 3]) == 1\nassert smallest_num([45, 46, 50, 60]) == 45\n",
150
+ entryPoint: "smallest_num",
151
+ id: "Mbpp/62",
152
+ prompt: "\"\"\"\nWrite a python function to find smallest number in a list.\nassert smallest_num([10, 20, 1, 45, 99]) == 1\n\"\"\"\n",
153
+ solution: "\ndef smallest_num(xs):\n assert len(xs) > 0, \"invalid inputs\"\n return min(xs)\n"
154
+ },
155
+ {
156
+ assertions: "\nassert max_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 7\nassert max_difference([(4, 6), (2, 17), (9, 13), (11, 12)]) == 15\nassert max_difference([(12, 35), (21, 27), (13, 23), (41, 22)]) == 23\n",
157
+ entryPoint: "max_difference",
158
+ id: "Mbpp/63",
159
+ prompt: "\"\"\"\nWrite a function to find the maximum difference between available pairs in the given tuple list.\nassert max_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 7\n\"\"\"\n",
160
+ solution: "\ndef max_difference(test_list):\n return max(abs(a - b) for a, b in test_list)\n"
161
+ },
162
+ {
163
+ assertions: "\nassert subject_marks([('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])==[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)]\nassert subject_marks([('Telugu',49),('Hindhi',54),('Social',33)])==([('Social',33),('Telugu',49),('Hindhi',54)])\nassert subject_marks([('Physics',96),('Chemistry',97),('Biology',45)])==([('Biology',45),('Physics',96),('Chemistry',97)])\n",
164
+ entryPoint: "subject_marks",
165
+ id: "Mbpp/64",
166
+ prompt: "\"\"\"\nWrite a function to sort a list of tuples using the second value of each tuple.\nassert subject_marks([('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])==[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)]\n\"\"\"\n",
167
+ solution: "\ndef subject_marks(subjectmarks):\n#subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])\n subjectmarks.sort(key = lambda x: x[1])\n return subjectmarks\n"
168
+ },
169
+ {
170
+ assertions: "\nassert recursive_list_sum(([1, 2, [3,4],[5,6]]))==21\nassert recursive_list_sum(([7, 10, [15,14],[19,41]]))==106\nassert recursive_list_sum(([10, 20, [30,40],[50,60]]))==210\n",
171
+ entryPoint: "recursive_list_sum",
172
+ id: "Mbpp/65",
173
+ prompt: "\"\"\"\nWrite a function to flatten a list and sum all of its elements.\nassert recursive_list_sum(([1, 2, [3,4],[5,6]]))==21\n\"\"\"\n",
174
+ solution: "\ndef recursive_list_sum(data_list):\n\ttotal = 0\n\tfor element in data_list:\n\t\tif type(element) == type([]):\n\t\t\ttotal = total + recursive_list_sum(element)\n\t\telse:\n\t\t\ttotal = total + element\n\treturn total\n"
175
+ },
176
+ {
177
+ assertions: "\nassert pos_count([1,-2,3,-4]) == 2\nassert pos_count([3,4,5,-1]) == 3\nassert pos_count([1,2,3,4]) == 4\n",
178
+ entryPoint: "pos_count",
179
+ id: "Mbpp/66",
180
+ prompt: "\"\"\"\nWrite a python function to count the number of positive numbers in a list.\nassert pos_count([1,-2,3,-4]) == 2\n\"\"\"\n",
181
+ solution: "\ndef pos_count(l):\n return len([x for x in l if x > 0])\n"
182
+ },
183
+ {
184
+ assertions: "\nassert bell_number(2)==2\nassert bell_number(10)==115975\nassert bell_number(56)==6775685320645824322581483068371419745979053216268760300\n",
185
+ entryPoint: "bell_number",
186
+ id: "Mbpp/67",
187
+ prompt: "\"\"\"\nWrite a function to find the number of ways to partition a set of Bell numbers.\nassert bell_number(2)==2\n\"\"\"\n",
188
+ solution: "\ndef bell_number(n): \n bell = [[0 for i in range(n+1)] for j in range(n+1)] \n bell[0][0] = 1\n for i in range(1, n+1): \n bell[i][0] = bell[i-1][i-1] \n for j in range(1, i+1): \n bell[i][j] = bell[i-1][j-1] + bell[i][j-1] \n return bell[n][0] \n"
189
+ },
190
+ {
191
+ assertions: "\nassert is_Monotonic([6, 5, 4, 4]) == True\nassert is_Monotonic([1, 2, 2, 3]) == True\nassert is_Monotonic([1, 3, 2]) == False\n",
192
+ entryPoint: "is_Monotonic",
193
+ id: "Mbpp/68",
194
+ prompt: "\"\"\"\nWrite a python function to check whether the given array is monotonic or not.\nassert is_Monotonic([6, 5, 4, 4]) == True\n\"\"\"\n",
195
+ solution: "\ndef is_Monotonic(A): \n return all(a <= b for a, b in zip(A, A[1:])) or all(a >= b for a, b in zip(A, A[1:]))\n"
196
+ },
197
+ {
198
+ assertions: "\nassert is_sublist([2,4,3,5,7],[3,7])==False\nassert is_sublist([2,4,3,5,7],[4,3])==True\nassert is_sublist([2,4,3,5,7],[1,6])==False\n",
199
+ entryPoint: "is_sublist",
200
+ id: "Mbpp/69",
201
+ prompt: "\"\"\"\nWrite a function to check whether a list contains the given sublist or not.\nassert is_sublist([2,4,3,5,7],[3,7])==False\n\"\"\"\n",
202
+ solution: "\ndef is_sublist(l, s):\n\tif len(l) < len(s):\n\t\treturn False\n\treturn any(l[i:i+len(s)] == s for i in range(len(l)-len(s)+1))\n"
203
+ },
204
+ {
205
+ assertions: "\nassert get_equal([(11, 22, 33), (44, 55, 66)]) == True\nassert get_equal([(1, 2, 3), (4, 5, 6, 7)]) == False\nassert get_equal([(1, 2), (3, 4)]) == True\n",
206
+ entryPoint: "get_equal",
207
+ id: "Mbpp/70",
208
+ prompt: "\"\"\"\nWrite a function to find whether all the given tuples have equal length or not.\nassert get_equal([(11, 22, 33), (44, 55, 66)]) == True\n\"\"\"\n",
209
+ solution: "\ndef get_equal(Input):\n return len(set(len(item) for item in Input)) == 1\n"
210
+ },
211
+ {
212
+ assertions: "\nassert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79]\nassert comb_sort([41, 32, 15, 19, 22]) == [15, 19, 22, 32, 41]\nassert comb_sort([99, 15, 13, 47]) == [13, 15, 47, 99]\n",
213
+ entryPoint: "comb_sort",
214
+ id: "Mbpp/71",
215
+ prompt: "\"\"\"\nWrite a function to sort a list of elements.\nassert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79]\n\"\"\"\n",
216
+ solution: "\ndef comb_sort(nums):\n n = len(nums)\n gap = n\n shrink = 1.3\n swapped = True\n while gap > 1 or swapped:\n gap = int(gap / shrink)\n if gap < 1:\n gap = 1\n swapped = False\n for i in range(n - gap):\n if nums[i] > nums[i + gap]:\n nums[i], nums[i + gap] = nums[i + gap], nums[i]\n swapped = True\n return nums\n"
217
+ },
218
+ {
219
+ assertions: "\nassert dif_Square(5) == True\nassert dif_Square(10) == False\nassert dif_Square(15) == True\n",
220
+ entryPoint: "dif_Square",
221
+ id: "Mbpp/72",
222
+ prompt: "\"\"\"\nWrite a python function to check whether the given number can be represented as the difference of two squares or not.\nassert dif_Square(5) == True\n\"\"\"\n",
223
+ solution: "\ndef dif_Square(n): \n # see https://www.quora.com/Which-numbers-can-be-expressed-as-the-difference-of-two-squares\n return n % 4 != 2\n"
224
+ },
225
+ {
226
+ assertions: "\nassert is_samepatterns([\"red\",\"green\",\"green\"], [\"a\", \"b\", \"b\"])==True\nassert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\",\"b\"])==False\nassert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\"])==False\n",
227
+ entryPoint: "is_samepatterns",
228
+ id: "Mbpp/74",
229
+ prompt: "\"\"\"\nWrite a function to check whether it follows the sequence given in the patterns array.\nassert is_samepatterns([\"red\",\"green\",\"green\"], [\"a\", \"b\", \"b\"])==True\n\"\"\"\n",
230
+ solution: "\ndef is_samepatterns(colors, patterns): \n if len(colors) != len(patterns):\n return False \n pattern_color_dict = {pattern: set() for pattern in patterns}\n for color, pattern in zip(colors, patterns):\n pattern_color_dict[pattern].add(color)\n return all(len(pattern_color_dict[pattern]) == 1 for pattern in patterns)\n"
231
+ },
232
+ {
233
+ assertions: "\nassert find_tuples([(6, 24, 12), (7, 9, 6), (12, 18, 21)], 6) == [(6, 24, 12)]\nassert find_tuples([(5, 25, 30), (4, 2, 3), (7, 8, 9)], 5) == [(5, 25, 30)]\nassert find_tuples([(7, 9, 16), (8, 16, 4), (19, 17, 18)], 4) == [(8, 16, 4)]\n",
234
+ entryPoint: "find_tuples",
235
+ id: "Mbpp/75",
236
+ prompt: "\"\"\"\nWrite a function to find tuples which have all elements divisible by k from the given list of tuples.\nassert find_tuples([(6, 24, 12), (7, 9, 6), (12, 18, 21)], 6) == [(6, 24, 12)]\n\"\"\"\n",
237
+ solution: "\ndef find_tuples(test_list, K):\n res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)]\n return res\n"
238
+ },
239
+ {
240
+ assertions: "\nassert is_Diff (12345) == False\nassert is_Diff(1212112) == True\nassert is_Diff(1212) == False\n",
241
+ entryPoint: "is_Diff",
242
+ id: "Mbpp/77",
243
+ prompt: "\"\"\"\nWrite a python function to find whether a number is divisible by 11.\nassert is_Diff (12345) == False\n\"\"\"\n",
244
+ solution: "\ndef is_Diff(n): \n return n % 11 == 0 \n"
245
+ },
246
+ {
247
+ assertions: "\nassert word_len(\"Hadoop\") == False\nassert word_len(\"great\") == True\nassert word_len(\"structure\") == True\n",
248
+ entryPoint: "word_len",
249
+ id: "Mbpp/79",
250
+ prompt: "\"\"\"\nWrite a python function to check whether the length of the word is odd or not.\nassert word_len(\"Hadoop\") == False\n\"\"\"\n",
251
+ solution: "\ndef word_len(s): \n return len(s) % 2 == 1\n"
252
+ },
253
+ {
254
+ assertions: "\nassert tetrahedral_number(5) == 35\nassert tetrahedral_number(6) == 56\nassert tetrahedral_number(7) == 84\n",
255
+ entryPoint: "tetrahedral_number",
256
+ id: "Mbpp/80",
257
+ prompt: "\"\"\"\nWrite a function to find the nth tetrahedral number.\nassert tetrahedral_number(5) == 35\n\"\"\"\n",
258
+ solution: "\ndef tetrahedral_number(n): \n\treturn (n * (n + 1) * (n + 2)) / 6\n"
259
+ },
260
+ {
261
+ assertions: "import math\n\nassert math.isclose(volume_sphere(10), 4188.790204786391, rel_tol=0.001)\nassert math.isclose(volume_sphere(25), 65449.84694978735, rel_tol=0.001)\nassert math.isclose(volume_sphere(20), 33510.32163829113, rel_tol=0.001)\n",
262
+ entryPoint: "volume_sphere",
263
+ id: "Mbpp/82",
264
+ prompt: "\"\"\"\nWrite a function to find the volume of a sphere.\nassert math.isclose(volume_sphere(10), 4188.790204786391, rel_tol=0.001)\n\"\"\"\n",
265
+ solution: "\nimport math\ndef volume_sphere(r):\n return (4./3.) * math.pi * (r**3)\n"
266
+ },
267
+ {
268
+ assertions: "\nassert sequence(10) == 6\nassert sequence(2) == 1\nassert sequence(3) == 2\n",
269
+ entryPoint: "sequence",
270
+ id: "Mbpp/84",
271
+ prompt: "\"\"\"\nWrite a function to find the nth number in the newman conway sequence.\nassert sequence(10) == 6\n\"\"\"\n",
272
+ solution: "\ndef sequence(n): \n\tif n == 1 or n == 2: \n\t\treturn 1\n\tseq = [0] * (n + 1)\n\tseq[1] = seq[2] = 1\n\tfor i in range(3, n + 1):\n\t\tseq[i] = seq[seq[i - 1]] + seq[i - seq[i - 1]]\n\treturn seq[n]\n"
273
+ },
274
+ {
275
+ assertions: "import math\n\nassert math.isclose(surfacearea_sphere(10), 1256.6370614359173, rel_tol=0.001)\nassert math.isclose(surfacearea_sphere(15), 2827.4333882308138, rel_tol=0.001)\nassert math.isclose(surfacearea_sphere(20), 5026.548245743669, rel_tol=0.001)\n",
276
+ entryPoint: "surfacearea_sphere",
277
+ id: "Mbpp/85",
278
+ prompt: "\"\"\"\nWrite a function to find the surface area of a sphere.\nassert math.isclose(surfacearea_sphere(10), 1256.6370614359173, rel_tol=0.001)\n\"\"\"\n",
279
+ solution: "\nimport math\ndef surfacearea_sphere(r):\n return 4 * math.pi * (r**2)\n"
280
+ },
281
+ {
282
+ assertions: "\nassert centered_hexagonal_number(10) == 271\nassert centered_hexagonal_number(2) == 7\nassert centered_hexagonal_number(9) == 217\n",
283
+ entryPoint: "centered_hexagonal_number",
284
+ id: "Mbpp/86",
285
+ prompt: "\"\"\"\nWrite a function to find nth centered hexagonal number.\nassert centered_hexagonal_number(10) == 271\n\"\"\"\n",
286
+ solution: "\ndef centered_hexagonal_number(n):\n return 3 * n * (n - 1) + 1\n"
287
+ },
288
+ {
289
+ assertions: "\nassert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" },{ \"O\": \"Orange\", \"W\": \"White\", \"B\": \"Black\" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White', 'O': 'Orange'}\nassert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" },{\"L\":\"lavender\",\"B\":\"Blue\"})=={'W': 'White', 'P': 'Pink', 'B': 'Black', 'R': 'Red', 'G': 'Green', 'L': 'lavender'}\nassert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" },{\"L\":\"lavender\",\"B\":\"Blue\"},{ \"G\": \"Green\", \"W\": \"White\" })=={'B': 'Black', 'P': 'Pink', 'R': 'Red', 'G': 'Green', 'L': 'lavender', 'W': 'White'}\n",
290
+ entryPoint: "merge_dictionaries_three",
291
+ id: "Mbpp/87",
292
+ prompt: "\"\"\"\nWrite a function to merge three dictionaries into a single dictionary.\nassert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" },{ \"O\": \"Orange\", \"W\": \"White\", \"B\": \"Black\" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White', 'O': 'Orange'}\n\"\"\"\n",
293
+ solution: "\nimport collections as ct\ndef merge_dictionaries_three(dict1,dict2, dict3):\n merged_dict = dict(ct.ChainMap({},dict1,dict2,dict3))\n return merged_dict\n"
294
+ },
295
+ {
296
+ assertions: "\nassert freq_count([10,10,10,10,20,20,20,20,40,40,50,50,30])==({10: 4, 20: 4, 40: 2, 50: 2, 30: 1})\nassert freq_count([1,2,3,4,3,2,4,1,3,1,4])==({1:3, 2:2,3:3,4:3})\nassert freq_count([5,6,7,4,9,10,4,5,6,7,9,5])==({10:1,5:3,6:2,7:2,4:2,9:2})\n",
297
+ entryPoint: "freq_count",
298
+ id: "Mbpp/88",
299
+ prompt: "\"\"\"\nWrite a function to get the frequency of all the elements in a list, returned as a dictionary.\nassert freq_count([10,10,10,10,20,20,20,20,40,40,50,50,30])==({10: 4, 20: 4, 40: 2, 50: 2, 30: 1})\n\"\"\"\n",
300
+ solution: "\nimport collections\ndef freq_count(list1):\n freq_count= collections.Counter(list1)\n return freq_count\n"
301
+ },
302
+ {
303
+ assertions: "\nassert closest_num(11) == 10\nassert closest_num(7) == 6\nassert closest_num(12) == 11\n",
304
+ entryPoint: "closest_num",
305
+ id: "Mbpp/89",
306
+ prompt: "\"\"\"\nWrite a function to find the closest smaller number than n.\nassert closest_num(11) == 10\n\"\"\"\n",
307
+ solution: "\ndef closest_num(N):\n return (N - 1)\n"
308
+ },
309
+ {
310
+ assertions: "\nassert len_log([\"python\",\"PHP\",\"bigdata\"]) == 7\nassert len_log([\"a\",\"ab\",\"abc\"]) == 3\nassert len_log([\"small\",\"big\",\"tall\"]) == 5\n",
311
+ entryPoint: "len_log",
312
+ id: "Mbpp/90",
313
+ prompt: "\"\"\"\nWrite a python function to find the length of the longest word.\nassert len_log([\"python\",\"PHP\",\"bigdata\"]) == 7\n\"\"\"\n",
314
+ solution: "\ndef len_log(list1):\n return max(len(x) for x in list1)\n"
315
+ },
316
+ {
317
+ assertions: "\nassert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ack\")==True\nassert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"abc\")==False\nassert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ange\")==True\n",
318
+ entryPoint: "find_substring",
319
+ id: "Mbpp/91",
320
+ prompt: "\"\"\"\nWrite a function to check if a string is present as a substring in a given list of string values.\nassert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ack\")==True\n\"\"\"\n",
321
+ solution: "\ndef find_substring(str1, sub_str):\n return any(sub_str in s for s in str1)\n"
322
+ },
323
+ {
324
+ assertions: "\nassert is_undulating(1212121) == True\nassert is_undulating(1991) == False\nassert is_undulating(121) == True\n",
325
+ entryPoint: "is_undulating",
326
+ id: "Mbpp/92",
327
+ prompt: "\"\"\"\nWrite a function to check whether the given number is undulating or not.\nassert is_undulating(1212121) == True\n\"\"\"\n",
328
+ solution: "\ndef is_undulating(n): \n\tdigits = [int(digit) for digit in str(n)]\n\tif len(set(digits)) != 2:\n\t\treturn False\n\treturn all(a != b for a, b in zip(digits, digits[1:]))\n"
329
+ },
330
+ {
331
+ assertions: "\nassert power(3,4) == 81\nassert power(2,3) == 8\nassert power(5,5) == 3125\n",
332
+ entryPoint: "power",
333
+ id: "Mbpp/93",
334
+ prompt: "\"\"\"\nWrite a function to calculate the value of 'a' to the power 'b'.\nassert power(3,4) == 81\n\"\"\"\n",
335
+ solution: "\ndef power(a, b):\n\treturn a ** b\n"
336
+ },
337
+ {
338
+ assertions: "\nassert index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]) == 'Varsha'\nassert index_minimum([('Yash', 185), ('Dawood', 125), ('Sanya', 175)]) == 'Dawood'\nassert index_minimum([('Sai', 345), ('Salman', 145), ('Ayesha', 96)]) == 'Ayesha'\n",
339
+ entryPoint: "index_minimum",
340
+ id: "Mbpp/94",
341
+ prompt: "\"\"\"\nGiven a list of tuples, write a function that returns the first value of the tuple with the smallest second value.\nassert index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]) == 'Varsha'\n\"\"\"\n",
342
+ solution: "\nfrom operator import itemgetter \ndef index_minimum(test_list):\n res = min(test_list, key = itemgetter(1))[0]\n return (res) \n"
343
+ },
344
+ {
345
+ assertions: "\nassert Find_Min_Length([[1],[1,2]]) == 1\nassert Find_Min_Length([[1,2],[1,2,3],[1,2,3,4]]) == 2\nassert Find_Min_Length([[3,3,3],[4,4,4,4]]) == 3\n",
346
+ entryPoint: "Find_Min_Length",
347
+ id: "Mbpp/95",
348
+ prompt: "\"\"\"\nWrite a python function to find the length of the smallest list in a list of lists.\nassert Find_Min_Length([[1],[1,2]]) == 1\n\"\"\"\n",
349
+ solution: "\ndef Find_Min_Length(lst): \n minLength = min(len(x) for x in lst )\n return minLength \n"
350
+ },
351
+ {
352
+ assertions: "\nassert divisor(15) == 4\nassert divisor(12) == 6\nassert divisor(9) == 3\n",
353
+ entryPoint: "divisor",
354
+ id: "Mbpp/96",
355
+ prompt: "\"\"\"\nWrite a python function to find the number of divisors of a given integer.\nassert divisor(15) == 4\n\"\"\"\n",
356
+ solution: "\ndef divisor(n):\n return sum(1 for i in range(1, n + 1) if n % i == 0)\n"
357
+ },
358
+ {
359
+ assertions: "\nassert frequency_lists([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]])=={1: 1, 2: 3, 3: 1, 4: 1, 5: 2, 6: 1, 7: 1, 8: 1, 9: 1}\nassert frequency_lists([[1,2,3,4],[5,6,7,8],[9,10,11,12]])=={1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1,10:1,11:1,12:1}\nassert frequency_lists([[20,30,40,17],[18,16,14,13],[10,20,30,40]])=={20:2,30:2,40:2,17: 1,18:1, 16: 1,14: 1,13: 1, 10: 1}\n",
360
+ entryPoint: "frequency_lists",
361
+ id: "Mbpp/97",
362
+ prompt: "\"\"\"\nWrite a function to find frequency of each element in a flattened list of lists, returned in a dictionary.\nassert frequency_lists([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]])=={1: 1, 2: 3, 3: 1, 4: 1, 5: 2, 6: 1, 7: 1, 8: 1, 9: 1}\n\"\"\"\n",
363
+ solution: "\ndef frequency_lists(list1):\n list1 = [item for sublist in list1 for item in sublist]\n return {x: list1.count(x) for x in list1}\n"
364
+ },
365
+ {
366
+ assertions: "import math\n\nassert math.isclose(multiply_num((8, 2, 3, -1, 7)), -67.2, rel_tol=0.001)\nassert math.isclose(multiply_num((-10,-20,-30)), -2000.0, rel_tol=0.001)\nassert math.isclose(multiply_num((19,15,18)), 1710.0, rel_tol=0.001)\n",
367
+ entryPoint: "multiply_num",
368
+ id: "Mbpp/98",
369
+ prompt: "\"\"\"\nWrite a function to multiply all the numbers in a list and divide with the length of the list.\nassert math.isclose(multiply_num((8, 2, 3, -1, 7)), -67.2, rel_tol=0.001)\n\"\"\"\n",
370
+ solution: "\ndef multiply_num(numbers): \n from functools import reduce\n return reduce(lambda x, y: x * y, numbers) / len(numbers)\n"
371
+ },
372
+ {
373
+ assertions: "\nassert decimal_to_binary(8) == '1000'\nassert decimal_to_binary(18) == '10010'\nassert decimal_to_binary(7) == '111'\n",
374
+ entryPoint: "decimal_to_binary",
375
+ id: "Mbpp/99",
376
+ prompt: "\"\"\"\nWrite a function to convert the given decimal number to its binary equivalent, represented as a string with no leading zeros.\nassert decimal_to_binary(8) == '1000'\n\"\"\"\n",
377
+ solution: "\ndef decimal_to_binary(n): \n return bin(n).replace(\"0b\",\"\") \n"
378
+ },
379
+ {
380
+ assertions: "\nassert next_smallest_palindrome(99)==101\nassert next_smallest_palindrome(1221)==1331\nassert next_smallest_palindrome(120)==121\n",
381
+ entryPoint: "next_smallest_palindrome",
382
+ id: "Mbpp/100",
383
+ prompt: "\"\"\"\nWrite a function to find the next smallest palindrome of a specified integer, returned as an integer.\nassert next_smallest_palindrome(99)==101\n\"\"\"\n",
384
+ solution: "\ndef next_smallest_palindrome(num):\n if all(digit == '9' for digit in str(num)):\n return num + 2\n else:\n num = [int(digit) for digit in str(num)]\n n = len(num)\n mid = n // 2\n left_smaller = False\n # if n is odd, ignore the middle digit at first\n i = mid - 1\n j = mid + 1 if n % 2 else mid\n while i >= 0 and num[i] == num[j]:\n i -= 1\n j += 1\n # stop if traverse end or difference found\n if i < 0 or num[i] < num[j]:\n left_smaller = True\n # copy left to right\n while i >= 0:\n num[j] = num[i]\n j += 1\n i -= 1\n # the middle digit must be incremented\n if left_smaller:\n carry = 1\n i = mid - 1\n if n % 2:\n num[mid] += carry\n carry = num[mid] // 10\n num[mid] %= 10\n j = mid + 1\n else:\n j = mid\n while i >= 0:\n num[i] += carry\n carry = num[i] // 10\n num[i] %= 10\n num[j] = num[i]\n j += 1\n i -= 1\n return int(\"\".join(map(str, num)))\n"
385
+ },
386
+ {
387
+ assertions: "\nassert kth_element([12,3,5,7,19], 2) == 3\nassert kth_element([17,24,8,23], 3) == 8\nassert kth_element([16,21,25,36,4], 4) == 36\n",
388
+ entryPoint: "kth_element",
389
+ id: "Mbpp/101",
390
+ prompt: "\"\"\"\nWrite a function to find the kth element in the given array using 1-based indexing.\nassert kth_element([12,3,5,7,19], 2) == 3\n\"\"\"\n",
391
+ solution: "\ndef kth_element(arr, k):\n return arr[k-1]\n"
392
+ },
393
+ {
394
+ assertions: "\nassert snake_to_camel('python_program')=='PythonProgram'\nassert snake_to_camel('python_language')==('PythonLanguage')\nassert snake_to_camel('programming_language')==('ProgrammingLanguage')\n",
395
+ entryPoint: "snake_to_camel",
396
+ id: "Mbpp/102",
397
+ prompt: "\"\"\"\nWrite a function to convert a snake case string to camel case string.\nassert snake_to_camel('python_program')=='PythonProgram'\n\"\"\"\n",
398
+ solution: "\ndef snake_to_camel(word):\n return ''.join(x.capitalize() or '_' for x in word.split('_'))\n"
399
+ },
400
+ {
401
+ assertions: "\nassert eulerian_num(3, 1) == 4\nassert eulerian_num(4, 1) == 11\nassert eulerian_num(5, 3) == 26\n",
402
+ entryPoint: "eulerian_num",
403
+ id: "Mbpp/103",
404
+ prompt: "\"\"\"\nWrite a function to find the Eulerian number a(n, m).\nassert eulerian_num(3, 1) == 4\n\"\"\"\n",
405
+ solution: "\ndef eulerian_num(n, m): \n\tif (m >= n or n == 0): \n\t\treturn 0 \n\tif (m == 0): \n\t\treturn 1 \n\treturn (n - m) * eulerian_num(n - 1, m - 1) + (m + 1) * eulerian_num(n - 1, m)\n"
406
+ },
407
+ {
408
+ assertions: "\nassert sort_sublists(([\"green\", \"orange\"], [\"black\", \"white\"], [\"white\", \"black\", \"orange\"]))==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]\nassert sort_sublists(([\" red \",\"green\" ],[\"blue \",\" black\"],[\" orange\",\"brown\"]))==[[' red ', 'green'], [' black', 'blue '], [' orange', 'brown']]\nassert sort_sublists(([\"zilver\",\"gold\"], [\"magnesium\",\"aluminium\"], [\"steel\", \"bronze\"]))==[['gold', 'zilver'],['aluminium', 'magnesium'], ['bronze', 'steel']]\n",
409
+ entryPoint: "sort_sublists",
410
+ id: "Mbpp/104",
411
+ prompt: "\"\"\"\nWrite a function to sort each sublist of strings in a given list of lists.\nassert sort_sublists(([\"green\", \"orange\"], [\"black\", \"white\"], [\"white\", \"black\", \"orange\"]))==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]\n\"\"\"\n",
412
+ solution: "\ndef sort_sublists(input_list):\n return [sorted(x) for x in input_list]\n"
413
+ },
414
+ {
415
+ assertions: "\nassert count([True,False,True]) == 2\nassert count([False,False]) == 0\nassert count([True,True,True]) == 3\n",
416
+ entryPoint: "count",
417
+ id: "Mbpp/105",
418
+ prompt: "\"\"\"\nWrite a python function to count true booleans in the given list.\nassert count([True,False,True]) == 2\n\"\"\"\n",
419
+ solution: "\ndef count(lst): \n return sum(lst) \n"
420
+ },
421
+ {
422
+ assertions: "\nassert add_lists([5, 6, 7], (9, 10)) == (9, 10, 5, 6, 7)\nassert add_lists([6, 7, 8], (10, 11)) == (10, 11, 6, 7, 8)\nassert add_lists([7, 8, 9], (11, 12)) == (11, 12, 7, 8, 9)\n",
423
+ entryPoint: "add_lists",
424
+ id: "Mbpp/106",
425
+ prompt: "\"\"\"\nWrite a function to append the given list to the given tuples.\nassert add_lists([5, 6, 7], (9, 10)) == (9, 10, 5, 6, 7)\n\"\"\"\n",
426
+ solution: "\ndef add_lists(test_list, test_tup):\n return test_tup + tuple(test_list)\n"
427
+ },
428
+ {
429
+ assertions: "\nassert merge_sorted_list([25, 24, 15, 4, 5, 29, 110],[19, 20, 11, 56, 25, 233, 154],[24, 26, 54, 48])==[4, 5, 11, 15, 19, 20, 24, 24, 25, 25, 26, 29, 48, 54, 56, 110, 154, 233]\nassert merge_sorted_list([1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12])==[1, 1, 2, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 11, 12]\nassert merge_sorted_list([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1],[25, 35, 22, 85, 14, 65, 75, 25, 58],[12, 74, 9, 50, 61, 41])==[1, 2, 3, 4, 7, 8, 9, 9, 9, 10, 12, 14, 14, 18, 22, 25, 25, 35, 41, 50, 58, 61, 65, 74, 75, 85]\n",
430
+ entryPoint: "merge_sorted_list",
431
+ id: "Mbpp/108",
432
+ prompt: "\"\"\"\nWrite a function to merge three lists into a single sorted list.\nassert merge_sorted_list([25, 24, 15, 4, 5, 29, 110],[19, 20, 11, 56, 25, 233, 154],[24, 26, 54, 48])==[4, 5, 11, 15, 19, 20, 24, 24, 25, 25, 26, 29, 48, 54, 56, 110, 154, 233]\n\"\"\"\n",
433
+ solution: "\nimport heapq\ndef merge_sorted_list(num1,num2,num3):\n return sorted(num1 + num2 + num3)\n"
434
+ },
435
+ {
436
+ assertions: "\nassert odd_Equivalent(\"011001\",6) == 3\nassert odd_Equivalent(\"11011\",5) == 4\nassert odd_Equivalent(\"1010\",4) == 2\n",
437
+ entryPoint: "odd_Equivalent",
438
+ id: "Mbpp/109",
439
+ prompt: "\"\"\"\nWrite a python function to find the number of numbers with an odd value when rotating a binary string the given number of times.\nassert odd_Equivalent(\"011001\",6) == 3\n\"\"\"\n",
440
+ solution: "\ndef odd_Equivalent(s,n): \n count=0\n for i in range(0,n): \n if (s[i] == '1'): \n count = count + 1\n return count \n"
441
+ },
442
+ {
443
+ assertions: "\nassert set(common_in_nested_lists([[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]]))==set([18, 12])\nassert set(common_in_nested_lists([[12, 5, 23, 25, 45], [7, 11, 5, 23, 28], [1, 5, 8, 18, 23, 16]]))==set([5,23])\nassert set(common_in_nested_lists([[2, 3,4, 1], [4, 5], [6,4, 8],[4, 5], [6, 8,4]]))==set([4])\n",
444
+ entryPoint: "common_in_nested_lists",
445
+ id: "Mbpp/111",
446
+ prompt: "\"\"\"\nWrite a function to find the common elements in given nested lists.\nassert set(common_in_nested_lists([[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]]))==set([18, 12])\n\"\"\"\n",
447
+ solution: "\ndef common_in_nested_lists(nestedlist):\n return list(set.intersection(*map(set, nestedlist)))\n"
448
+ },
449
+ {
450
+ assertions: "\nassert check_integer(\"python\")==False\nassert check_integer(\"1\")==True\nassert check_integer(\"12345\")==True\n",
451
+ entryPoint: "check_integer",
452
+ id: "Mbpp/113",
453
+ prompt: "\"\"\"\nWrite a function to check if a string represents an integer or not.\nassert check_integer(\"python\")==False\n\"\"\"\n",
454
+ solution: "\ndef check_integer(text):\n text = text.strip()\n if len(text) < 1:\n return None\n else:\n if text[0] in '+-':\n text = text[1:]\n return text.isdigit()\n"
455
+ },
456
+ {
457
+ assertions: "\nassert tuple_to_int((1,2,3))==123\nassert tuple_to_int((4,5,6))==456\nassert tuple_to_int((5,6,7))==567\n",
458
+ entryPoint: "tuple_to_int",
459
+ id: "Mbpp/116",
460
+ prompt: "\"\"\"\nWrite a function to convert a given tuple of positive integers into a single integer.\nassert tuple_to_int((1,2,3))==123\n\"\"\"\n",
461
+ solution: "\ndef tuple_to_int(nums):\n return int(''.join(map(str,nums)))\n"
462
+ },
463
+ {
464
+ assertions: "\nassert string_to_list(\"python programming\")==['python','programming']\nassert string_to_list(\"lists tuples strings\")==['lists','tuples','strings']\nassert string_to_list(\"write a program\")==['write','a','program']\n",
465
+ entryPoint: "string_to_list",
466
+ id: "Mbpp/118",
467
+ prompt: "\"\"\"\nWrite a function to convert a string to a list of strings split on the space character.\nassert string_to_list(\"python programming\")==['python','programming']\n\"\"\"\n",
468
+ solution: "\ndef string_to_list(string): \n return string.split(\" \")\n"
469
+ },
470
+ {
471
+ assertions: "\nassert search([1,1,2,2,3]) == 3\nassert search([1,1,3,3,4,4,5,5,7,7,8]) == 8\nassert search([1,2,2,3,3,4,4]) == 1\n",
472
+ entryPoint: "search",
473
+ id: "Mbpp/119",
474
+ prompt: "\"\"\"\nWrite a python function to find the element that appears only once in a sorted array.\nassert search([1,1,2,2,3]) == 3\n\"\"\"\n",
475
+ solution: "\ndef search(arr):\n n = len(arr)\n XOR = 0\n for i in range(n) :\n XOR = XOR ^ arr[i]\n return (XOR)\n"
476
+ },
477
+ {
478
+ assertions: "\nassert math.isclose(max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)]), 36, rel_tol=0.001)\nassert math.isclose(max_product_tuple([(10,20), (15,2), (5,10)] ), 200, rel_tol=0.001)\nassert math.isclose(max_product_tuple([(11,44), (10,15), (20,5), (12, 9)] ), 484, rel_tol=0.001)\n",
479
+ entryPoint: "max_product_tuple",
480
+ id: "Mbpp/120",
481
+ prompt: "\"\"\"\nWrite a function to find the maximum absolute product between numbers in pairs of tuples within a given list.\nassert max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==36\n\"\"\"\n",
482
+ solution: "\ndef max_product_tuple(list1):\n return max(abs(x * y) for x, y in list1)\n"
483
+ },
484
+ {
485
+ assertions: "\nassert amicable_numbers_sum(999)==504\nassert amicable_numbers_sum(9999)==31626\nassert amicable_numbers_sum(99)==0\n",
486
+ entryPoint: "amicable_numbers_sum",
487
+ id: "Mbpp/123",
488
+ prompt: "\"\"\"\nWrite a function to sum all amicable numbers from 1 to a specified number.\nassert amicable_numbers_sum(999)==504\n\"\"\"\n",
489
+ solution: "\ndef div_sum(num):\n res = 1\n i = 2\n while i * i <= num:\n if num % i == 0:\n res += i\n if i * i != num:\n res += num / i\n i += 1\n return res\ndef amicable_numbers_sum(limit):\n amicables = set()\n for num in range(2, limit + 1):\n if num in amicables:\n continue\n sum_fact = div_sum(num)\n sum_fact2 = div_sum(sum_fact)\n if num == sum_fact2 and num != sum_fact:\n amicables.add(num)\n amicables.add(sum_fact2)\n return sum(amicables)\n"
490
+ },
491
+ {
492
+ assertions: "import math\n\nassert math.isclose(angle_complex(0,1j), 1.5707963267948966, rel_tol=0.001)\nassert math.isclose(angle_complex(2,1j), 0.4636476090008061, rel_tol=0.001)\nassert math.isclose(angle_complex(0,2j), 1.5707963267948966, rel_tol=0.001)\n",
493
+ entryPoint: "angle_complex",
494
+ id: "Mbpp/124",
495
+ prompt: "\"\"\"\nWrite a function to get the angle of a complex number.\nassert math.isclose(angle_complex(0,1j), 1.5707963267948966, rel_tol=0.001)\n\"\"\"\n",
496
+ solution: "\nimport cmath\ndef angle_complex(a,b):\n angle=cmath.phase(a+b)\n return angle\n"
497
+ },
498
+ {
499
+ assertions: "\nassert find_length(\"11000010001\") == 6\nassert find_length(\"10111\") == 1\nassert find_length(\"11011101100101\") == 2\n",
500
+ entryPoint: "find_length",
501
+ id: "Mbpp/125",
502
+ prompt: "\"\"\"\nWrite 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.\nassert find_length(\"11000010001\") == 6\n\"\"\"\n",
503
+ solution: "\ndef find_length(string): \n\tcurrent_sum = 0\n\tmax_sum = 0\n\tfor c in string: \n\t\tcurrent_sum += 1 if c == '0' else -1\n\t\tif current_sum < 0: \n\t\t\tcurrent_sum = 0\n\t\tmax_sum = max(current_sum, max_sum) \n\treturn max_sum\n"
504
+ },
505
+ {
506
+ assertions: "\nassert sum(10,15) == 6\nassert sum(100,150) == 93\nassert sum(4,6) == 3\n",
507
+ entryPoint: "sum",
508
+ id: "Mbpp/126",
509
+ prompt: "\"\"\"\nWrite a python function to find the sum of common divisors of two given numbers.\nassert sum(10,15) == 6\n\"\"\"\n",
510
+ solution: "\nimport math\ndef sum(a,b): \n sum = 0\n n = math.gcd(a, b)\n N = int(math.sqrt(n)) + 1\n for i in range (1, N): \n if (n % i == 0): \n sum += i\n if (n / i != i): \n sum += (n / i)\n return sum\n"
511
+ },
512
+ {
513
+ assertions: "\nassert multiply_int(10,20)==200\nassert multiply_int(5,10)==50\nassert multiply_int(4,8)==32\n",
514
+ entryPoint: "multiply_int",
515
+ id: "Mbpp/127",
516
+ prompt: "\"\"\"\nWrite a function to multiply two integers.\nassert multiply_int(10,20)==200\n\"\"\"\n",
517
+ solution: "\ndef multiply_int(x, y):\n return x * y\n"
518
+ },
519
+ {
520
+ assertions: "\nassert long_words(3,\"python is a programming language\")==['python','programming','language']\nassert long_words(2,\"writing a program\")==['writing','program']\nassert long_words(5,\"sorting list\")==['sorting']\n",
521
+ entryPoint: "long_words",
522
+ id: "Mbpp/128",
523
+ prompt: "\"\"\"\nWrite a function to find words that are longer than n characters from a given list of words.\nassert long_words(3,\"python is a programming language\")==['python','programming','language']\n\"\"\"\n",
524
+ solution: "\ndef long_words(n, s):\n return list(filter(lambda x: len(x) > n, s.split(' ')))\n"
525
+ },
526
+ {
527
+ assertions: "\nassert magic_square_test([[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]])==True\nassert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 8]])==True\nassert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 7]])==False\n",
528
+ entryPoint: "magic_square_test",
529
+ id: "Mbpp/129",
530
+ prompt: "\"\"\"\nWrite a function to calculate whether the matrix is a magic square.\nassert magic_square_test([[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]])==True\n\"\"\"\n",
531
+ solution: "\ndef magic_square_test(my_matrix):\n s = sum(my_matrix[0])\n # row\n if any(sum(row) != s for row in my_matrix):\n return False\n # column\n if any(sum(row[i] for row in my_matrix) != s for i in range(len(my_matrix[0]))):\n return False\n # diagonal\n if sum(my_matrix[i][i] for i in range(len(my_matrix))) != s:\n return False\n # anti-diagonal\n if sum(my_matrix[i][len(my_matrix) - i - 1] for i in range(len(my_matrix))) != s:\n return False\n return True\n"
532
+ },
533
+ {
534
+ assertions: "\nassert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2])==2\nassert max_occurrences([2,3,8,4,7,9,8,7,9,15,14,10,12,13,16,18])==8\nassert max_occurrences([10,20,20,30,40,90,80,50,30,20,50,10])==20\n",
535
+ entryPoint: "max_occurrences",
536
+ id: "Mbpp/130",
537
+ prompt: "\"\"\"\nWrite a function to find the item with maximum frequency in a given list.\nassert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2])==2\n\"\"\"\n",
538
+ solution: "\nfrom collections import defaultdict\ndef max_occurrences(nums):\n d = defaultdict(int)\n for n in nums:\n d[n] += 1\n return max(d, key=d.get)\n"
539
+ },
540
+ {
541
+ assertions: "\nassert reverse_vowels(\"Python\") == \"Python\"\nassert reverse_vowels(\"USA\") == \"ASU\"\nassert reverse_vowels(\"ab\") == \"ab\"\n",
542
+ entryPoint: "reverse_vowels",
543
+ id: "Mbpp/131",
544
+ prompt: "\"\"\"\nWrite a python function to reverse only the vowels of a given string (where y is not a vowel).\nassert reverse_vowels(\"Python\") == \"Python\"\n\"\"\"\n",
545
+ solution: "\ndef reverse_vowels(str1):\n\tis_vowel = lambda x: x in 'aeiouAEIOU'\n\tpos = [i for i, c in enumerate(str1) if is_vowel(c)]\n\treturn ''.join(c if not is_vowel(c) else str1[pos.pop()] for c in str1)\n\t\t\n"
546
+ },
547
+ {
548
+ assertions: "\nassert tup_string(('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's'))==(\"exercises\")\nassert tup_string(('p','y','t','h','o','n'))==(\"python\")\nassert tup_string(('p','r','o','g','r','a','m'))==(\"program\")\n",
549
+ entryPoint: "tup_string",
550
+ id: "Mbpp/132",
551
+ prompt: "\"\"\"\nWrite a function to convert a tuple to a string.\nassert tup_string(('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's'))==(\"exercises\")\n\"\"\"\n",
552
+ solution: "\ndef tup_string(tup1):\n return ''.join(tup1)\n"
553
+ },
554
+ {
555
+ assertions: "\nassert sum_negativenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==-32\nassert sum_negativenum([10,15,-14,13,-18,12,-20])==-52\nassert sum_negativenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==-894\n",
556
+ entryPoint: "sum_negativenum",
557
+ id: "Mbpp/133",
558
+ prompt: "\"\"\"\nWrite a function to calculate the sum of the negative numbers of a given list of numbers.\nassert sum_negativenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==-32\n\"\"\"\n",
559
+ solution: "\ndef sum_negativenum(nums):\n return sum(x for x in nums if x < 0)\n"
560
+ },
561
+ {
562
+ assertions: "\nassert hexagonal_num(10) == 190\nassert hexagonal_num(5) == 45\nassert hexagonal_num(7) == 91\n",
563
+ entryPoint: "hexagonal_num",
564
+ id: "Mbpp/135",
565
+ prompt: "\"\"\"\nWrite a function to find the nth hexagonal number.\nassert hexagonal_num(10) == 190\n\"\"\"\n",
566
+ solution: "\ndef hexagonal_num(n): \n\treturn n * (2 * n - 1) \n"
567
+ },
568
+ {
569
+ assertions: "import math\n\nassert math.isclose(zero_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8]), 0.181818, rel_tol=0.001)\nassert math.isclose(zero_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8]), 0.00, rel_tol=0.001)\nassert math.isclose(zero_count([2, 4, -6, -9, 11, -12, 14, -5, 17]), 0.00, rel_tol=0.001)\n",
570
+ entryPoint: "zero_count",
571
+ id: "Mbpp/137",
572
+ prompt: "\"\"\"\nWrite a function to find the ratio of zeroes to non-zeroes in an array of integers.\nassert math.isclose(zero_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8]), 0.181818, rel_tol=0.001)\n\"\"\"\n",
573
+ solution: "\ndef zero_count(nums):\n if all(x == 0 for x in nums):\n return float('inf')\n return sum(x == 0 for x in nums) / sum(x != 0 for x in nums)\n"
574
+ },
575
+ {
576
+ assertions: "\nassert is_Sum_Of_Powers_Of_Two(10) == True\nassert is_Sum_Of_Powers_Of_Two(7) == False\nassert is_Sum_Of_Powers_Of_Two(14) == True\n",
577
+ entryPoint: "is_Sum_Of_Powers_Of_Two",
578
+ id: "Mbpp/138",
579
+ prompt: "\"\"\"\nWrite a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.\nassert is_Sum_Of_Powers_Of_Two(10) == True\n\"\"\"\n",
580
+ solution: "\ndef is_Sum_Of_Powers_Of_Two(n): \n return n > 0 and n % 2 == 0\n"
581
+ },
582
+ {
583
+ assertions: "import math\n\nassert math.isclose(circle_circumference(10), 62.830000000000005, rel_tol=0.001)\nassert math.isclose(circle_circumference(5), 31.415000000000003, rel_tol=0.001)\nassert math.isclose(circle_circumference(4), 25.132, rel_tol=0.001)\n",
584
+ entryPoint: "circle_circumference",
585
+ id: "Mbpp/139",
586
+ prompt: "\"\"\"\nWrite a function to find the circumference of a circle.\nassert math.isclose(circle_circumference(10), 62.830000000000005, rel_tol=0.001)\n\"\"\"\n",
587
+ solution: "\nimport math\ndef circle_circumference(r):\n return 2 * math.pi * r\n"
588
+ },
589
+ {
590
+ assertions: "\nassert extract_singly([(3, 4, 5), (4, 5, 7), (1, 4)]) == set([3, 4, 5, 7, 1])\nassert extract_singly([(1, 2, 3), (4, 2, 3), (7, 8)]) == set([1, 2, 3, 4, 7, 8])\nassert extract_singly([(7, 8, 9), (10, 11, 12), (10, 11)]) == set([7, 8, 9, 10, 11, 12])\n",
591
+ entryPoint: "extract_singly",
592
+ id: "Mbpp/140",
593
+ prompt: "\"\"\"\nWrite a function to flatten the list of lists into a single set of numbers.\nassert set(extract_singly([(3, 4, 5), (4, 5, 7), (1, 4)])) == set([3, 4, 5, 7, 1])\n\"\"\"\n",
594
+ solution: "\ndef extract_singly(test_list):\n return set([item for sublist in test_list for item in sublist])\n"
595
+ },
596
+ {
597
+ assertions: "\nassert pancake_sort([15, 79, 25, 38, 69]) == [15, 25, 38, 69, 79]\nassert pancake_sort([98, 12, 54, 36, 85]) == [12, 36, 54, 85, 98]\nassert pancake_sort([41, 42, 32, 12, 23]) == [12, 23, 32, 41, 42]\n",
598
+ entryPoint: "pancake_sort",
599
+ id: "Mbpp/141",
600
+ prompt: "\"\"\"\nWrite a function to sort a list of elements.\nassert pancake_sort([15, 79, 25, 38, 69]) == [15, 25, 38, 69, 79]\n\"\"\"\n",
601
+ solution: "\ndef pancake_sort(nums):\n arr_len = len(nums)\n while arr_len > 1:\n mi = nums.index(max(nums[0:arr_len]))\n nums = nums[mi::-1] + nums[mi+1:len(nums)]\n nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)]\n arr_len -= 1\n return nums\n"
602
+ },
603
+ {
604
+ assertions: "\nassert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,9],[2,1,3,1,2,6,7,9])==3\nassert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==4\nassert count_samepair([1,2,3,4,2,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==5\n",
605
+ entryPoint: "count_samepair",
606
+ id: "Mbpp/142",
607
+ prompt: "\"\"\"\nWrite a function to count number items that are identical in the same position of three given lists.\nassert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,9],[2,1,3,1,2,6,7,9])==3\n\"\"\"\n",
608
+ solution: "\ndef count_samepair(list1,list2,list3):\n return sum(m == n == o for m, n, o in zip(list1,list2,list3))\n"
609
+ },
610
+ {
611
+ assertions: "\nassert max_Abs_Diff((2,1,5,3)) == 4\nassert max_Abs_Diff((9,3,2,5,1)) == 8\nassert max_Abs_Diff((3,2,1)) == 2\n",
612
+ entryPoint: "max_Abs_Diff",
613
+ id: "Mbpp/145",
614
+ prompt: "\"\"\"\nWrite a python function to find the maximum difference between any two elements in a given array.\nassert max_Abs_Diff((2,1,5,3)) == 4\n\"\"\"\n",
615
+ solution: "\ndef max_Abs_Diff(arr): \n return max(arr) - min(arr)\n"
616
+ },
617
+ {
618
+ assertions: "\nassert find_solution(2, 3, 7) == (2, 1)\nassert find_solution(4, 2, 7) == None\nassert find_solution(1, 13, 17) == (4, 1)\n",
619
+ entryPoint: "find_solution",
620
+ id: "Mbpp/160",
621
+ prompt: "\"\"\"\nWrite a function that returns integers x and y that satisfy ax + by = n as a tuple, or return None if no solution exists.\nassert find_solution(2, 3, 7) == (2, 1)\n\"\"\"\n",
622
+ solution: "\ndef find_solution(a, b, n):\n\ti = 0\n\twhile i * a <= n:\n\t\tif (n - (i * a)) % b == 0: \n\t\t\treturn (i, (n - (i * a)) // b)\n\t\ti = i + 1\n\treturn None\n"
623
+ },
624
+ {
625
+ assertions: "\nassert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 4, 6, 8]) == [1, 3, 5, 7, 9, 10]\nassert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 3, 5, 7]) == [2, 4, 6, 8, 9, 10]\nassert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [5, 7]) == [1, 2, 3, 4, 6, 8, 9, 10]\n",
626
+ entryPoint: "remove_elements",
627
+ id: "Mbpp/161",
628
+ prompt: "\"\"\"\nWrite a function to remove all elements from a given list present in another list.\nassert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 4, 6, 8]) == [1, 3, 5, 7, 9, 10]\n\"\"\"\n",
629
+ solution: "\ndef remove_elements(list1, list2):\n return [x for x in list1 if x not in list2]\n"
630
+ },
631
+ {
632
+ assertions: "\nassert sum_series(0) == 0\nassert sum_series(6) == 12\nassert sum_series(10) == 30\nassert sum_series(9) == 25\n",
633
+ entryPoint: "sum_series",
634
+ id: "Mbpp/162",
635
+ prompt: "\"\"\"\nWrite 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).\nassert sum_series(6) == 12\n\"\"\"\n",
636
+ solution: "\ndef sum_series(n):\n if n <= 0:\n return 0\n return sum(n - 2 * i for i in range(n // 2 + 1))\n"
637
+ },
638
+ {
639
+ assertions: "\nassert count_char_position(\"xbcefg\") == 2\nassert count_char_position(\"ABcED\") == 3\nassert count_char_position(\"AbgdeF\") == 5\n",
640
+ entryPoint: "count_char_position",
641
+ id: "Mbpp/165",
642
+ prompt: "\"\"\"\nWrite 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).\nassert count_char_position(\"xbcefg\") == 2\n\"\"\"\n",
643
+ solution: "\ndef count_char_position(str1): \n return sum(ord(ch.lower()) - ord('a') == i for i, ch in enumerate(str1))\n"
644
+ },
645
+ {
646
+ assertions: "\nassert find_even_pair([5, 4, 7, 2, 1]) == 4\nassert find_even_pair([7, 2, 8, 1, 0, 5, 11]) == 9\nassert find_even_pair([1, 2, 3]) == 1\n",
647
+ entryPoint: "find_even_pair",
648
+ id: "Mbpp/166",
649
+ prompt: "\"\"\"\nWrite a function that counts the number of pairs of integers in a list that xor to an even number.\nassert find_even_pair([5, 4, 7, 2, 1]) == 4\n\"\"\"\n",
650
+ solution: "\ndef find_even_pair(A): \n if len(A) < 2: \n return 0\n return sum((a ^ b) % 2 == 0 for i, a in enumerate(A) for b in A[i + 1:])\n"
651
+ },
652
+ {
653
+ assertions: "\nassert next_power_of_2(0) == 1\nassert next_power_of_2(5) == 8\nassert next_power_of_2(17) == 32\n",
654
+ entryPoint: "next_power_of_2",
655
+ id: "Mbpp/167",
656
+ prompt: "\"\"\"\nWrite a python function to find the smallest power of 2 greater than or equal to n.\nassert next_power_of_2(0) == 1\n\"\"\"\n",
657
+ solution: "\ndef next_power_of_2(n): \n if n and not n & (n - 1):\n return n\n res = 1\n while n != 0: \n n >>= 1\n res <<= 1\n return res; \n"
658
+ },
659
+ {
660
+ assertions: "\nassert frequency([1,2,3], 4) == 0\nassert frequency([1,2,2,3,3,3,4], 3) == 3\nassert frequency([0,1,2,3,1,2], 1) == 2\n",
661
+ entryPoint: "frequency",
662
+ id: "Mbpp/168",
663
+ prompt: "\"\"\"\nWrite a function to count the number of occurrences of a number in a given list.\nassert frequency([1,2,3], 4) == 0\n\"\"\"\n",
664
+ solution: "\ndef frequency(a,x): \n return a.count(x)\n"
665
+ },
666
+ {
667
+ assertions: "\nassert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 8, 10) == 29\nassert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 5, 7) == 16\nassert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 7, 10) == 38\n",
668
+ entryPoint: "sum_range_list",
669
+ id: "Mbpp/170",
670
+ prompt: "\"\"\"\nWrite a function to find the sum of numbers in a list within a range specified by two indices.\nassert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 8, 10) == 29\n\"\"\"\n",
671
+ solution: "\ndef sum_range_list(list1, m, n): \n return sum(list1[m : n + 1])\n"
672
+ },
673
+ {
674
+ assertions: "\nassert perimeter_pentagon(5) == 25\nassert perimeter_pentagon(10) == 50\nassert perimeter_pentagon(15) == 75\n",
675
+ entryPoint: "perimeter_pentagon",
676
+ id: "Mbpp/171",
677
+ prompt: "\"\"\"\nWrite a function to find the perimeter of a regular pentagon from the length of its sides.\nassert perimeter_pentagon(5) == 25\n\"\"\"\n",
678
+ solution: "\ndef perimeter_pentagon(a):\n return 5 * a\n"
679
+ },
680
+ {
681
+ assertions: "\nassert count_occurance(\"letstdlenstdporstd\") == 3\nassert count_occurance(\"truststdsolensporsd\") == 1\nassert count_occurance(\"makestdsostdworthit\") == 2\nassert count_occurance(\"stds\") == 1\nassert count_occurance(\"\") == 0\n",
682
+ entryPoint: "count_occurance",
683
+ id: "Mbpp/172",
684
+ prompt: "\"\"\"\nWrite a function to count the number of occurence of the string 'std' in a given string.\nassert count_occurance(\"letstdlenstdporstd\") == 3\n\"\"\"\n",
685
+ solution: "\ndef count_occurance(s):\n return s.count('std')\n"
686
+ },
687
+ {
688
+ assertions: "\nassert check_type((5, 6, 7, 3, 5, 6) ) == True\nassert check_type((1, 2, \"4\") ) == False\nassert check_type((3, 2, 1, 4, 5) ) == True\n",
689
+ entryPoint: "check_type",
690
+ id: "Mbpp/222",
691
+ prompt: "\"\"\"\nWrite a function to check if all the elements in tuple have same data type or not.\nassert check_type((5, 6, 7, 3, 5, 6) ) == True\n\"\"\"\n",
692
+ solution: "\ndef check_type(test_tuple):\n return all(isinstance(item, type(test_tuple[0])) for item in test_tuple)\n"
693
+ },
694
+ {
695
+ assertions: "\nassert is_majority([1, 2, 3, 3, 3, 3, 10], 7, 3) == True\nassert is_majority([1, 1, 2, 4, 4, 4, 6, 6], 8, 4) == False\nassert is_majority([1, 1, 1, 2, 2], 5, 1) == True\n",
696
+ entryPoint: "is_majority",
697
+ id: "Mbpp/223",
698
+ prompt: "\"\"\"\nWrite 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.)\nassert is_majority([1, 2, 3, 3, 3, 3, 10], 7, 3) == True\n\"\"\"\n",
699
+ solution: "\nfrom bisect import bisect_left, bisect_right\ndef is_majority(arr, n, x):\n\tif x not in arr:\n\t\treturn False\n\tl = bisect_left(arr, x)\n\tr = bisect_right(arr, x)\n\treturn r - l > n / 2\n"
700
+ },
701
+ {
702
+ assertions: "\nassert count_Set_Bits(2) == 1\nassert count_Set_Bits(4) == 1\nassert count_Set_Bits(6) == 2\n",
703
+ entryPoint: "count_Set_Bits",
704
+ id: "Mbpp/224",
705
+ prompt: "\"\"\"\nWrite a python function to count the number of set bits (binary digits with value 1) in a given number.\nassert count_Set_Bits(2) == 1\n\"\"\"\n",
706
+ solution: "\ndef count_Set_Bits(n): \n return bin(n)[2:].count('1')\n"
707
+ },
708
+ {
709
+ assertions: "\nassert odd_values_string('abcdef') == 'ace'\nassert odd_values_string('python') == 'pto'\nassert odd_values_string('data') == 'dt'\nassert odd_values_string('lambs') == 'lms'\n",
710
+ entryPoint: "odd_values_string",
711
+ id: "Mbpp/226",
712
+ prompt: "\"\"\"\nWrite a python function to remove the characters which have odd index values of a given string.\nassert odd_values_string('abcdef') == 'ace'\n\"\"\"\n",
713
+ solution: "\ndef odd_values_string(str1):\n return ''.join(str1[i] for i in range(0, len(str1), 2))\n"
714
+ },
715
+ {
716
+ assertions: "\nassert min_of_three(10,20,0)==0\nassert min_of_three(19,15,18)==15\nassert min_of_three(-10,-20,-30)==-30\n",
717
+ entryPoint: "min_of_three",
718
+ id: "Mbpp/227",
719
+ prompt: "\"\"\"\nWrite a function to find minimum of three numbers.\nassert min_of_three(10,20,0)==0\n\"\"\"\n",
720
+ solution: "\ndef min_of_three(a,b,c): \n return min(a, b, c)\n"
721
+ },
722
+ {
723
+ assertions: "\nassert replace_blank(\"hello people\",'@')==(\"hello@people\")\nassert replace_blank(\"python program language\",'$')==(\"python$program$language\")\nassert replace_blank(\"blank space\",\"-\")==(\"blank-space\")\n",
724
+ entryPoint: "replace_blank",
725
+ id: "Mbpp/230",
726
+ prompt: "\"\"\"\nWrite a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string.\nassert replace_blank(\"hello people\",'@')==(\"hello@people\")\n\"\"\"\n",
727
+ solution: "\ndef replace_blank(str1, char):\n return str1.replace(' ', char)\n"
728
+ },
729
+ {
730
+ assertions: "\nassert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2))==set([100,90])\nassert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5))==set([100,90,80,70,60])\nassert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3))==set([100,90,80])\n",
731
+ entryPoint: "larg_nnum",
732
+ id: "Mbpp/232",
733
+ prompt: "\"\"\"\nWrite a function that takes in a list and an integer n and returns a list containing the n largest items from the list.\nassert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2))==set([100,90])\n\"\"\"\n",
734
+ solution: "\nimport heapq\ndef larg_nnum(list1, n):\n return heapq.nlargest(n,list1)\n"
735
+ },
736
+ {
737
+ assertions: "import math\n\nassert math.isclose(lateralsuface_cylinder(10,5), 314.15000000000003, rel_tol=0.001)\nassert math.isclose(lateralsuface_cylinder(4,5), 125.66000000000001, rel_tol=0.001)\nassert math.isclose(lateralsuface_cylinder(4,10), 251.32000000000002, rel_tol=0.001)\n",
738
+ entryPoint: "lateralsuface_cylinder",
739
+ id: "Mbpp/233",
740
+ prompt: "\"\"\"\nWrite a function to find the lateral surface area of a cylinder.\nassert math.isclose(lateralsuface_cylinder(10,5), 314.15000000000003, rel_tol=0.001)\n\"\"\"\n",
741
+ solution: "\nimport math\ndef lateralsuface_cylinder(r, h):\n return 2 * math.pi * r * h\n"
742
+ },
743
+ {
744
+ assertions: "\nassert volume_cube(3)==27\nassert volume_cube(2)==8\nassert volume_cube(5)==125\n",
745
+ entryPoint: "volume_cube",
746
+ id: "Mbpp/234",
747
+ prompt: "\"\"\"\nWrite a function to find the volume of a cube given its side length.\nassert volume_cube(3)==27\n\"\"\"\n",
748
+ solution: "\ndef volume_cube(l):\n return l ** 3\n"
749
+ },
750
+ {
751
+ assertions: "\nassert even_bit_set_number(10) == 10\nassert even_bit_set_number(20) == 30\nassert even_bit_set_number(30) == 30\n",
752
+ entryPoint: "even_bit_set_number",
753
+ id: "Mbpp/235",
754
+ prompt: "\"\"\"\nWrite a python function to set all even bits of a given number.\nassert even_bit_set_number(10) == 10\n\"\"\"\n",
755
+ solution: "\ndef even_bit_set_number(n): \n mask = 2\n while mask < n:\n n |= mask\n mask <<= 2\n return n\n"
756
+ },
757
+ {
758
+ assertions: "\nassert check_occurences([(3, 1), (1, 3), (2, 5), (5, 2), (6, 3)] ) == {(1, 3): 2, (2, 5): 2, (3, 6): 1}\nassert check_occurences([(4, 2), (2, 4), (3, 6), (6, 3), (7, 4)] ) == {(2, 4): 2, (3, 6): 2, (4, 7): 1}\nassert check_occurences([(13, 2), (11, 23), (12, 25), (25, 12), (16, 23)] ) == {(2, 13): 1, (11, 23): 1, (12, 25): 2, (16, 23): 1}\n",
759
+ entryPoint: "check_occurences",
760
+ id: "Mbpp/237",
761
+ prompt: "\"\"\"\nWrite 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.\nassert check_occurences([(3, 1), (1, 3), (2, 5), (5, 2), (6, 3)] ) == {(1, 3): 2, (2, 5): 2, (3, 6): 1}\n\"\"\"\n",
762
+ solution: "\nfrom collections import Counter \ndef check_occurences(test_list):\n return dict(Counter(tuple(sorted(t)) for t in test_list))\n"
763
+ },
764
+ {
765
+ assertions: "\nassert number_of_substrings(\"abc\") == 6\nassert number_of_substrings(\"abcd\") == 10\nassert number_of_substrings(\"abcde\") == 15\n",
766
+ entryPoint: "number_of_substrings",
767
+ id: "Mbpp/238",
768
+ prompt: "\"\"\"\nWrite a python function to count the number of non-empty substrings of a given string.\nassert number_of_substrings(\"abc\") == 6\n\"\"\"\n",
769
+ solution: "\ndef number_of_substrings(str1): \n\tstr_len = len(str1) \n\treturn str_len * (str_len + 1) // 2\n"
770
+ },
771
+ {
772
+ assertions: "\nassert get_total_number_of_sequences(10, 4) == 4\nassert get_total_number_of_sequences(5, 2) == 6\nassert get_total_number_of_sequences(16, 3) == 84\n",
773
+ entryPoint: "get_total_number_of_sequences",
774
+ id: "Mbpp/239",
775
+ prompt: "\"\"\"\nWrite 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.\nassert get_total_number_of_sequences(10, 4) == 4\n\"\"\"\n",
776
+ solution: "\ndef get_total_number_of_sequences(m, n):\n\tT=[[0 for _ in range(n + 1)] for _ in range(m + 1)] \n\tfor i in range(m + 1): \n\t\tfor j in range(n + 1): \n\t\t\tif i==0 or j==0: \n\t\t\t\tT[i][j] = 0\n\t\t\telif i<j: \n\t\t\t\tT[i][j] = 0\n\t\t\telif j==1: \n\t\t\t\tT[i][j] = i \n\t\t\telse: \n\t\t\t\tT[i][j] = T[i-1][j] + T[i//2][j-1] \n\treturn T[m][n]\n"
777
+ },
778
+ {
779
+ assertions: "\nassert replace_list([1, 3, 5, 7, 9, 10],[2, 4, 6, 8])==[1, 3, 5, 7, 9, 2, 4, 6, 8]\nassert replace_list([1,2,3,4,5],[5,6,7,8])==[1,2,3,4,5,6,7,8]\nassert replace_list([\"red\",\"blue\",\"green\"],[\"yellow\"])==[\"red\",\"blue\",\"yellow\"]\n",
780
+ entryPoint: "replace_list",
781
+ id: "Mbpp/240",
782
+ prompt: "\"\"\"\nWrite a function that takes in two lists and replaces the last element of the first list with the elements of the second list.\nassert replace_list([1, 3, 5, 7, 9, 10],[2, 4, 6, 8])==[1, 3, 5, 7, 9, 2, 4, 6, 8]\n\"\"\"\n",
783
+ solution: "\ndef replace_list(list1, list2):\n return list1[:-1] + list2\n"
784
+ },
785
+ {
786
+ assertions: "\nassert count_charac(\"python programming\")==18\nassert count_charac(\"language\")==8\nassert count_charac(\"words\")==5\n",
787
+ entryPoint: "count_charac",
788
+ id: "Mbpp/242",
789
+ prompt: "\"\"\"\nWrite a function to count the total number of characters in a string.\nassert count_charac(\"python programming\")==18\n\"\"\"\n",
790
+ solution: "\ndef count_charac(str1):\n return len(str1)\n"
791
+ },
792
+ {
793
+ assertions: "\nassert next_Perfect_Square(35) == 36\nassert next_Perfect_Square(6) == 9\nassert next_Perfect_Square(9) == 16\n",
794
+ entryPoint: "next_Perfect_Square",
795
+ id: "Mbpp/244",
796
+ prompt: "\"\"\"\nWrite a python function to find the next perfect square greater than a given number.\nassert next_Perfect_Square(35) == 36\n\"\"\"\n",
797
+ solution: "\nimport math \ndef next_Perfect_Square(N): \n if N < 0:\n return 0\n nextN = math.floor(math.sqrt(N)) + 1\n return nextN * nextN \n"
798
+ },
799
+ {
800
+ assertions: "\nassert max_sum([1, 15, 51, 45, 33, 100, 12, 18, 9]) == 194\nassert max_sum([80, 60, 30, 40, 20, 10]) == 210\nassert max_sum([2, 3 ,14, 16, 21, 23, 29, 30]) == 138\n",
801
+ entryPoint: "max_sum",
802
+ id: "Mbpp/245",
803
+ prompt: "\"\"\"\nWrite 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.\nassert max_sum([1, 15, 51, 45, 33, 100, 12, 18, 9]) == 194\n\"\"\"\n",
804
+ solution: "\ndef max_sum(arr): \n\tMSIBS = arr[:] \n\tfor i in range(len(arr)): \n\t\tfor j in range(0, i): \n\t\t\tif arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]: \n\t\t\t\tMSIBS[i] = MSIBS[j] + arr[i] \n\tMSDBS = arr[:] \n\tfor i in range(1, len(arr) + 1): \n\t\tfor j in range(1, i): \n\t\t\tif arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]: \n\t\t\t\tMSDBS[-i] = MSDBS[-j] + arr[-i] \n\tmax_sum = float(\"-Inf\") \n\tfor i, j, k in zip(MSIBS, MSDBS, arr): \n\t\tmax_sum = max(max_sum, i + j - k) \n\treturn max_sum\n"
805
+ },
806
+ {
807
+ assertions: "\nassert lps(\"TENS FOR TENS\") == 5\nassert lps(\"CARDIO FOR CARDS\") == 7\nassert lps(\"PART OF THE JOURNEY IS PART\") == 9\n",
808
+ entryPoint: "lps",
809
+ id: "Mbpp/247",
810
+ prompt: "\"\"\"\nWrite a function to find the length of the longest palindromic subsequence in the given string.\nassert lps(\"TENS FOR TENS\") == 5\n\"\"\"\n",
811
+ solution: "\ndef lps(str1): \n\tn = len(str1)\n\tdp = [[0] * n for _ in range(n)]\n\tfor i in range(n - 1, -1, -1):\n\t\tdp[i][i] = 1\n\t\tfor j in range(i + 1, n):\n\t\t\tif str1[i] == str1[j]:\n\t\t\t\tdp[i][j] = dp[i + 1][j - 1] + 2\n\t\t\telse:\n\t\t\t\tdp[i][j] = max(dp[i + 1][j], dp[i][j - 1])\n\treturn dp[0][n - 1]\n"
812
+ },
813
+ {
814
+ assertions: "\nassert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),4) == 0\nassert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),10) == 3\nassert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),8) == 4\n",
815
+ entryPoint: "count_X",
816
+ id: "Mbpp/250",
817
+ prompt: "\"\"\"\nWrite a python function that takes in a tuple and an element and counts the occcurences of the element in the tuple.\nassert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),4) == 0\n\"\"\"\n",
818
+ solution: "\ndef count_X(tup, x): \n return tup.count(x)\n"
819
+ },
820
+ {
821
+ assertions: "\nassert insert_element(['Red', 'Green', 'Black'] ,'c')==['c', 'Red', 'c', 'Green', 'c', 'Black']\nassert insert_element(['python', 'java'] ,'program')==['program', 'python', 'program', 'java']\nassert insert_element(['happy', 'sad'] ,'laugh')==['laugh', 'happy', 'laugh', 'sad']\n",
822
+ entryPoint: "insert_element",
823
+ id: "Mbpp/251",
824
+ prompt: "\"\"\"\nWrite 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.\nassert insert_element(['Red', 'Green', 'Black'] ,'c')==['c', 'Red', 'c', 'Green', 'c', 'Black']\n\"\"\"\n",
825
+ solution: "\ndef insert_element(list1, element):\n list1 = [v for elt in list1 for v in (element, elt)]\n return list1\n"
826
+ },
827
+ {
828
+ assertions: "\nassert convert(1) == (1.0, 0.0)\nassert convert(4) == (4.0,0.0)\nassert convert(5) == (5.0,0.0)\n",
829
+ entryPoint: "convert",
830
+ id: "Mbpp/252",
831
+ prompt: "\"\"\"\nWrite a python function to convert complex numbers to polar coordinates.\nassert convert(1) == (1.0, 0.0)\n\"\"\"\n",
832
+ solution: "\nimport cmath \ndef convert(numbers): \n return cmath.polar(numbers) \n"
833
+ },
834
+ {
835
+ assertions: "\nassert count_integer([1,2,'abc',1.2]) == 2\nassert count_integer([1,2,3]) == 3\nassert count_integer([1,1.2,4,5.1]) == 2\n",
836
+ entryPoint: "count_integer",
837
+ id: "Mbpp/253",
838
+ prompt: "\"\"\"\nWrite a python function that returns the number of integer elements in a given list.\nassert count_integer([1,2,'abc',1.2]) == 2\n\"\"\"\n",
839
+ solution: "\ndef count_integer(list1):\n return sum(isinstance(x, int) for x in list1)\n"
840
+ },
841
+ {
842
+ assertions: "\nassert combinations_colors( [\"Red\",\"Green\",\"Blue\"],1)==[('Red',), ('Green',), ('Blue',)]\nassert combinations_colors( [\"Red\",\"Green\",\"Blue\"],2)==[('Red', 'Red'), ('Red', 'Green'), ('Red', 'Blue'), ('Green', 'Green'), ('Green', 'Blue'), ('Blue', 'Blue')]\nassert combinations_colors( [\"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')]\n",
843
+ entryPoint: "combinations_colors",
844
+ id: "Mbpp/255",
845
+ prompt: "\"\"\"\nWrite 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.\nassert combinations_colors( [\"Red\",\"Green\",\"Blue\"],1)==[('Red',), ('Green',), ('Blue',)]\n\"\"\"\n",
846
+ solution: "\nfrom itertools import combinations_with_replacement \ndef combinations_colors(l, n):\n return list(combinations_with_replacement(l, n))\n"
847
+ },
848
+ {
849
+ assertions: "\nassert count_Primes_nums(5) == 2\nassert count_Primes_nums(10) == 4\nassert count_Primes_nums(100) == 25\n",
850
+ entryPoint: "count_Primes_nums",
851
+ id: "Mbpp/256",
852
+ prompt: "\"\"\"\nWrite a python function that takes in a non-negative number and returns the number of prime numbers less than the given non-negative number.\nassert count_Primes_nums(5) == 2\n\"\"\"\n",
853
+ solution: "\ndef count_Primes_nums(n):\n return sum(all(i % j != 0 for j in range(2, i)) for i in range(2, n))\n"
854
+ },
855
+ {
856
+ assertions: "\nassert swap_numbers(10,20)==(20,10)\nassert swap_numbers(15,17)==(17,15)\nassert swap_numbers(100,200)==(200,100)\n",
857
+ entryPoint: "swap_numbers",
858
+ id: "Mbpp/257",
859
+ prompt: "\"\"\"\nWrite a function that takes in two numbers and returns a tuple with the second number and then the first number.\nassert swap_numbers(10,20)==(20,10)\n\"\"\"\n",
860
+ solution: "\ndef swap_numbers(a,b):\n return (b, a)\n"
861
+ },
862
+ {
863
+ assertions: "\nassert maximize_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((6, 7), (4, 9), (2, 9), (7, 10))\nassert maximize_elements(((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))) == ((7, 8), (5, 10), (3, 10), (8, 11))\nassert maximize_elements(((3, 5), (6, 7), (4, 11), (3, 12)), ((8, 9), (5, 11), (3, 3), (9, 5))) == ((8, 9), (6, 11), (4, 11), (9, 12))\n",
864
+ entryPoint: "maximize_elements",
865
+ id: "Mbpp/259",
866
+ prompt: "\"\"\"\nWrite a function to maximize the given two tuples.\nassert maximize_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((6, 7), (4, 9), (2, 9), (7, 10))\n\"\"\"\n",
867
+ solution: "\ndef maximize_elements(test_tup1, test_tup2):\n return tuple((max(a, c), max(b, d)) for (a, b), (c, d) in zip(test_tup1, test_tup2))\n"
868
+ },
869
+ {
870
+ assertions: "\nassert newman_prime(3) == 7\nassert newman_prime(4) == 17\nassert newman_prime(5) == 41\n",
871
+ entryPoint: "newman_prime",
872
+ id: "Mbpp/260",
873
+ prompt: "\"\"\"\nWrite a function to find the nth newman–shanks–williams prime number.\nassert newman_prime(3) == 7\n\"\"\"\n",
874
+ solution: "\ndef newman_prime(n): \n\tif n == 0 or n == 1: \n\t\treturn 1\n\ta = 1\n\tb = 1\n\tc = 1\n\tfor _ in range(2, n + 1):\n\t\tc = 2 * b + a\n\t\ta = b\n\t\tb = c\n\treturn c\n"
875
+ },
876
+ {
877
+ assertions: "\nassert division_elements((10, 4, 6, 9),(5, 2, 3, 3)) == (2, 2, 2, 3)\nassert division_elements((12, 6, 8, 16),(6, 3, 4, 4)) == (2, 2, 2, 4)\nassert division_elements((20, 14, 36, 18),(5, 7, 6, 9)) == (4, 2, 6, 2)\n",
878
+ entryPoint: "division_elements",
879
+ id: "Mbpp/261",
880
+ prompt: "\"\"\"\nWrite a function that takes in two tuples and performs mathematical division operation element-wise across the given tuples.\nassert division_elements((10, 4, 6, 9),(5, 2, 3, 3)) == (2, 2, 2, 3)\n\"\"\"\n",
881
+ solution: "\ndef division_elements(test_tup1, test_tup2):\n return tuple(ele1 / ele2 for ele1, ele2 in zip(test_tup1, test_tup2))\n"
882
+ },
883
+ {
884
+ assertions: "\nassert split_two_parts([1,1,2,3,4,4,5,1],3)==([1, 1, 2], [3, 4, 4, 5, 1])\nassert split_two_parts(['a', 'b', 'c', 'd'],2)==(['a', 'b'], ['c', 'd'])\nassert split_two_parts(['p', 'y', 't', 'h', 'o', 'n'],4)==(['p', 'y', 't', 'h'], ['o', 'n'])\n",
885
+ entryPoint: "split_two_parts",
886
+ id: "Mbpp/262",
887
+ prompt: "\"\"\"\nWrite 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.\nassert split_two_parts([1,1,2,3,4,4,5,1],3)==([1, 1, 2], [3, 4, 4, 5, 1])\n\"\"\"\n",
888
+ solution: "\ndef split_two_parts(list1, L):\n return list1[:L], list1[L:]\n"
889
+ },
890
+ {
891
+ assertions: "\nassert dog_age(12)==61\nassert dog_age(15)==73\nassert dog_age(24)==109\n",
892
+ entryPoint: "dog_age",
893
+ id: "Mbpp/264",
894
+ prompt: "\"\"\"\nWrite a function to calculate a dog's age in dog's years.\nassert dog_age(12)==61\n\"\"\"\n",
895
+ solution: "\ndef dog_age(h_age):\n\tif h_age <= 2:\n\t\td_age = h_age * 10.5\n\telse:\n\t\td_age = 21 + (h_age - 2) * 4\n\treturn d_age\n"
896
+ },
897
+ {
898
+ assertions: "\nassert list_split(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'],3)==[['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']]\nassert list_split([1,2,3,4,5,6,7,8,9,10,11,12,13,14],3)==[[1,4,7,10,13], [2,5,8,11,14], [3,6,9,12]]\nassert list_split(['python','java','C','C++','DBMS','SQL'],2)==[['python', 'C', 'DBMS'], ['java', 'C++', 'SQL']]\n",
899
+ entryPoint: "list_split",
900
+ id: "Mbpp/265",
901
+ prompt: "\"\"\"\nWrite 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.\nassert list_split(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'],3)==[['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']]\n\"\"\"\n",
902
+ solution: "\ndef list_split(S, step):\n return [S[i::step] for i in range(step)]\n"
903
+ },
904
+ {
905
+ assertions: "\nassert lateralsurface_cube(5)==100\nassert lateralsurface_cube(9)==324\nassert lateralsurface_cube(10)==400\n",
906
+ entryPoint: "lateralsurface_cube",
907
+ id: "Mbpp/266",
908
+ prompt: "\"\"\"\nWrite a function to find the lateral surface area of a cube given its side length.\nassert lateralsurface_cube(5)==100\n\"\"\"\n",
909
+ solution: "\ndef lateralsurface_cube(l):\n return 4 * l * l\n"
910
+ },
911
+ {
912
+ assertions: "\nassert square_Sum(2) == 10\nassert square_Sum(3) == 35\nassert square_Sum(4) == 84\n",
913
+ entryPoint: "square_Sum",
914
+ id: "Mbpp/267",
915
+ prompt: "\"\"\"\nWrite a python function that takes in an integer n and returns the sum of the squares of the first n odd natural numbers.\nassert square_Sum(2) == 10\n\"\"\"\n",
916
+ solution: "\ndef square_Sum(n): \n return n * (4 * n * n - 1) / 3\n"
917
+ },
918
+ {
919
+ assertions: "\nassert find_star_num(3) == 37\nassert find_star_num(4) == 73\nassert find_star_num(5) == 121\n",
920
+ entryPoint: "find_star_num",
921
+ id: "Mbpp/268",
922
+ prompt: "\"\"\"\nWrite a function to find the n'th star number.\nassert find_star_num(3) == 37\n\"\"\"\n",
923
+ solution: "\ndef find_star_num(n): \n\treturn 6 * n * (n - 1) + 1 \n"
924
+ },
925
+ {
926
+ assertions: "\nassert ascii_value('A')==65\nassert ascii_value('R')==82\nassert ascii_value('S')==83\n",
927
+ entryPoint: "ascii_value",
928
+ id: "Mbpp/269",
929
+ prompt: "\"\"\"\nWrite a function to find the ascii value of a character.\nassert ascii_value('A')==65\n\"\"\"\n",
930
+ solution: "\ndef ascii_value(k):\n return ord(k)\n"
931
+ },
932
+ {
933
+ assertions: "\nassert sum_even_and_even_index([5, 6, 12, 1, 18, 8]) == 30\nassert sum_even_and_even_index([3, 20, 17, 9, 2, 10, 18, 13, 6, 18]) == 26\nassert sum_even_and_even_index([5, 6, 12, 1]) == 12\n",
934
+ entryPoint: "sum_even_and_even_index",
935
+ id: "Mbpp/270",
936
+ prompt: "\"\"\"\nWrite a python function to find the sum of even numbers at even positions of a list.\nassert sum_even_and_even_index([5, 6, 12, 1, 18, 8]) == 30\n\"\"\"\n",
937
+ solution: "\ndef sum_even_and_even_index(arr): \n return sum(x for x in arr[::2] if x % 2 == 0)\n"
938
+ },
939
+ {
940
+ assertions: "\nassert even_Power_Sum(2) == 1056\nassert even_Power_Sum(3) == 8832\nassert even_Power_Sum(1) == 32\n",
941
+ entryPoint: "even_Power_Sum",
942
+ id: "Mbpp/271",
943
+ prompt: "\"\"\"\nWrite 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.\nassert even_Power_Sum(2) == 1056\n\"\"\"\n",
944
+ solution: "\ndef even_Power_Sum(n): \n return sum(x ** 5 for x in range(2, 2 * n + 1, 2))\n"
945
+ },
946
+ {
947
+ assertions: "\nassert rear_extract([(1, 'Rash', 21), (2, 'Varsha', 20), (3, 'Kil', 19)]) == [21, 20, 19]\nassert rear_extract([(1, 'Sai', 36), (2, 'Ayesha', 25), (3, 'Salman', 45)]) == [36, 25, 45]\nassert rear_extract([(1, 'Sudeep', 14), (2, 'Vandana', 36), (3, 'Dawood', 56)]) == [14, 36, 56]\n",
948
+ entryPoint: "rear_extract",
949
+ id: "Mbpp/272",
950
+ prompt: "\"\"\"\nWrite a function that takes in a list of tuples and returns a list containing the rear element of each tuple.\nassert rear_extract([(1, 'Rash', 21), (2, 'Varsha', 20), (3, 'Kil', 19)]) == [21, 20, 19]\n\"\"\"\n",
951
+ solution: "\ndef rear_extract(test_list):\n return [x[-1] for x in test_list]\n"
952
+ },
953
+ {
954
+ assertions: "\nassert substract_elements((10, 4, 5), (2, 5, 18)) == (8, -1, -13)\nassert substract_elements((11, 2, 3), (24, 45 ,16)) == (-13, -43, -13)\nassert substract_elements((7, 18, 9), (10, 11, 12)) == (-3, 7, -3)\n",
955
+ entryPoint: "substract_elements",
956
+ id: "Mbpp/273",
957
+ prompt: "\"\"\"\nWrite 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.\nassert substract_elements((10, 4, 5), (2, 5, 18)) == (8, -1, -13)\n\"\"\"\n",
958
+ solution: "\ndef substract_elements(test_tup1, test_tup2):\n return tuple(x - y for x, y in zip(test_tup1, test_tup2))\n"
959
+ },
960
+ {
961
+ assertions: "\nassert even_binomial_Coeff_Sum(4) == 8\nassert even_binomial_Coeff_Sum(6) == 32\nassert even_binomial_Coeff_Sum(2) == 2\n",
962
+ entryPoint: "even_binomial_Coeff_Sum",
963
+ id: "Mbpp/274",
964
+ prompt: "\"\"\"\nWrite a python function that takes in a positive integer n and finds the sum of even index binomial coefficients.\nassert even_binomial_Coeff_Sum(4) == 8\n\"\"\"\n",
965
+ solution: "\nimport math \ndef even_binomial_Coeff_Sum( n): \n return 1 << (n - 1)\n"
966
+ },
967
+ {
968
+ assertions: "import math\n\nassert math.isclose(volume_cylinder(10,5), 1570.7500000000002, rel_tol=0.001)\nassert math.isclose(volume_cylinder(4,5), 251.32000000000002, rel_tol=0.001)\nassert math.isclose(volume_cylinder(4,10), 502.64000000000004, rel_tol=0.001)\n",
969
+ entryPoint: "volume_cylinder",
970
+ id: "Mbpp/276",
971
+ prompt: "\"\"\"\nWrite a function that takes in the radius and height of a cylinder and returns the the volume.\nassert math.isclose(volume_cylinder(10,5), 1570.7500000000002, rel_tol=0.001)\n\"\"\"\n",
972
+ solution: "\nimport math\ndef volume_cylinder(r,h):\n return math.pi * r * r * h\n"
973
+ },
974
+ {
975
+ assertions: "\nassert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},170)=={'Cierra Vega': 175, 'Alden Cantrell': 180, 'Pierre Cox': 190}\nassert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},180)=={ 'Alden Cantrell': 180, 'Pierre Cox': 190}\nassert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},190)=={ 'Pierre Cox': 190}\n",
976
+ entryPoint: "dict_filter",
977
+ id: "Mbpp/277",
978
+ prompt: "\"\"\"\nWrite 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.\nassert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},170)=={'Cierra Vega': 175, 'Alden Cantrell': 180, 'Pierre Cox': 190}\n\"\"\"\n",
979
+ solution: "\ndef dict_filter(dict1, n):\n return {key : value for (key, value) in dict1.items() if value >=n}\n"
980
+ },
981
+ {
982
+ assertions: "\nassert count_first_elements((1, 5, 7, (4, 6), 10) ) == 3\nassert count_first_elements((2, 9, (5, 7), 11) ) == 2\nassert count_first_elements((11, 15, 5, 8, (2, 3), 8) ) == 4\n",
983
+ entryPoint: "count_first_elements",
984
+ id: "Mbpp/278",
985
+ prompt: "\"\"\"\nWrite a function to find the number of elements that occurs before the tuple element in the given tuple.\nassert count_first_elements((1, 5, 7, (4, 6), 10) ) == 3\n\"\"\"\n",
986
+ solution: "\ndef count_first_elements(test_tup):\n for count, ele in enumerate(test_tup):\n if isinstance(ele, tuple):\n break\n return count\n"
987
+ },
988
+ {
989
+ assertions: "\nassert is_num_decagonal(3) == 27\nassert is_num_decagonal(7) == 175\nassert is_num_decagonal(10) == 370\n",
990
+ entryPoint: "is_num_decagonal",
991
+ id: "Mbpp/279",
992
+ prompt: "\"\"\"\nWrite a function to find the nth decagonal number.\nassert is_num_decagonal(3) == 27\n\"\"\"\n",
993
+ solution: "\ndef is_num_decagonal(n): \n\treturn 4 * n * n - 3 * n \n"
994
+ },
995
+ {
996
+ assertions: "\nassert sequential_search([11,23,58,31,56,77,43,12,65,19],31) == (True, 3)\nassert sequential_search([12, 32, 45, 62, 35, 47, 44, 61],61) == (True, 7)\nassert sequential_search([9, 10, 17, 19, 22, 39, 48, 56],48) == (True, 6)\n",
997
+ entryPoint: "sequential_search",
998
+ id: "Mbpp/280",
999
+ prompt: "\"\"\"\nWrite 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).\nassert sequential_search([11,23,58,31,56,77,43,12,65,19],31) == (True, 3)\n\"\"\"\n",
1000
+ solution: "\ndef sequential_search(dlist, item):\n return item in dlist, (dlist.index(item) if item in dlist else -1)\n"
1001
+ },
1002
+ {
1003
+ assertions: "\nassert all_unique([1,2,3]) == True\nassert all_unique([1,2,1,2]) == False\nassert all_unique([1,2,3,4,5]) == True\n",
1004
+ entryPoint: "all_unique",
1005
+ id: "Mbpp/281",
1006
+ prompt: "\"\"\"\nWrite a python function to check if the elements of a given list are unique or not.\nassert all_unique([1,2,3]) == True\n\"\"\"\n",
1007
+ solution: "\ndef all_unique(test_list):\n return len(test_list) == len(set(test_list))\n"
1008
+ },
1009
+ {
1010
+ assertions: "\nassert sub_list([1, 2, 3],[4,5,6])==[-3,-3,-3]\nassert sub_list([1,2],[3,4])==[-2,-2]\nassert sub_list([90,120],[50,70])==[40,50]\n",
1011
+ entryPoint: "sub_list",
1012
+ id: "Mbpp/282",
1013
+ prompt: "\"\"\"\nWrite a function to subtract two lists element-wise.\nassert sub_list([1, 2, 3],[4,5,6])==[-3,-3,-3]\n\"\"\"\n",
1014
+ solution: "\ndef sub_list(nums1,nums2):\n return [num1 - num2 for num1, num2 in zip(nums1, nums2)]\n"
1015
+ },
1016
+ {
1017
+ assertions: "\nassert validate(1234) == True\nassert validate(51241) == False\nassert validate(321) == True\n",
1018
+ entryPoint: "validate",
1019
+ id: "Mbpp/283",
1020
+ prompt: "\"\"\"\nWrite 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.\nassert validate(1234) == True\n\"\"\"\n",
1021
+ solution: "\ndef validate(n): \n digits = [int(digit) for digit in str(n)]\n return all(digit >= digits.count(digit) for digit in digits)\n"
1022
+ },
1023
+ {
1024
+ assertions: "\nassert check_element([\"green\", \"orange\", \"black\", \"white\"],'blue')==False\nassert check_element([1,2,3,4],7)==False\nassert check_element([\"green\", \"green\", \"green\", \"green\"],'green')==True\n",
1025
+ entryPoint: "check_element",
1026
+ id: "Mbpp/284",
1027
+ prompt: "\"\"\"\nWrite a function that takes in a list and element and checks whether all items in the list are equal to the given element.\nassert check_element([\"green\", \"orange\", \"black\", \"white\"],'blue')==False\n\"\"\"\n",
1028
+ solution: "\ndef check_element(list1, element):\n return all(v == element for v in list1)\n"
1029
+ },
1030
+ {
1031
+ assertions: "\nassert text_match_two_three(\"ac\")==(False)\nassert text_match_two_three(\"dc\")==(False)\nassert text_match_two_three(\"abbbba\")==(True)\n",
1032
+ entryPoint: "text_match_two_three",
1033
+ id: "Mbpp/285",
1034
+ prompt: "\"\"\"\nWrite a function that checks whether a string contains the 'a' character followed by two or three 'b' characters.\nassert text_match_two_three(\"ac\")==(False)\n\"\"\"\n",
1035
+ solution: "\nimport re\ndef text_match_two_three(text):\n patterns = 'ab{2,3}'\n return re.search(patterns, text) is not None\n"
1036
+ },
1037
+ {
1038
+ assertions: "\nassert max_sub_array_sum_repeated([10, 20, -30, -1], 4, 3) == 30\nassert max_sub_array_sum_repeated([-1, 10, 20], 3, 2) == 59\nassert max_sub_array_sum_repeated([-1, -2, -3], 3, 3) == -1\n",
1039
+ entryPoint: "max_sub_array_sum_repeated",
1040
+ id: "Mbpp/286",
1041
+ prompt: "\"\"\"\nWrite 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.\nassert max_sub_array_sum_repeated([10, 20, -30, -1], 4, 3) == 30\n\"\"\"\n",
1042
+ solution: "\ndef max_sub_array_sum_repeated(a, n, k): \n\tmodifed = a * k\n\tpre = 0\t# dp[i-1]\n\tres = modifed[0]\n\tfor n in modifed:\n\t\tpre = max(pre + n, n)\n\t\tres = max(pre, res)\n\treturn res\n"
1043
+ },
1044
+ {
1045
+ assertions: "\nassert square_Sum(2) == 20\nassert square_Sum(3) == 56\nassert square_Sum(4) == 120\n",
1046
+ entryPoint: "square_Sum",
1047
+ id: "Mbpp/287",
1048
+ prompt: "\"\"\"\nWrite a python function takes in an integer n and returns the sum of squares of first n even natural numbers.\nassert square_Sum(2) == 20\n\"\"\"\n",
1049
+ solution: "\ndef square_Sum(n): \n return 2 * n * (n + 1) * (2 * n + 1) /3\n"
1050
+ },
1051
+ {
1052
+ assertions: "\nassert max_length([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])\nassert max_length([[1], [5, 7], [10, 12, 14,15]])==(4, [10, 12, 14,15])\nassert max_length([[5], [15,20,25]])==(3, [15,20,25])\n",
1053
+ entryPoint: "max_length",
1054
+ id: "Mbpp/290",
1055
+ prompt: "\"\"\"\nWrite a function to find the list of maximum length in a list of lists.\nassert max_length([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])\n\"\"\"\n",
1056
+ solution: "\ndef max_length(list1):\n return max([(len(x), x) for x in list1], key=lambda x: x[0])\n"
1057
+ },
1058
+ {
1059
+ assertions: "\nassert find(10,3) == 3\nassert find(4,2) == 2\nassert find(20,5) == 4\n",
1060
+ entryPoint: "find",
1061
+ id: "Mbpp/292",
1062
+ prompt: "\"\"\"\nWrite a python function to find quotient of two numbers (rounded down to the nearest integer).\nassert find(10,3) == 3\n\"\"\"\n",
1063
+ solution: "\ndef find(n,m): \n return n // m \n"
1064
+ },
1065
+ {
1066
+ assertions: "\nassert math.isclose(otherside_rightangle(7,8), 10.63014581273465, rel_tol=0.001)\nassert math.isclose(otherside_rightangle(3,4), 5, rel_tol=0.001)\nassert math.isclose(otherside_rightangle(7,15), 16.55294535724685, rel_tol=0.001)\n",
1067
+ entryPoint: "otherside_rightangle",
1068
+ id: "Mbpp/293",
1069
+ prompt: "\"\"\"\nWrite a function to find the third side of a right angled triangle.\nassert otherside_rightangle(7,8)==10.63014581273465\n\"\"\"\n",
1070
+ solution: "\nimport math\ndef otherside_rightangle(w,h):\n return math.sqrt(w * w + h * h)\n"
1071
+ },
1072
+ {
1073
+ assertions: "\nassert max_val(['Python', 3, 2, 4, 5, 'version'])==5\nassert max_val(['Python', 15, 20, 25])==25\nassert max_val(['Python', 30, 20, 40, 50, 'version'])==50\n",
1074
+ entryPoint: "max_val",
1075
+ id: "Mbpp/294",
1076
+ prompt: "\"\"\"\nWrite a function to find the maximum value in a given heterogeneous list.\nassert max_val(['Python', 3, 2, 4, 5, 'version'])==5\n\"\"\"\n",
1077
+ solution: "\ndef max_val(listval):\n max_val = max(i for i in listval if isinstance(i, int)) \n return max_val\n"
1078
+ },
1079
+ {
1080
+ assertions: "\nassert get_Inv_Count([1,20,6,4,5]) == 5\nassert get_Inv_Count([1,2,1]) == 1\nassert get_Inv_Count([1,2,5,6,1]) == 3\n",
1081
+ entryPoint: "get_Inv_Count",
1082
+ id: "Mbpp/296",
1083
+ prompt: "\"\"\"\nWrite a python function to count inversions in an array.\nassert get_Inv_Count([1,20,6,4,5]) == 5\n\"\"\"\n",
1084
+ solution: "\ndef get_Inv_Count(arr): \n # consider use merge sort, but for simplicity, use brute force\n inv_count = 0\n for i in range(len(arr)): \n for j in range(i + 1, len(arr)): \n if (arr[i] > arr[j]): \n inv_count += 1\n return inv_count \n"
1085
+ },
1086
+ {
1087
+ assertions: "\nassert flatten_list([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]\nassert flatten_list([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])==[10, 20, 40, 30, 56, 25, 10, 20, 33, 40]\nassert flatten_list([[1,2,3], [4,5,6], [10,11,12], [7,8,9]])==[1, 2, 3, 4, 5, 6, 10, 11, 12, 7, 8, 9]\n",
1088
+ entryPoint: "flatten_list",
1089
+ id: "Mbpp/297",
1090
+ prompt: "\"\"\"\nWrite a function to flatten a given nested list structure.\nassert flatten_list([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]\n\"\"\"\n",
1091
+ solution: "\ndef flatten_list(list1):\n\tresult = []\n\tfor item in list1:\n\t\tif isinstance(item, list):\n\t\t\tresult.extend(flatten_list(item))\n\t\telse:\n\t\t\tresult.append(item)\n\treturn result\n"
1092
+ },
1093
+ {
1094
+ assertions: "\nassert max_aggregate([('Juan Whelan',90),('Sabah Colley',88),('Peter Nichols',7),('Juan Whelan',122),('Sabah Colley',84)])==('Juan Whelan', 212)\nassert max_aggregate([('Juan Whelan',50),('Sabah Colley',48),('Peter Nichols',37),('Juan Whelan',22),('Sabah Colley',14)])==('Juan Whelan', 72)\nassert max_aggregate([('Juan Whelan',10),('Sabah Colley',20),('Peter Nichols',30),('Juan Whelan',40),('Sabah Colley',50)])==('Sabah Colley', 70)\n",
1095
+ entryPoint: "max_aggregate",
1096
+ id: "Mbpp/299",
1097
+ prompt: "\"\"\"\nWrite a function to calculate the maximum aggregate from the list of tuples.\nassert max_aggregate([('Juan Whelan',90),('Sabah Colley',88),('Peter Nichols',7),('Juan Whelan',122),('Sabah Colley',84)])==('Juan Whelan', 212)\n\"\"\"\n",
1098
+ solution: "\nfrom collections import defaultdict\ndef max_aggregate(stdata):\n temp = defaultdict(int)\n for name, marks in stdata:\n temp[name] += marks\n return max(temp.items(), key=lambda x: x[1])\n"
1099
+ },
1100
+ {
1101
+ assertions: "import math\n\nassert math.isclose(count_binary_seq(1), 2.0, rel_tol=0.001)\nassert math.isclose(count_binary_seq(2), 6.0, rel_tol=0.001)\nassert math.isclose(count_binary_seq(3), 20.0, rel_tol=0.001)\n",
1102
+ entryPoint: "count_binary_seq",
1103
+ id: "Mbpp/300",
1104
+ prompt: "\"\"\"\nWrite 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.\nassert math.isclose(count_binary_seq(1), 2.0, rel_tol=0.001)\n\"\"\"\n",
1105
+ solution: "\ndef count_binary_seq(n): \n\tnCr = 1\n\tres = 1\n\tfor r in range(1, n + 1): \n\t\tnCr = (nCr * (n + 1 - r)) / r \n\t\tres += nCr * nCr \n\treturn res \n"
1106
+ },
1107
+ {
1108
+ assertions: "\nassert dict_depth({'a':1, 'b': {'c': {'d': {}}}})==4\nassert dict_depth({'a':1, 'b': {'c':'python'}})==2\nassert dict_depth({1: 'Sun', 2: {3: {4:'Mon'}}})==3\n",
1109
+ entryPoint: "dict_depth",
1110
+ id: "Mbpp/301",
1111
+ prompt: "\"\"\"\nWrite a function to find the depth of a dictionary.\nassert dict_depth({'a':1, 'b': {'c': {'d': {}}}})==4\n\"\"\"\n",
1112
+ solution: "\ndef dict_depth_aux(d):\n if isinstance(d, dict):\n return 1 + (max(map(dict_depth_aux, d.values())) if d else 0)\n return 0\ndef dict_depth(d):\n return dict_depth_aux(d)\n"
1113
+ },
1114
+ {
1115
+ assertions: "\nassert start_withp([\"Python PHP\", \"Java JavaScript\", \"c c++\"])==('Python', 'PHP')\nassert start_withp([\"Python Programming\",\"Java Programming\"])==('Python','Programming')\nassert start_withp([\"Pqrst Pqr\",\"qrstuv\"])==('Pqrst','Pqr')\n",
1116
+ entryPoint: "start_withp",
1117
+ id: "Mbpp/305",
1118
+ prompt: "\"\"\"\nWrite a function to return two words from a list of words starting with letter 'p'.\nassert start_withp([\"Python PHP\", \"Java JavaScript\", \"c c++\"])==('Python', 'PHP')\n\"\"\"\n",
1119
+ solution: "\nimport re\ndef start_withp(words):\n for w in words:\n m = re.match(\"(P\\w+)\\W(P\\w+)\", w)\n if m:\n return m.groups()\n"
1120
+ },
1121
+ {
1122
+ assertions: "\nassert max_sum_increasing_subseq([1, 101, 2, 3, 100, 4, 5 ], 7, 4, 6) == 11\nassert max_sum_increasing_subseq([1, 101, 2, 3, 100, 4, 5 ], 7, 2, 5) == 7\nassert max_sum_increasing_subseq([11, 15, 19, 21, 26, 28, 31], 7, 2, 4) == 71\n",
1123
+ entryPoint: "max_sum_increasing_subseq",
1124
+ id: "Mbpp/306",
1125
+ prompt: "\"\"\"\nWrite 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 .\nassert max_sum_increasing_subseq([1, 101, 2, 3, 100, 4, 5 ], 7, 4, 6) == 11\n\"\"\"\n",
1126
+ solution: "\ndef max_sum_increasing_subseq(a, n, index, k):\n\tdp = [[0 for _ in range(n)] for _ in range(n)]\n\tfor i in range(n):\n\t\tif a[i] > a[0]:\n\t\t\tdp[0][i] = a[i] + a[0]\n\t\telse:\n\t\t\tdp[0][i] = a[i]\n\tfor i in range(1, n):\n\t\tfor j in range(n):\n\t\t\tif a[j] > a[i] and j > i:\n\t\t\t\tif dp[i - 1][i] + a[j] > dp[i - 1][j]:\n\t\t\t\t\tdp[i][j] = dp[i - 1][i] + a[j]\n\t\t\t\telse:\n\t\t\t\t\tdp[i][j] = dp[i - 1][j]\n\t\t\telse:\n\t\t\t\tdp[i][j] = dp[i - 1][j]\n\treturn dp[index][k]\n"
1127
+ },
1128
+ {
1129
+ assertions: "\nassert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],3)==[60, 54, 50]\nassert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],4)==[60, 54, 50, 48]\nassert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],5)==[60, 54, 50, 48, 45]\n",
1130
+ entryPoint: "large_product",
1131
+ id: "Mbpp/308",
1132
+ prompt: "\"\"\"\nWrite a function to find the specified number of largest products from two given lists, selecting one factor from each list.\nassert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],3)==[60, 54, 50]\n\"\"\"\n",
1133
+ solution: "\ndef large_product(nums1, nums2, N):\n result = sorted([x*y for x in nums1 for y in nums2], reverse=True)[:N]\n return result\n"
1134
+ },
1135
+ {
1136
+ assertions: "\nassert maximum(5,10) == 10\nassert maximum(-1,-2) == -1\nassert maximum(9,7) == 9\n",
1137
+ entryPoint: "maximum",
1138
+ id: "Mbpp/309",
1139
+ prompt: "\"\"\"\nWrite a python function to find the maximum of two numbers.\nassert maximum(5,10) == 10\n\"\"\"\n",
1140
+ solution: "\ndef maximum(a,b): \n return max(a, b)\n"
1141
+ },
1142
+ {
1143
+ assertions: "\nassert string_to_tuple(\"python 3.0\")==('p', 'y', 't', 'h', 'o', 'n', '3', '.', '0')\nassert string_to_tuple(\"item1\")==('i', 't', 'e', 'm', '1')\nassert string_to_tuple(\"15.10\")==('1', '5', '.', '1', '0')\n",
1144
+ entryPoint: "string_to_tuple",
1145
+ id: "Mbpp/310",
1146
+ prompt: "\"\"\"\nWrite a function to convert a given string to a tuple of characters.\nassert string_to_tuple(\"python 3.0\")==('p', 'y', 't', 'h', 'o', 'n', '3', '.', '0')\n\"\"\"\n",
1147
+ solution: "\ndef string_to_tuple(str1):\n result = tuple(x for x in str1 if not x.isspace()) \n return result\n"
1148
+ },
1149
+ {
1150
+ assertions: "\nassert set_left_most_unset_bit(10) == 14\nassert set_left_most_unset_bit(12) == 14\nassert set_left_most_unset_bit(15) == 15\n",
1151
+ entryPoint: "set_left_most_unset_bit",
1152
+ id: "Mbpp/311",
1153
+ prompt: "\"\"\"\nWrite a python function to set the left most unset bit.\nassert set_left_most_unset_bit(10) == 14\n\"\"\"\n",
1154
+ solution: "\ndef set_left_most_unset_bit(n): \n if not (n & (n + 1)): \n return n \n pos, temp, count = 0, n, 0 \n while temp: \n if not (temp & 1): \n pos = count \n count += 1\n temp >>= 1\n return (n | (1 << (pos))) \n"
1155
+ },
1156
+ {
1157
+ assertions: "import math\n\nassert math.isclose(volume_cone(5,12), 314.15926535897927, rel_tol=0.001)\nassert math.isclose(volume_cone(10,15), 1570.7963267948965, rel_tol=0.001)\nassert math.isclose(volume_cone(19,17), 6426.651371693521, rel_tol=0.001)\n",
1158
+ entryPoint: "volume_cone",
1159
+ id: "Mbpp/312",
1160
+ prompt: "\"\"\"\nWrite a function to find the volume of a cone.\nassert math.isclose(volume_cone(5,12), 314.15926535897927, rel_tol=0.001)\n\"\"\"\n",
1161
+ solution: "\nimport math\ndef volume_cone(r,h):\n return (1.0 / 3) * math.pi * r * r * h\n"
1162
+ },
1163
+ {
1164
+ assertions: "\nassert highest_Power_of_2(10) == 8\nassert highest_Power_of_2(19) == 16\nassert highest_Power_of_2(32) == 32\n",
1165
+ entryPoint: "highest_Power_of_2",
1166
+ id: "Mbpp/388",
1167
+ prompt: "\"\"\"\nWrite a python function to find the highest power of 2 that is less than or equal to n.\nassert highest_Power_of_2(10) == 8\n\"\"\"\n",
1168
+ solution: "\ndef highest_Power_of_2(n): \n i = 0\n while ((1 << i) <= n): \n i += 1\n return (1 << (i - 1))\n"
1169
+ },
1170
+ {
1171
+ assertions: "\nassert find_lucas(9) == 76\nassert find_lucas(4) == 7\nassert find_lucas(3) == 4\n",
1172
+ entryPoint: "find_lucas",
1173
+ id: "Mbpp/389",
1174
+ prompt: "\"\"\"\nWrite a function to find the n'th lucas number.\nassert find_lucas(9) == 76\n\"\"\"\n",
1175
+ solution: "\ndef find_lucas(n): \n\tif (n == 0): \n\t\treturn 2\n\tif (n == 1): \n\t\treturn 1\n\treturn find_lucas(n - 1) + find_lucas(n - 2) \n"
1176
+ },
1177
+ {
1178
+ assertions: "\nassert add_string([1,2,3,4],'temp{0}')==['temp1', 'temp2', 'temp3', 'temp4']\nassert add_string(['a','b','c','d'], 'python{0}')==[ 'pythona', 'pythonb', 'pythonc', 'pythond']\nassert add_string([5,6,7,8],'string{0}')==['string5', 'string6', 'string7', 'string8']\n",
1179
+ entryPoint: "add_string",
1180
+ id: "Mbpp/390",
1181
+ prompt: "\"\"\"\nWrite a function to apply a given format string to all of the elements in a list.\nassert add_string([1,2,3,4],'temp{0}')==['temp1', 'temp2', 'temp3', 'temp4']\n\"\"\"\n",
1182
+ solution: "\ndef add_string(list_, string):\n return [string.format(i) for i in list_]\n"
1183
+ },
1184
+ {
1185
+ assertions: "\nassert convert_list_dictionary([\"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}}]\nassert convert_list_dictionary([\"abc\",\"def\",\"ghi\",\"jkl\"],[\"python\",\"program\",\"language\",\"programs\"],[100,200,300,400])==[{'abc':{'python':100}},{'def':{'program':200}},{'ghi':{'language':300}},{'jkl':{'programs':400}}]\nassert convert_list_dictionary([\"A1\",\"A2\",\"A3\",\"A4\"],[\"java\",\"C\",\"C++\",\"DBMS\"],[10,20,30,40])==[{'A1':{'java':10}},{'A2':{'C':20}},{'A3':{'C++':30}},{'A4':{'DBMS':40}}]\n",
1186
+ entryPoint: "convert_list_dictionary",
1187
+ id: "Mbpp/391",
1188
+ prompt: "\"\"\"\nWrite a function to convert more than one list to nested dictionary.\nassert convert_list_dictionary([\"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}}]\n\"\"\"\n",
1189
+ solution: "\ndef convert_list_dictionary(l1, l2, l3):\n result = [{x: {y: z}} for (x, y, z) in zip(l1, l2, l3)]\n return result\n"
1190
+ },
1191
+ {
1192
+ assertions: "\nassert get_max_sum(60) == 106\nassert get_max_sum(10) == 12\nassert get_max_sum(2) == 2\n",
1193
+ entryPoint: "get_max_sum",
1194
+ id: "Mbpp/392",
1195
+ prompt: "\"\"\"\nWrite 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).\nassert get_max_sum(60) == 106\n\"\"\"\n",
1196
+ solution: "\ndef get_max_sum (n):\n\t# if n = 0, f(0) = max(5(f(0), 0)), so f(0) = 5f(0) or f(0) = 0, for both cases f(0) = 0\n\tres = [0]\n\tfor i in range(1, n + 1):\n\t\tres.append(max(res[i // 2] + res[i // 3] + res[i // 4] + res[i // 5], i))\n\treturn res[n]\n"
1197
+ },
1198
+ {
1199
+ assertions: "\nassert check_distinct((1, 4, 5, 6, 1, 4)) == False\nassert check_distinct((1, 4, 5, 6)) == True\nassert check_distinct((2, 3, 4, 5, 6)) == True\n",
1200
+ entryPoint: "check_distinct",
1201
+ id: "Mbpp/394",
1202
+ prompt: "\"\"\"\nWrite a function to check if given tuple contains no duplicates.\nassert check_distinct((1, 4, 5, 6, 1, 4)) == False\n\"\"\"\n",
1203
+ solution: "\ndef check_distinct(test_tup):\n return len(test_tup) == len(set(test_tup))\n"
1204
+ },
1205
+ {
1206
+ assertions: "\nassert first_non_repeating_character(\"abcabc\") == None\nassert first_non_repeating_character(\"abc\") == \"a\"\nassert first_non_repeating_character(\"ababc\") == \"c\"\n",
1207
+ entryPoint: "first_non_repeating_character",
1208
+ id: "Mbpp/395",
1209
+ prompt: "\"\"\"\nWrite a python function to find the first non-repeated character in a given string.\nassert first_non_repeating_character(\"abcabc\") == None\n\"\"\"\n",
1210
+ solution: "\ndef first_non_repeating_character(str1):\n for ch in str1:\n if str1.count(ch) == 1:\n return ch\n return None\n"
1211
+ },
1212
+ {
1213
+ assertions: "\nassert median_numbers(25,55,65)==55.0\nassert median_numbers(20,10,30)==20.0\nassert median_numbers(15,45,75)==45.0\n",
1214
+ entryPoint: "median_numbers",
1215
+ id: "Mbpp/397",
1216
+ prompt: "\"\"\"\nWrite a function to find the median of three numbers.\nassert median_numbers(25,55,65)==55.0\n\"\"\"\n",
1217
+ solution: "\ndef median_numbers(a,b,c):\n return sorted([a,b,c])[1]\n"
1218
+ },
1219
+ {
1220
+ assertions: "\nassert sum_of_digits([10,2,56])==14\nassert sum_of_digits([[10,20,4,5,'b',70,'a']])==19\nassert sum_of_digits([10,20,-4,5,-70])==19\n",
1221
+ entryPoint: "sum_of_digits",
1222
+ id: "Mbpp/398",
1223
+ prompt: "\"\"\"\nWrite a function to compute the sum of digits of each number of a given list.\nassert sum_of_digits([10,2,56])==14\n\"\"\"\n",
1224
+ solution: "\ndef sum_of_digits(nums):\n return sum(int(el) for n in nums for el in str(n) if el.isdigit())\n"
1225
+ },
1226
+ {
1227
+ assertions: "\nassert minimum(1,2) == 1\nassert minimum(-5,-4) == -5\nassert minimum(0,0) == 0\n",
1228
+ entryPoint: "minimum",
1229
+ id: "Mbpp/404",
1230
+ prompt: "\"\"\"\nWrite a python function to find the minimum of two numbers.\nassert minimum(1,2) == 1\n\"\"\"\n",
1231
+ solution: "\ndef minimum(a,b): \n return min(a,b)\n"
1232
+ },
1233
+ {
1234
+ assertions: "\nassert check_tuplex((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),'r')==True\nassert check_tuplex((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),'5')==False\nassert check_tuplex((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\",\"e\"),3)==True\n",
1235
+ entryPoint: "check_tuplex",
1236
+ id: "Mbpp/405",
1237
+ prompt: "\"\"\"\nWrite a function to check whether an element exists within a tuple.\nassert check_tuplex((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),'r')==True\n\"\"\"\n",
1238
+ solution: "\ndef check_tuplex(tuplex, element): \n return element in tuplex\n"
1239
+ },
1240
+ {
1241
+ assertions: "\nassert find_Parity(12) == False\nassert find_Parity(7) == True\nassert find_Parity(10) == False\n",
1242
+ entryPoint: "find_Parity",
1243
+ id: "Mbpp/406",
1244
+ prompt: "\"\"\"\nWrite a python function to find whether the parity of a given number is odd.\nassert find_Parity(12) == False\n\"\"\"\n",
1245
+ solution: "\ndef find_Parity(x): \n return x % 2 != 0\n"
1246
+ },
1247
+ {
1248
+ assertions: "\nassert min_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==8\nassert min_product_tuple([(10,20), (15,2), (5,10)] )==30\nassert min_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==100\n",
1249
+ entryPoint: "min_product_tuple",
1250
+ id: "Mbpp/409",
1251
+ prompt: "\"\"\"\nWrite a function to find the minimum product from the pairs of tuples within a given list.\nassert min_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==8\n\"\"\"\n",
1252
+ solution: "\ndef min_product_tuple(list1):\n return min(x * y for x, y in list1)\n"
1253
+ },
1254
+ {
1255
+ assertions: "\nassert min_val(['Python', 3, 2, 4, 5, 'version'])==2\nassert min_val(['Python', 15, 20, 25])==15\nassert min_val(['Python', 30, 20, 40, 50, 'version'])==20\n",
1256
+ entryPoint: "min_val",
1257
+ id: "Mbpp/410",
1258
+ prompt: "\"\"\"\nWrite a function to find the minimum value in a given heterogeneous list.\nassert min_val(['Python', 3, 2, 4, 5, 'version'])==2\n\"\"\"\n",
1259
+ solution: "\ndef min_val(listval):\n min_val = min(i for i in listval if isinstance(i, int))\n return min_val\n"
1260
+ },
1261
+ {
1262
+ assertions: "\nassert remove_odd([1,2,3]) == [2]\nassert remove_odd([2,4,6]) == [2,4,6]\nassert remove_odd([10,20,3]) == [10,20]\n",
1263
+ entryPoint: "remove_odd",
1264
+ id: "Mbpp/412",
1265
+ prompt: "\"\"\"\nWrite a python function to remove odd numbers from a given list.\nassert remove_odd([1,2,3]) == [2]\n\"\"\"\n",
1266
+ solution: "\ndef remove_odd(l):\n return [i for i in l if i % 2 == 0]\n"
1267
+ },
1268
+ {
1269
+ assertions: "\nassert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,0)==['Greyson Fulton', 'Brady Kent', 'Wyatt Knott', 'Beau Turnbull']\nassert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,2)==[99, 96, 94, 98]\nassert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)],1)==[98, 97, 91, 94]\n",
1270
+ entryPoint: "extract_nth_element",
1271
+ id: "Mbpp/413",
1272
+ prompt: "\"\"\"\nWrite a function to extract the nth element from a given list of tuples.\nassert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,0)==['Greyson Fulton', 'Brady Kent', 'Wyatt Knott', 'Beau Turnbull']\n\"\"\"\n",
1273
+ solution: "\ndef extract_nth_element(list1, n):\n return [x[n] for x in list1]\n"
1274
+ },
1275
+ {
1276
+ assertions: "\nassert overlapping([1,2,3,4,5],[6,7,8,9]) == False\nassert overlapping([1,2,3],[4,5,6]) == False\nassert overlapping([1,4,5],[1,4,5]) == True\n",
1277
+ entryPoint: "overlapping",
1278
+ id: "Mbpp/414",
1279
+ prompt: "\"\"\"\nWrite a python function to check whether any value in a sequence exists in a sequence or not.\nassert overlapping([1,2,3,4,5],[6,7,8,9]) == False\n\"\"\"\n",
1280
+ solution: "\ndef overlapping(list1,list2): \n return any(v in list2 for v in list1)\n"
1281
+ },
1282
+ {
1283
+ assertions: "\nassert max_Product([1,2,3,4,7,0,8,4]) == (7,8)\nassert max_Product([0,-1,-2,-4,5,0,-6]) == (-4,-6)\nassert max_Product([1,2,3]) == (2,3)\n",
1284
+ entryPoint: "max_Product",
1285
+ id: "Mbpp/415",
1286
+ prompt: "\"\"\"\nWrite a python function to find a pair with highest product from a given array of integers.\nassert max_Product([1,2,3,4,7,0,8,4]) == (7,8)\n\"\"\"\n",
1287
+ solution: "\ndef max_Product(arr): \n pairs = [(a, b) for a in arr for b in arr if a != b]\n return max(pairs, key=lambda x: x[0] * x[1])\n"
1288
+ },
1289
+ {
1290
+ assertions: "\nassert Find_Max([['A'],['A','B'],['A','B','C']]) == ['A','B','C']\nassert Find_Max([[1],[1,2],[1,2,3]]) == [1,2,3]\nassert Find_Max([[1,1],[1,2,3],[1,5,6,1]]) == [1,5,6,1]\n",
1291
+ entryPoint: "Find_Max",
1292
+ id: "Mbpp/418",
1293
+ prompt: "\"\"\"\nWrite a python function to find the element of a list having maximum length.\nassert Find_Max([['A'],['A','B'],['A','B','C']]) == ['A','B','C']\n\"\"\"\n",
1294
+ solution: "\ndef Find_Max(lst): \n return max(lst, key = len)\n"
1295
+ },
1296
+ {
1297
+ assertions: "\nassert round_and_sum([22.4, 4.0, -16.22, -9.10, 11.00, -12.22, 14.20, -5.20, 17.50])==243\nassert round_and_sum([5,2,9,24.3,29])==345\nassert round_and_sum([25.0,56.7,89.2])==513\n",
1298
+ entryPoint: "round_and_sum",
1299
+ id: "Mbpp/419",
1300
+ prompt: "\"\"\"\nWrite a function to round every number of a given list of numbers and print the total sum multiplied by the length of the list.\nassert round_and_sum([22.4, 4.0, -16.22, -9.10, 11.00, -12.22, 14.20, -5.20, 17.50])==243\n\"\"\"\n",
1301
+ solution: "\ndef round_and_sum(list1):\n l = len(list1)\n return sum([round(i) for i in list1]) * l\n"
1302
+ },
1303
+ {
1304
+ assertions: "\nassert cube_Sum(2) == 72\nassert cube_Sum(3) == 288\nassert cube_Sum(4) == 800\n",
1305
+ entryPoint: "cube_Sum",
1306
+ id: "Mbpp/420",
1307
+ prompt: "\"\"\"\nWrite a python function to find the cube sum of first n even natural numbers.\nassert cube_Sum(2) == 72\n\"\"\"\n",
1308
+ solution: "\ndef cube_Sum(n): \n return 2 * (n ** 2) * ((n + 1) ** 2)\n"
1309
+ },
1310
+ {
1311
+ assertions: "\nassert concatenate_tuple((\"ID\", \"is\", 4, \"UTS\") ) == 'ID-is-4-UTS'\nassert concatenate_tuple((\"QWE\", \"is\", 4, \"RTY\") ) == 'QWE-is-4-RTY'\nassert concatenate_tuple((\"ZEN\", \"is\", 4, \"OP\") ) == 'ZEN-is-4-OP'\n",
1312
+ entryPoint: "concatenate_tuple",
1313
+ id: "Mbpp/421",
1314
+ prompt: "\"\"\"\nWrite a function to concatenate each element of tuple by the delimiter.\nassert concatenate_tuple((\"ID\", \"is\", 4, \"UTS\") ) == 'ID-is-4-UTS'\n\"\"\"\n",
1315
+ solution: "\ndef concatenate_tuple(test_tup):\n delim = \"-\"\n res = ''.join([str(ele) + delim for ele in test_tup])\n res = res[ : len(res) - len(delim)]\n return (str(res)) \n"
1316
+ },
1317
+ {
1318
+ assertions: "\nassert find_Average_Of_Cube(2) == 4.5\nassert find_Average_Of_Cube(3) == 12\nassert find_Average_Of_Cube(1) == 1\n",
1319
+ entryPoint: "find_Average_Of_Cube",
1320
+ id: "Mbpp/422",
1321
+ prompt: "\"\"\"\nWrite a python function to find the average of cubes of first n natural numbers.\nassert find_Average_Of_Cube(2) == 4.5\n\"\"\"\n",
1322
+ solution: "\ndef find_Average_Of_Cube(n): \n return sum([(i ** 3) for i in range(1, n + 1)]) / n\n"
1323
+ },
1324
+ {
1325
+ assertions: "\nassert extract_rear(('Mers', 'for', 'Vers') ) == ['s', 'r', 's']\nassert extract_rear(('Avenge', 'for', 'People') ) == ['e', 'r', 'e']\nassert extract_rear(('Gotta', 'get', 'go') ) == ['a', 't', 'o']\n",
1326
+ entryPoint: "extract_rear",
1327
+ id: "Mbpp/424",
1328
+ prompt: "\"\"\"\nWrite a function to extract only the rear index element of each string in the given tuple.\nassert extract_rear(('Mers', 'for', 'Vers') ) == ['s', 'r', 's']\n\"\"\"\n",
1329
+ solution: "\ndef extract_rear(test_tuple):\n return [ele[-1] for ele in test_tuple]\n"
1330
+ },
1331
+ {
1332
+ assertions: "\nassert count_element_in_list([[1, 3], [5, 7], [1, 11], [1, 15, 7]],1)==3\nassert count_element_in_list([['A', 'B'], ['A', 'C'], ['A', 'D', 'E'], ['B', 'C', 'D']],'A')==3\nassert count_element_in_list([['A', 'B'], ['A', 'C'], ['A', 'D', 'E'], ['B', 'C', 'D']],'E')==1\n",
1333
+ entryPoint: "count_element_in_list",
1334
+ id: "Mbpp/425",
1335
+ prompt: "\"\"\"\nWrite a function to count the number of sublists containing a particular element.\nassert count_element_in_list([[1, 3], [5, 7], [1, 11], [1, 15, 7]],1)==3\n\"\"\"\n",
1336
+ solution: "\ndef count_element_in_list(list1, x): \n return sum(x in sublist for sublist in list1)\n"
1337
+ },
1338
+ {
1339
+ assertions: "\nassert filter_oddnumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9]\nassert filter_oddnumbers([10,20,45,67,84,93])==[45,67,93]\nassert filter_oddnumbers([5,7,9,8,6,4,3])==[5,7,9,3]\n",
1340
+ entryPoint: "filter_oddnumbers",
1341
+ id: "Mbpp/426",
1342
+ prompt: "\"\"\"\nWrite a function to filter odd numbers.\nassert filter_oddnumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9]\n\"\"\"\n",
1343
+ solution: "\ndef filter_oddnumbers(nums):\n return [n for n in nums if n % 2 == 1]\n"
1344
+ },
1345
+ {
1346
+ assertions: "\nassert change_date_format(\"2026-01-02\") == '02-01-2026'\nassert change_date_format(\"2020-11-13\") == '13-11-2020'\nassert change_date_format(\"2021-04-26\") == '26-04-2021'\n",
1347
+ entryPoint: "change_date_format",
1348
+ id: "Mbpp/427",
1349
+ prompt: "\"\"\"\nWrite a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.\nassert change_date_format(\"2026-01-02\") == '02-01-2026'\n\"\"\"\n",
1350
+ solution: "\nimport re\ndef change_date_format(dt):\n return re.sub(r'(\\d{4})-(\\d{1,2})-(\\d{1,2})', '\\\\3-\\\\2-\\\\1', dt)\n"
1351
+ },
1352
+ {
1353
+ assertions: "\nassert shell_sort([12, 23, 4, 5, 3, 2, 12, 81, 56, 95]) == [2, 3, 4, 5, 12, 12, 23, 56, 81, 95]\nassert shell_sort([24, 22, 39, 34, 87, 73, 68]) == [22, 24, 34, 39, 68, 73, 87]\nassert shell_sort([32, 30, 16, 96, 82, 83, 74]) == [16, 30, 32, 74, 82, 83, 96]\n",
1354
+ entryPoint: "shell_sort",
1355
+ id: "Mbpp/428",
1356
+ prompt: "\"\"\"\nWrite a function to sort the given array by using shell sort.\nassert shell_sort([12, 23, 4, 5, 3, 2, 12, 81, 56, 95]) == [2, 3, 4, 5, 12, 12, 23, 56, 81, 95]\n\"\"\"\n",
1357
+ solution: "\ndef shell_sort(my_list):\n gap = len(my_list) // 2\n while gap > 0:\n for i in range(gap, len(my_list)):\n current_item = my_list[i]\n j = i\n while j >= gap and my_list[j - gap] > current_item:\n my_list[j] = my_list[j - gap]\n j -= gap\n my_list[j] = current_item\n gap //= 2\n return my_list\n"
1358
+ },
1359
+ {
1360
+ assertions: "\nassert and_tuples((10, 4, 6, 9), (5, 2, 3, 3)) == (0, 0, 2, 1)\nassert and_tuples((1, 2, 3, 4), (5, 6, 7, 8)) == (1, 2, 3, 0)\nassert and_tuples((8, 9, 11, 12), (7, 13, 14, 17)) == (0, 9, 10, 0)\n",
1361
+ entryPoint: "and_tuples",
1362
+ id: "Mbpp/429",
1363
+ prompt: "\"\"\"\nWrite a function to extract the elementwise and tuples from the given two tuples.\nassert and_tuples((10, 4, 6, 9), (5, 2, 3, 3)) == (0, 0, 2, 1)\n\"\"\"\n",
1364
+ solution: "\ndef and_tuples(test_tup1, test_tup2):\n return tuple(x & y for x, y in zip(test_tup1, test_tup2))\n"
1365
+ },
1366
+ {
1367
+ assertions: "\nassert parabola_directrix(5,3,2)==-198\nassert parabola_directrix(9,8,4)==-2336\nassert parabola_directrix(2,4,6)==-130\n",
1368
+ entryPoint: "parabola_directrix",
1369
+ id: "Mbpp/430",
1370
+ prompt: "\"\"\"\nWrite a function to find the directrix of a parabola.\nassert parabola_directrix(5,3,2)==-198\n\"\"\"\n",
1371
+ solution: "\ndef parabola_directrix(a, b, c): \n return ((int)(c - ((b * b) + 1) * 4 * a ))\n"
1372
+ },
1373
+ {
1374
+ assertions: "\nassert median_trapezium(15,25,35)==20\nassert median_trapezium(10,20,30)==15\nassert median_trapezium(6,9,4)==7.5\n",
1375
+ entryPoint: "median_trapezium",
1376
+ id: "Mbpp/432",
1377
+ prompt: "\"\"\"\nWrite a function to find the median length of a trapezium.\nassert median_trapezium(15,25,35)==20\n\"\"\"\n",
1378
+ solution: "\ndef median_trapezium(base1,base2,height):\n return (base1 + base2) / 2\n"
1379
+ },
1380
+ {
1381
+ assertions: "\nassert check_greater([1, 2, 3, 4, 5], 4) == False\nassert check_greater([2, 3, 4, 5, 6], 8) == True\nassert check_greater([9, 7, 4, 8, 6, 1], 11) == True\n",
1382
+ entryPoint: "check_greater",
1383
+ id: "Mbpp/433",
1384
+ prompt: "\"\"\"\nWrite a function to check whether the entered number is greater than the elements of the given array.\nassert check_greater([1, 2, 3, 4, 5], 4) == False\n\"\"\"\n",
1385
+ solution: "\ndef check_greater(arr, number):\n return all(number > el for el in arr)\n"
1386
+ },
1387
+ {
1388
+ assertions: "\nassert last_Digit(123) == 3\nassert last_Digit(25) == 5\nassert last_Digit(30) == 0\n",
1389
+ entryPoint: "last_Digit",
1390
+ id: "Mbpp/435",
1391
+ prompt: "\"\"\"\nWrite a python function to find the last digit of a given number.\nassert last_Digit(123) == 3\n\"\"\"\n",
1392
+ solution: "\ndef last_Digit(n) :\n if n < 0: \n n = -n\n return n % 10\n"
1393
+ },
1394
+ {
1395
+ assertions: "\nassert neg_nos([-1,4,5,-6]) == [-1,-6]\nassert neg_nos([-1,-2,3,4]) == [-1,-2]\nassert neg_nos([-7,-6,8,9]) == [-7,-6]\n",
1396
+ entryPoint: "neg_nos",
1397
+ id: "Mbpp/436",
1398
+ prompt: "\"\"\"\nWrite a python function to return the negative numbers in a list.\nassert neg_nos([-1,4,5,-6]) == [-1,-6]\n\"\"\"\n",
1399
+ solution: "\ndef neg_nos(list1):\n return [i for i in list1 if i < 0]\n"
1400
+ },
1401
+ {
1402
+ assertions: "\nassert remove_odd(\"python\")==(\"yhn\")\nassert remove_odd(\"program\")==(\"rga\")\nassert remove_odd(\"language\")==(\"agae\")\n",
1403
+ entryPoint: "remove_odd",
1404
+ id: "Mbpp/437",
1405
+ prompt: "\"\"\"\nWrite a function to remove odd characters in a string.\nassert remove_odd(\"python\")==(\"yhn\")\n\"\"\"\n",
1406
+ solution: "\ndef remove_odd(str1):\n return str1[1::2]\n"
1407
+ },
1408
+ {
1409
+ assertions: "\nassert multiple_to_single([11, 33, 50])==113350\nassert multiple_to_single([-1,2,3,4,5,6])==-123456\nassert multiple_to_single([10,15,20,25])==10152025\n",
1410
+ entryPoint: "multiple_to_single",
1411
+ id: "Mbpp/439",
1412
+ prompt: "\"\"\"\nWrite a function to join a list of multiple integers into a single integer.\nassert multiple_to_single([11, 33, 50])==113350\n\"\"\"\n",
1413
+ solution: "\ndef multiple_to_single(L):\n return int(''.join(map(str,L)))\n"
1414
+ },
1415
+ {
1416
+ assertions: "\nassert find_adverb_position(\"clearly!! we can see the sky\")==(0, 7, 'clearly')\nassert find_adverb_position(\"seriously!! there are many roses\")==(0, 9, 'seriously')\nassert find_adverb_position(\"unfortunately!! sita is going to home\")==(0, 13, 'unfortunately')\n",
1417
+ entryPoint: "find_adverb_position",
1418
+ id: "Mbpp/440",
1419
+ prompt: "\"\"\"\nWrite a function to find the first adverb and their positions in a given sentence.\nassert find_adverb_position(\"clearly!! we can see the sky\")==(0, 7, 'clearly')\n\"\"\"\n",
1420
+ solution: "\nimport re\ndef find_adverb_position(text):\n for m in re.finditer(r\"\\w+ly\", text):\n return (m.start(), m.end(), m.group(0))\n"
1421
+ },
1422
+ {
1423
+ assertions: "\nassert surfacearea_cube(5)==150\nassert surfacearea_cube(3)==54\nassert surfacearea_cube(10)==600\n",
1424
+ entryPoint: "surfacearea_cube",
1425
+ id: "Mbpp/441",
1426
+ prompt: "\"\"\"\nWrite a function to find the surface area of a cube of a given size.\nassert surfacearea_cube(5)==150\n\"\"\"\n",
1427
+ solution: "\ndef surfacearea_cube(l):\n return 6 * l * l\n"
1428
+ },
1429
+ {
1430
+ assertions: "\nassert index_multiplication(((1, 3), (4, 5), (2, 9), (1, 10)),((6, 7), (3, 9), (1, 1), (7, 3)) ) == ((6, 21), (12, 45), (2, 9), (7, 30))\nassert index_multiplication(((2, 4), (5, 6), (3, 10), (2, 11)),((7, 8), (4, 10), (2, 2), (8, 4)) ) == ((14, 32), (20, 60), (6, 20), (16, 44))\nassert index_multiplication(((3, 5), (6, 7), (4, 11), (3, 12)),((8, 9), (5, 11), (3, 3), (9, 5)) ) == ((24, 45), (30, 77), (12, 33), (27, 60))\n",
1431
+ entryPoint: "index_multiplication",
1432
+ id: "Mbpp/445",
1433
+ prompt: "\"\"\"\nWrite a function to perform index wise multiplication of tuple elements in the given two tuples.\nassert index_multiplication(((1, 3), (4, 5), (2, 9), (1, 10)),((6, 7), (3, 9), (1, 1), (7, 3)) ) == ((6, 21), (12, 45), (2, 9), (7, 30))\n\"\"\"\n",
1434
+ solution: "\ndef index_multiplication(test_tup1, test_tup2):\n return tuple(tuple(a * b for a, b in zip(tup1, tup2))\n for tup1, tup2 in zip(test_tup1, test_tup2))\n"
1435
+ },
1436
+ {
1437
+ assertions: "\nassert count_Occurrence(('a', 'a', 'c', 'b', 'd'),['a', 'b'] ) == 3\nassert count_Occurrence((1, 2, 3, 1, 4, 6, 7, 1, 4),[1, 4, 7]) == 6\nassert count_Occurrence((1,2,3,4,5,6),[1,2]) == 2\n",
1438
+ entryPoint: "count_Occurrence",
1439
+ id: "Mbpp/446",
1440
+ prompt: "\"\"\"\nWrite a python function to count the occurence of all elements of list in a tuple.\nassert count_Occurrence(('a', 'a', 'c', 'b', 'd'),['a', 'b'] ) == 3\n\"\"\"\n",
1441
+ solution: "\nfrom collections import Counter \ndef count_Occurrence(tup, lst): \n return sum(tup.count(ele) for ele in lst)\n"
1442
+ },
1443
+ {
1444
+ assertions: "\nassert cube_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]\nassert cube_nums([10,20,30])==([1000, 8000, 27000])\nassert cube_nums([12,15])==([1728, 3375])\n",
1445
+ entryPoint: "cube_nums",
1446
+ id: "Mbpp/447",
1447
+ prompt: "\"\"\"\nWrite a function to find cubes of individual elements in a list.\nassert cube_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]\n\"\"\"\n",
1448
+ solution: "\ndef cube_nums(nums):\n return [n**3 for n in nums]\n"
1449
+ },
1450
+ {
1451
+ assertions: "\nassert cal_sum(9) == 49\nassert cal_sum(10) == 66\nassert cal_sum(11) == 88\n",
1452
+ entryPoint: "cal_sum",
1453
+ id: "Mbpp/448",
1454
+ prompt: "\"\"\"\nWrite a function to calculate the sum of perrin numbers.\nassert cal_sum(9) == 49\n\"\"\"\n",
1455
+ solution: "\ndef cal_sum(n): \n\ta = 3\n\tb = 0\n\tc = 2\n\tif (n == 0): \n\t\treturn 3\n\tif (n == 1): \n\t\treturn 3\n\tif (n == 2): \n\t\treturn 5\n\tsum = 5\n\twhile (n > 2): \n\t\td = a + b \n\t\tsum = sum + d \n\t\ta = b \n\t\tb = c \n\t\tc = d \n\t\tn = n - 1\n\treturn sum\n"
1456
+ },
1457
+ {
1458
+ assertions: "\nassert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,8)==['practice', 'solution']\nassert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,6)==['Python']\nassert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,9)==['exercises']\n",
1459
+ entryPoint: "extract_string",
1460
+ id: "Mbpp/450",
1461
+ prompt: "\"\"\"\nWrite a function to extract specified size of strings from a given list of string values.\nassert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,8)==['practice', 'solution']\n\"\"\"\n",
1462
+ solution: "\ndef extract_string(str1, l):\n return [e for e in str1 if len(e) == l] \n"
1463
+ },
1464
+ {
1465
+ assertions: "\nassert remove_whitespaces(' Google Flutter ') == 'GoogleFlutter'\nassert remove_whitespaces(' Google Dart ') == 'GoogleDart'\nassert remove_whitespaces(' iOS Swift ') == 'iOSSwift'\n",
1466
+ entryPoint: "remove_whitespaces",
1467
+ id: "Mbpp/451",
1468
+ prompt: "\"\"\"\nWrite a function to remove all whitespaces from the given string.\nassert remove_whitespaces(' Google Flutter ') == 'GoogleFlutter'\n\"\"\"\n",
1469
+ solution: "\nimport re\ndef remove_whitespaces(text1):\n return text1.replace(' ', '')\n"
1470
+ },
1471
+ {
1472
+ assertions: "\nassert sumofFactors(18) == 26\nassert sumofFactors(30) == 48\nassert sumofFactors(6) == 8\n",
1473
+ entryPoint: "sumofFactors",
1474
+ id: "Mbpp/453",
1475
+ prompt: "\"\"\"\nWrite a python function to find the sum of even factors of a number.\nassert sumofFactors(18) == 26\n\"\"\"\n",
1476
+ solution: "\nimport math \ndef sumofFactors(n) : \n if (n % 2 != 0) : \n return 0\n return sum([i for i in range(2, n + 1) if n % i == 0 and i % 2 == 0])\n"
1477
+ },
1478
+ {
1479
+ assertions: "\nassert text_match_wordz(\"pythonz.\")==True\nassert text_match_wordz(\"xyz.\")==True\nassert text_match_wordz(\" lang .\")==False\n",
1480
+ entryPoint: "text_match_wordz",
1481
+ id: "Mbpp/454",
1482
+ prompt: "\"\"\"\nWrite a function that matches a word containing 'z'.\nassert text_match_wordz(\"pythonz.\")==True\n\"\"\"\n",
1483
+ solution: "\nimport re\ndef text_match_wordz(text):\n return 'z' in text\n"
1484
+ },
1485
+ {
1486
+ assertions: "\nassert check_monthnumb_number(5)==True\nassert check_monthnumb_number(2)==False\nassert check_monthnumb_number(6)==False\n",
1487
+ entryPoint: "check_monthnumb_number",
1488
+ id: "Mbpp/455",
1489
+ prompt: "\"\"\"\nWrite a function to check whether the given month number contains 31 days or not.\nassert check_monthnumb_number(5)==True\n\"\"\"\n",
1490
+ solution: "\ndef check_monthnumb_number(monthnum2):\n return monthnum2 in [1, 3, 5, 7, 8, 10, 12]\n"
1491
+ },
1492
+ {
1493
+ assertions: "\nassert reverse_string_list(['Red', 'Green', 'Blue', 'White', 'Black'])==['deR', 'neerG', 'eulB', 'etihW', 'kcalB']\nassert reverse_string_list(['john','amal','joel','george'])==['nhoj','lama','leoj','egroeg']\nassert reverse_string_list(['jack','john','mary'])==['kcaj','nhoj','yram']\n",
1494
+ entryPoint: "reverse_string_list",
1495
+ id: "Mbpp/456",
1496
+ prompt: "\"\"\"\nWrite a function to reverse each string in a given list of string values.\nassert reverse_string_list(['Red', 'Green', 'Blue', 'White', 'Black'])==['deR', 'neerG', 'eulB', 'etihW', 'kcalB']\n\"\"\"\n",
1497
+ solution: "\ndef reverse_string_list(stringlist):\n return [x[::-1] for x in stringlist]\n"
1498
+ },
1499
+ {
1500
+ assertions: "\nassert Find_Min([[1],[1,2],[1,2,3]]) == [1]\nassert Find_Min([[1,1],[1,1,1],[1,2,7,8]]) == [1,1]\nassert Find_Min([['x'],['x','y'],['x','y','z']]) == ['x']\n",
1501
+ entryPoint: "Find_Min",
1502
+ id: "Mbpp/457",
1503
+ prompt: "\"\"\"\nWrite a python function to find the sublist having minimum length.\nassert Find_Min([[1],[1,2],[1,2,3]]) == [1]\n\"\"\"\n",
1504
+ solution: "\ndef Find_Min(lst): \n return min(lst, key=len) \n"
1505
+ },
1506
+ {
1507
+ assertions: "\nassert rectangle_area(10,20)==200\nassert rectangle_area(10,5)==50\nassert rectangle_area(4,2)==8\n",
1508
+ entryPoint: "rectangle_area",
1509
+ id: "Mbpp/458",
1510
+ prompt: "\"\"\"\nWrite a function to find the area of a rectangle.\nassert rectangle_area(10,20)==200\n\"\"\"\n",
1511
+ solution: "\ndef rectangle_area(l,b):\n return l * b\n"
1512
+ },
1513
+ {
1514
+ assertions: "\nassert remove_uppercase('cAstyoUrFavoRitETVshoWs') == 'cstyoravoitshos'\nassert remove_uppercase('wAtchTheinTernEtrAdIo') == 'wtchheinerntrdo'\nassert remove_uppercase('VoicESeaRchAndreComMendaTionS') == 'oiceachndreomendaion'\n",
1515
+ entryPoint: "remove_uppercase",
1516
+ id: "Mbpp/459",
1517
+ prompt: "\"\"\"\nWrite a function to remove uppercase substrings from a given string.\nassert remove_uppercase('cAstyoUrFavoRitETVshoWs') == 'cstyoravoitshos'\n\"\"\"\n",
1518
+ solution: "\ndef remove_uppercase(str1):\n return ''.join(c for c in str1 if c.islower())\n"
1519
+ },
1520
+ {
1521
+ assertions: "\nassert Extract([[1, 2], [3, 4, 5], [6, 7, 8, 9]]) == [1, 3, 6]\nassert Extract([[1,2,3],[4, 5]]) == [1,4]\nassert Extract([[9,8,1],[1,2]]) == [9,1]\n",
1522
+ entryPoint: "Extract",
1523
+ id: "Mbpp/460",
1524
+ prompt: "\"\"\"\nWrite a python function to get the first element of each sublist.\nassert Extract([[1, 2], [3, 4, 5], [6, 7, 8, 9]]) == [1, 3, 6]\n\"\"\"\n",
1525
+ solution: "\ndef Extract(lst): \n return [item[0] for item in lst] \n"
1526
+ },
1527
+ {
1528
+ assertions: "\nassert combinations_list(['orange', 'red', 'green', 'blue'])==[[], ['orange'], ['red'], ['red', 'orange'], ['green'], ['green', 'orange'], ['green', 'red'], ['green', 'red', 'orange'], ['blue'], ['blue', 'orange'], ['blue', 'red'], ['blue', 'red', 'orange'], ['blue', 'green'], ['blue', 'green', 'orange'], ['blue', 'green', 'red'], ['blue', 'green', 'red', 'orange']]\nassert combinations_list(['red', 'green', 'blue', 'white', 'black', 'orange'])==[[], ['red'], ['green'], ['green', 'red'], ['blue'], ['blue', 'red'], ['blue', 'green'], ['blue', 'green', 'red'], ['white'], ['white', 'red'], ['white', 'green'], ['white', 'green', 'red'], ['white', 'blue'], ['white', 'blue', 'red'], ['white', 'blue', 'green'], ['white', 'blue', 'green', 'red'], ['black'], ['black', 'red'], ['black', 'green'], ['black', 'green', 'red'], ['black', 'blue'], ['black', 'blue', 'red'], ['black', 'blue', 'green'], ['black', 'blue', 'green', 'red'], ['black', 'white'], ['black', 'white', 'red'], ['black', 'white', 'green'], ['black', 'white', 'green', 'red'], ['black', 'white', 'blue'], ['black', 'white', 'blue', 'red'], ['black', 'white', 'blue', 'green'], ['black', 'white', 'blue', 'green', 'red'], ['orange'], ['orange', 'red'], ['orange', 'green'], ['orange', 'green', 'red'], ['orange', 'blue'], ['orange', 'blue', 'red'], ['orange', 'blue', 'green'], ['orange', 'blue', 'green', 'red'], ['orange', 'white'], ['orange', 'white', 'red'], ['orange', 'white', 'green'], ['orange', 'white', 'green', 'red'], ['orange', 'white', 'blue'], ['orange', 'white', 'blue', 'red'], ['orange', 'white', 'blue', 'green'], ['orange', 'white', 'blue', 'green', 'red'], ['orange', 'black'], ['orange', 'black', 'red'], ['orange', 'black', 'green'], ['orange', 'black', 'green', 'red'], ['orange', 'black', 'blue'], ['orange', 'black', 'blue', 'red'], ['orange', 'black', 'blue', 'green'], ['orange', 'black', 'blue', 'green', 'red'], ['orange', 'black', 'white'], ['orange', 'black', 'white', 'red'], ['orange', 'black', 'white', 'green'], ['orange', 'black', 'white', 'green', 'red'], ['orange', 'black', 'white', 'blue'], ['orange', 'black', 'white', 'blue', 'red'], ['orange', 'black', 'white', 'blue', 'green'], ['orange', 'black', 'white', 'blue', 'green', 'red']]\nassert combinations_list(['red', 'green', 'black', 'orange'])==[[], ['red'], ['green'], ['green', 'red'], ['black'], ['black', 'red'], ['black', 'green'], ['black', 'green', 'red'], ['orange'], ['orange', 'red'], ['orange', 'green'], ['orange', 'green', 'red'], ['orange', 'black'], ['orange', 'black', 'red'], ['orange', 'black', 'green'], ['orange', 'black', 'green', 'red']]\n",
1529
+ entryPoint: "combinations_list",
1530
+ id: "Mbpp/462",
1531
+ prompt: "\"\"\"\nWrite a function to find all possible combinations of the elements of a given list.\nassert combinations_list(['orange', 'red', 'green', 'blue'])==[[], ['orange'], ['red'], ['red', 'orange'], ['green'], ['green', 'orange'], ['green', 'red'], ['green', 'red', 'orange'], ['blue'], ['blue', 'orange'], ['blue', 'red'], ['blue', 'red', 'orange'], ['blue', 'green'], ['blue', 'green', 'orange'], ['blue', 'green', 'red'], ['blue', 'green', 'red', 'orange']]\n\"\"\"\n",
1532
+ solution: "\ndef combinations_list(list1):\n if len(list1) == 0:\n return [[]]\n result = []\n for el in combinations_list(list1[1:]):\n result += [el, el+[list1[0]]]\n return result\n"
1533
+ },
1534
+ {
1535
+ assertions: "\nassert max_subarray_product([1, -2, -3, 0, 7, -8, -2]) == 112\nassert max_subarray_product([6, -3, -10, 0, 2]) == 180\nassert max_subarray_product([-2, -40, 0, -2, -3]) == 80\n",
1536
+ entryPoint: "max_subarray_product",
1537
+ id: "Mbpp/463",
1538
+ prompt: "\"\"\"\nWrite a function to find the maximum product subarray of the given array.\nassert max_subarray_product([1, -2, -3, 0, 7, -8, -2]) == 112\n\"\"\"\n",
1539
+ solution: "\ndef max_subarray_product(arr):\n\tmax_so_far = min_ending = max_ending = arr[0]\n\tfor n in arr[1:]:\n\t\tmin_ending, max_ending = min(n, min_ending * n, max_ending * n), max(n, min_ending * n, max_ending * n)\n\t\tmax_so_far = max(max_so_far, max_ending)\n\treturn max_so_far\n"
1540
+ },
1541
+ {
1542
+ assertions: "\nassert drop_empty({'c1': 'Red', 'c2': 'Green', 'c3':None})=={'c1': 'Red', 'c2': 'Green'}\nassert drop_empty({'c1': 'Red', 'c2': None, 'c3':None})=={'c1': 'Red'}\nassert drop_empty({'c1': None, 'c2': 'Green', 'c3':None})=={ 'c2': 'Green'}\n",
1543
+ entryPoint: "drop_empty",
1544
+ id: "Mbpp/465",
1545
+ prompt: "\"\"\"\nWrite a function to drop empty items from a given dictionary.\nassert drop_empty({'c1': 'Red', 'c2': 'Green', 'c3':None})=={'c1': 'Red', 'c2': 'Green'}\n\"\"\"\n",
1546
+ solution: "\ndef drop_empty(dict1):\n dict1 = {key:value for (key, value) in dict1.items() if value is not None}\n return dict1\n"
1547
+ },
1548
+ {
1549
+ assertions: "\nassert max_product([3, 100, 4, 5, 150, 6]) == 3000\nassert max_product([4, 42, 55, 68, 80]) == 50265600\nassert max_product([10, 22, 9, 33, 21, 50, 41, 60]) == 2460\n",
1550
+ entryPoint: "max_product",
1551
+ id: "Mbpp/468",
1552
+ prompt: "\"\"\"\nWrite a function to find the maximum product formed by multiplying numbers of an increasing subsequence of that array.\nassert max_product([3, 100, 4, 5, 150, 6]) == 3000\n\"\"\"\n",
1553
+ solution: "\ndef max_product(arr): \n # record the correspond ending element to maintain the increasing subsequence\n ret = max_ending = min_ending = (arr[0], arr[0])\n for n in arr[1:]:\n if n > max_ending[1]:\n max_ending = max((max_ending[0] * n, n), max_ending, key=lambda x: x[0])\n else:\n max_ending = (n, n)\n if n > min_ending[1]:\n min_ending = min((min_ending[0] * n, n), min_ending, key=lambda x: x[0])\n else:\n min_ending = (n, n)\n ret = max(ret, max_ending, min_ending, key=lambda x: x[0])\n return ret[0]\n"
1554
+ },
1555
+ {
1556
+ assertions: "\nassert add_pairwise((1, 5, 7, 8, 10)) == (6, 12, 15, 18)\nassert add_pairwise((2, 6, 8, 9, 11)) == (8, 14, 17, 20)\nassert add_pairwise((3, 7, 9, 10, 12)) == (10, 16, 19, 22)\n",
1557
+ entryPoint: "add_pairwise",
1558
+ id: "Mbpp/470",
1559
+ prompt: "\"\"\"\nWrite a function to find the pairwise addition of the neighboring elements of the given tuple.\nassert add_pairwise((1, 5, 7, 8, 10)) == (6, 12, 15, 18)\n\"\"\"\n",
1560
+ solution: "\ndef add_pairwise(test_tup):\n return tuple(a + b for a, b in zip(test_tup, test_tup[1:]))\n"
1561
+ },
1562
+ {
1563
+ assertions: "\nassert find_remainder([ 100, 10, 5, 25, 35, 14 ],11) ==9\nassert find_remainder([1,1,1],1) == 0\nassert find_remainder([1,2,1],2) == 0\n",
1564
+ entryPoint: "find_remainder",
1565
+ id: "Mbpp/471",
1566
+ prompt: "\"\"\"\nWrite a python function to find the product of the array multiplication modulo n.\nassert find_remainder([ 100, 10, 5, 25, 35, 14 ],11) ==9\n\"\"\"\n",
1567
+ solution: "\ndef find_remainder(arr, n): \n from functools import reduce\n return reduce(lambda x, y: x * y, arr) % n\n"
1568
+ },
1569
+ {
1570
+ assertions: "\nassert check_Consecutive([1,2,3,4,5]) == True\nassert check_Consecutive([1,2,3,5,6]) == False\nassert check_Consecutive([1,2,1]) == False\n",
1571
+ entryPoint: "check_Consecutive",
1572
+ id: "Mbpp/472",
1573
+ prompt: "\"\"\"\nWrite a python function to check whether the given list contains consecutive numbers or not.\nassert check_Consecutive([1,2,3,4,5]) == True\n\"\"\"\n",
1574
+ solution: "\ndef check_Consecutive(l): \n return sorted(l) == list(range(min(l),max(l)+1)) \n"
1575
+ },
1576
+ {
1577
+ assertions: "\nassert tuple_intersection([(3, 4), (5, 6), (9, 10), (4, 5)] , [(5, 4), (3, 4), (6, 5), (9, 11)]) == {(4, 5), (3, 4), (5, 6)}\nassert tuple_intersection([(4, 1), (7, 4), (11, 13), (17, 14)] , [(1, 4), (7, 4), (16, 12), (10, 13)]) == {(4, 7), (1, 4)}\nassert tuple_intersection([(2, 1), (3, 2), (1, 3), (1, 4)] , [(11, 2), (2, 3), (6, 2), (1, 3)]) == {(1, 3), (2, 3)}\n",
1578
+ entryPoint: "tuple_intersection",
1579
+ id: "Mbpp/473",
1580
+ prompt: "\"\"\"\nWrite a function to find the tuple intersection of elements in the given tuple list irrespective of their order.\nassert tuple_intersection([(3, 4), (5, 6), (9, 10), (4, 5)] , [(5, 4), (3, 4), (6, 5), (9, 11)]) == {(4, 5), (3, 4), (5, 6)}\n\"\"\"\n",
1581
+ solution: "\ndef tuple_intersection(test_list1, test_list2):\n return set([tuple(sorted(ele)) for ele in test_list1]) & set([tuple(sorted(ele)) for ele in test_list2])\n"
1582
+ },
1583
+ {
1584
+ assertions: "\nassert replace_char(\"polygon\",'y','l')==(\"pollgon\")\nassert replace_char(\"character\",'c','a')==(\"aharaater\")\nassert replace_char(\"python\",'l','a')==(\"python\")\n",
1585
+ entryPoint: "replace_char",
1586
+ id: "Mbpp/474",
1587
+ prompt: "\"\"\"\nWrite a function to replace characters in a string.\nassert replace_char(\"polygon\",'y','l')==(\"pollgon\")\n\"\"\"\n",
1588
+ solution: "\ndef replace_char(str1, ch, newch):\n return str1.replace(ch, newch)\n"
1589
+ },
1590
+ {
1591
+ assertions: "\nassert sort_counter({'Math':81, 'Physics':83, 'Chemistry':87})==[('Chemistry', 87), ('Physics', 83), ('Math', 81)]\nassert sort_counter({'Math':400, 'Physics':300, 'Chemistry':250})==[('Math', 400), ('Physics', 300), ('Chemistry', 250)]\nassert sort_counter({'Math':900, 'Physics':1000, 'Chemistry':1250})==[('Chemistry', 1250), ('Physics', 1000), ('Math', 900)]\n",
1592
+ entryPoint: "sort_counter",
1593
+ id: "Mbpp/475",
1594
+ prompt: "\"\"\"\nWrite a function to sort a dictionary by value.\nassert sort_counter({'Math':81, 'Physics':83, 'Chemistry':87})==[('Chemistry', 87), ('Physics', 83), ('Math', 81)]\n\"\"\"\n",
1595
+ solution: "\ndef sort_counter(dict1):\n return sorted(dict1.items(), key=lambda x: x[1], reverse=True)\n"
1596
+ },
1597
+ {
1598
+ assertions: "\nassert big_sum([1,2,3]) == 4\nassert big_sum([-1,2,3,4]) == 3\nassert big_sum([2,3,6]) == 8\n",
1599
+ entryPoint: "big_sum",
1600
+ id: "Mbpp/476",
1601
+ prompt: "\"\"\"\nWrite a python function to find the sum of the largest and smallest value in a given array.\nassert big_sum([1,2,3]) == 4\n\"\"\"\n",
1602
+ solution: "\ndef big_sum(nums):\n return max(nums) + min(nums)\n"
1603
+ },
1604
+ {
1605
+ assertions: "\nassert is_lower(\"InValid\") == \"invalid\"\nassert is_lower(\"TruE\") == \"true\"\nassert is_lower(\"SenTenCE\") == \"sentence\"\n",
1606
+ entryPoint: "is_lower",
1607
+ id: "Mbpp/477",
1608
+ prompt: "\"\"\"\nWrite a python function to convert the given string to lower case.\nassert is_lower(\"InValid\") == \"invalid\"\n\"\"\"\n",
1609
+ solution: "\ndef is_lower(string):\n return string.lower()\n"
1610
+ },
1611
+ {
1612
+ assertions: "\nassert remove_lowercase(\"PYTHon\")==('PYTH')\nassert remove_lowercase(\"FInD\")==('FID')\nassert remove_lowercase(\"STRinG\")==('STRG')\n",
1613
+ entryPoint: "remove_lowercase",
1614
+ id: "Mbpp/478",
1615
+ prompt: "\"\"\"\nWrite a function to remove lowercase substrings from a given string.\nassert remove_lowercase(\"PYTHon\")==('PYTH')\n\"\"\"\n",
1616
+ solution: "\nimport re\ndef remove_lowercase(str1):\n return re.sub('[a-z]', '', str1)\n"
1617
+ },
1618
+ {
1619
+ assertions: "\nassert first_Digit(123) == 1\nassert first_Digit(456) == 4\nassert first_Digit(12) == 1\n",
1620
+ entryPoint: "first_Digit",
1621
+ id: "Mbpp/479",
1622
+ prompt: "\"\"\"\nWrite a python function to find the first digit of a given number.\nassert first_Digit(123) == 1\n\"\"\"\n",
1623
+ solution: "\ndef first_Digit(n) : \n return int(str(n)[0])\n"
1624
+ },
1625
+ {
1626
+ assertions: "\nassert Split([1,2,3,4,5,6]) == [1,3,5]\nassert Split([10,11,12,13]) == [11,13]\nassert Split([7,8,9,1]) == [7,9,1]\n",
1627
+ entryPoint: "Split",
1628
+ id: "Mbpp/554",
1629
+ prompt: "\"\"\"\nWrite a python function which takes a list of integers and only returns the odd ones.\nassert Split([1,2,3,4,5,6]) == [1,3,5]\n\"\"\"\n",
1630
+ solution: "\ndef Split(l): \n return list(filter(lambda x: x % 2 == 1, l))\n"
1631
+ },
1632
+ {
1633
+ assertions: "\nassert difference(3) == 30\nassert difference(5) == 210\nassert difference(2) == 6\n",
1634
+ entryPoint: "difference",
1635
+ id: "Mbpp/555",
1636
+ prompt: "\"\"\"\nWrite a python function to find the difference between the sum of cubes of the first n natural numbers and the sum of the first n natural numbers.\nassert difference(3) == 30\n\"\"\"\n",
1637
+ solution: "\ndef difference(n) : \n S = (n*(n + 1))//2; \n res = S*(S-1); \n return res; \n"
1638
+ },
1639
+ {
1640
+ assertions: "\nassert find_Odd_Pair([5,4,7,2,1],5) == 6\nassert find_Odd_Pair([7,2,8,1,0,5,11],7) == 12\nassert find_Odd_Pair([1,2,3],3) == 2\n",
1641
+ entryPoint: "find_Odd_Pair",
1642
+ id: "Mbpp/556",
1643
+ prompt: "\"\"\"\nWrite a python function to count the number of pairs whose xor value is odd.\nassert find_Odd_Pair([5,4,7,2,1],5) == 6\n\"\"\"\n",
1644
+ solution: "\ndef find_Odd_Pair(A,N) : \n oddPair = 0\n for i in range(0,N) : \n for j in range(i+1,N) : \n if ((A[i] ^ A[j]) % 2 != 0): \n oddPair+=1 \n return oddPair \n"
1645
+ },
1646
+ {
1647
+ assertions: "\nassert toggle_string(\"Python\")==(\"pYTHON\")\nassert toggle_string(\"Pangram\")==(\"pANGRAM\")\nassert toggle_string(\"LIttLE\")==(\"liTTle\")\n",
1648
+ entryPoint: "toggle_string",
1649
+ id: "Mbpp/557",
1650
+ prompt: "\"\"\"\nWrite a function to toggle the case of all characters in a string.\nassert toggle_string(\"Python\")==(\"pYTHON\")\n\"\"\"\n",
1651
+ solution: "\ndef toggle_string(string):\n return string.swapcase()\n"
1652
+ },
1653
+ {
1654
+ assertions: "\nassert digit_distance_nums(1,2) == 1\nassert digit_distance_nums(23,56) == 6\nassert digit_distance_nums(123,256) == 7\n",
1655
+ entryPoint: "digit_distance_nums",
1656
+ id: "Mbpp/558",
1657
+ prompt: "\"\"\"\nWrite a python function to find the sum of the per-digit difference between two integers.\nassert digit_distance_nums(1,2) == 1\n\"\"\"\n",
1658
+ solution: "\ndef digit_distance_nums(n1, n2):\n return sum([abs(int(c1) - int(c2)) for c1, c2 in zip(str(n1), str(n2))])\n"
1659
+ },
1660
+ {
1661
+ assertions: "\nassert max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3], 8) == 7\nassert max_sub_array_sum([-3, -4, 5, -2, -3, 2, 6, -4], 8) == 8\nassert max_sub_array_sum([-4, -5, 6, -3, -4, 3, 7, -5], 8) == 10\n",
1662
+ entryPoint: "max_sub_array_sum",
1663
+ id: "Mbpp/559",
1664
+ prompt: "\"\"\"\nWrite a function to find the sum of the largest contiguous sublist in the given list.\nassert max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3], 8) == 7\n\"\"\"\n",
1665
+ solution: "\ndef max_sub_array_sum(a, size):\n max_so_far = 0\n max_ending_here = 0\n for i in range(0, size):\n max_ending_here = max_ending_here + a[i]\n if max_ending_here < 0:\n max_ending_here = 0\n elif (max_so_far < max_ending_here):\n max_so_far = max_ending_here\n return max_so_far\n"
1666
+ },
1667
+ {
1668
+ assertions: "\nassert union_elements((3, 4, 5, 6),(5, 7, 4, 10) ) == (3, 4, 5, 6, 7, 10)\nassert union_elements((1, 2, 3, 4),(3, 4, 5, 6) ) == (1, 2, 3, 4, 5, 6)\nassert union_elements((11, 12, 13, 14),(13, 15, 16, 17) ) == (11, 12, 13, 14, 15, 16, 17)\n",
1669
+ entryPoint: "union_elements",
1670
+ id: "Mbpp/560",
1671
+ prompt: "\"\"\"\nWrite a function to find the union of the elements of two given tuples and output them in sorted order.\nassert union_elements((3, 4, 5, 6),(5, 7, 4, 10) ) == (3, 4, 5, 6, 7, 10)\n\"\"\"\n",
1672
+ solution: "\ndef union_elements(test_tup1, test_tup2):\n return tuple(sorted(set(test_tup1 + test_tup2)))\n"
1673
+ },
1674
+ {
1675
+ assertions: "\nassert Find_Max_Length([[1],[1,4],[5,6,7,8]]) == 4\nassert Find_Max_Length([[0,1],[2,2,],[3,2,1]]) == 3\nassert Find_Max_Length([[7],[22,23],[13,14,15],[10,20,30,40,50]]) == 5\n",
1676
+ entryPoint: "Find_Max_Length",
1677
+ id: "Mbpp/562",
1678
+ prompt: "\"\"\"\nWrite a python function to find the length of the longest sublists.\nassert Find_Max_Length([[1],[1,4],[5,6,7,8]]) == 4\n\"\"\"\n",
1679
+ solution: "\ndef Find_Max_Length(lst): \n return len(max(lst, key = len))\n"
1680
+ },
1681
+ {
1682
+ assertions: "\nassert extract_values('\"Python\", \"PHP\", \"Java\"')==['Python', 'PHP', 'Java']\nassert extract_values('\"python\",\"program\",\"language\"')==['python','program','language']\nassert extract_values('\"red\",\"blue\",\"green\",\"yellow\"')==['red','blue','green','yellow']\n",
1683
+ entryPoint: "extract_values",
1684
+ id: "Mbpp/563",
1685
+ prompt: "\"\"\"\nWrite a function to extract values between quotation marks from a string.\nassert extract_values('\"Python\", \"PHP\", \"Java\"')==['Python', 'PHP', 'Java']\n\"\"\"\n",
1686
+ solution: "\nimport re\ndef extract_values(text):\n return (re.findall(r'\"(.*?)\"', text))\n"
1687
+ },
1688
+ {
1689
+ assertions: "\nassert count_Pairs([1,2,1],3) == 2\nassert count_Pairs([1,1,1,1],4) == 0\nassert count_Pairs([1,2,3,4,5],5) == 10\n",
1690
+ entryPoint: "count_Pairs",
1691
+ id: "Mbpp/564",
1692
+ prompt: "\"\"\"\nWrite a python function which takes a list of integers and counts the number of possible unordered pairs where both elements are unequal.\nassert count_Pairs([1,2,1],3) == 2\n\"\"\"\n",
1693
+ solution: "\ndef count_Pairs(arr,n): \n cnt = 0; \n for i in range(n): \n for j in range(i + 1,n): \n if (arr[i] != arr[j]): \n cnt += 1; \n return cnt; \n"
1694
+ },
1695
+ {
1696
+ assertions: "\nassert split('python') == ['p','y','t','h','o','n']\nassert split('Name') == ['N','a','m','e']\nassert split('program') == ['p','r','o','g','r','a','m']\n",
1697
+ entryPoint: "split",
1698
+ id: "Mbpp/565",
1699
+ prompt: "\"\"\"\nWrite a python function to split a string into characters.\nassert split('python') == ['p','y','t','h','o','n']\n\"\"\"\n",
1700
+ solution: "\ndef split(word): \n return list(word)\n"
1701
+ },
1702
+ {
1703
+ assertions: "\nassert sum_digits(345)==12\nassert sum_digits(12)==3\nassert sum_digits(97)==16\n",
1704
+ entryPoint: "sum_digits",
1705
+ id: "Mbpp/566",
1706
+ prompt: "\"\"\"\nWrite a function to get the sum of the digits of a non-negative integer.\nassert sum_digits(345)==12\n\"\"\"\n",
1707
+ solution: "\ndef sum_digits(n):\n return sum(map(int, str(n)))\n"
1708
+ },
1709
+ {
1710
+ assertions: "\nassert issort_list([1,2,4,6,8,10,12,14,16,17])==True\nassert issort_list([1, 2, 4, 6, 8, 10, 12, 14, 20, 17])==False\nassert issort_list([1, 2, 4, 6, 8, 10,15,14,20])==False\n",
1711
+ entryPoint: "issort_list",
1712
+ id: "Mbpp/567",
1713
+ prompt: "\"\"\"\nWrite a function to check whether a specified list is sorted or not.\nassert issort_list([1,2,4,6,8,10,12,14,16,17])==True\n\"\"\"\n",
1714
+ solution: "\ndef issort_list(list1):\n return all(a <= b for a, b in zip(list1, list1[1:]))\n"
1715
+ },
1716
+ {
1717
+ assertions: "\nassert empty_list(5)==[{},{},{},{},{}]\nassert empty_list(6)==[{},{},{},{},{},{}]\nassert empty_list(7)==[{},{},{},{},{},{},{}]\n",
1718
+ entryPoint: "empty_list",
1719
+ id: "Mbpp/568",
1720
+ prompt: "\"\"\"\nWrite a function to create a list of N empty dictionaries.\nassert empty_list(5)==[{},{},{},{},{}]\n\"\"\"\n",
1721
+ solution: "\ndef empty_list(length):\n return [{} for _ in range(length)]\n"
1722
+ },
1723
+ {
1724
+ assertions: "\nassert sort_sublists([['green', 'orange'], ['black', 'white'], ['white', 'black', 'orange']])==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]\nassert sort_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']])==[['green', 'orange'], ['black'], ['green', 'orange'], ['white']]\nassert sort_sublists([['a','b'],['d','c'],['g','h'] , ['f','e']])==[['a', 'b'], ['c', 'd'], ['g', 'h'], ['e', 'f']]\n",
1725
+ entryPoint: "sort_sublists",
1726
+ id: "Mbpp/569",
1727
+ prompt: "\"\"\"\nWrite a function to sort each sublist of strings in a given list of lists.\nassert sort_sublists([['green', 'orange'], ['black', 'white'], ['white', 'black', 'orange']])==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]\n\"\"\"\n",
1728
+ solution: "\ndef sort_sublists(list1):\n return list(map(sorted,list1)) \n"
1729
+ },
1730
+ {
1731
+ assertions: "\nassert two_unique_nums([1,2,3,2,3,4,5]) == [1, 4, 5]\nassert two_unique_nums([1,2,3,2,4,5]) == [1, 3, 4, 5]\nassert two_unique_nums([1,2,3,4,5]) == [1, 2, 3, 4, 5]\n",
1732
+ entryPoint: "two_unique_nums",
1733
+ id: "Mbpp/572",
1734
+ prompt: "\"\"\"\nWrite a python function to remove duplicate numbers from a given number of lists.\nassert two_unique_nums([1,2,3,2,3,4,5]) == [1, 4, 5]\n\"\"\"\n",
1735
+ solution: "\ndef two_unique_nums(nums):\n return [n for n in nums if nums.count(n)==1]\n"
1736
+ },
1737
+ {
1738
+ assertions: "\nassert unique_product([10, 20, 30, 40, 20, 50, 60, 40]) == 720000000\nassert unique_product([1, 2, 3, 1,]) == 6\nassert unique_product([7, 8, 9, 0, 1, 1]) == 0\n",
1739
+ entryPoint: "unique_product",
1740
+ id: "Mbpp/573",
1741
+ prompt: "\"\"\"\nWrite a python function to calculate the product of the unique numbers in a given list.\nassert unique_product([10, 20, 30, 40, 20, 50, 60, 40]) == 720000000\n\"\"\"\n",
1742
+ solution: "\ndef unique_product(list_data):\n from functools import reduce\n return reduce(lambda x, y: x*y, set(list_data))\n"
1743
+ },
1744
+ {
1745
+ assertions: "\nassert is_Sub_Array([1,4,3,5],[1,2]) == False\nassert is_Sub_Array([1,2,1],[1,2,1]) == True\nassert is_Sub_Array([1,0,2,2],[2,2,0]) ==False\n",
1746
+ entryPoint: "is_Sub_Array",
1747
+ id: "Mbpp/576",
1748
+ prompt: "\"\"\"\nWrite a python function to check whether a list is sublist of another or not.\nassert is_Sub_Array([1,4,3,5],[1,2]) == False\n\"\"\"\n",
1749
+ solution: "\ndef is_Sub_Array(A,B): \n a = 0\n b = 0\n while a < len(A) and b < len(B):\n if A[a] == B[b]:\n a += 1\n b += 1\n else:\n a += 1\n return b == len(B)\n"
1750
+ },
1751
+ {
1752
+ assertions: "\nassert last_Digit_Factorial(4) == 4\nassert last_Digit_Factorial(21) == 0\nassert last_Digit_Factorial(30) == 0\n",
1753
+ entryPoint: "last_Digit_Factorial",
1754
+ id: "Mbpp/577",
1755
+ prompt: "\"\"\"\nWrite a python function to find the last digit in factorial of a given number.\nassert last_Digit_Factorial(4) == 4\n\"\"\"\n",
1756
+ solution: "\ndef last_Digit_Factorial(n): \n if (n == 0): \n return 1\n elif (n <= 2): \n return n \n elif (n == 3): \n return 6\n elif (n == 4): \n return 4 \n else: \n return 0\n"
1757
+ },
1758
+ {
1759
+ assertions: "\nassert interleave_lists([1,2,3,4,5,6,7],[10,20,30,40,50,60,70],[100,200,300,400,500,600,700])==[1, 10, 100, 2, 20, 200, 3, 30, 300, 4, 40, 400, 5, 50, 500, 6, 60, 600, 7, 70, 700]\nassert interleave_lists([10,20],[15,2],[5,10])==[10,15,5,20,2,10]\nassert interleave_lists([11,44], [10,15], [20,5])==[11,10,20,44,15,5]\n",
1760
+ entryPoint: "interleave_lists",
1761
+ id: "Mbpp/578",
1762
+ prompt: "\"\"\"\nWrite a function to interleave 3 lists of the same length into a single flat list.\nassert interleave_lists([1,2,3,4,5,6,7],[10,20,30,40,50,60,70],[100,200,300,400,500,600,700])==[1, 10, 100, 2, 20, 200, 3, 30, 300, 4, 40, 400, 5, 50, 500, 6, 60, 600, 7, 70, 700]\n\"\"\"\n",
1763
+ solution: "\ndef interleave_lists(list1, list2, list3):\n return [el for pair in zip(list1, list2, list3) for el in pair]\n"
1764
+ },
1765
+ {
1766
+ assertions: "\nassert find_dissimilar((3, 4, 5, 6), (5, 7, 4, 10)) == (3, 6, 7, 10)\nassert find_dissimilar((1, 2, 3, 4), (7, 2, 3, 9)) == (1, 4, 7, 9)\nassert find_dissimilar((21, 11, 25, 26), (26, 34, 21, 36)) == (34, 36, 11, 25)\n",
1767
+ entryPoint: "find_dissimilar",
1768
+ id: "Mbpp/579",
1769
+ prompt: "\"\"\"\nWrite a function to find the dissimilar elements in the given two tuples.\nassert find_dissimilar((3, 4, 5, 6), (5, 7, 4, 10)) == (3, 6, 7, 10)\n\"\"\"\n",
1770
+ solution: "\ndef find_dissimilar(test_tup1, test_tup2):\n return tuple(set(test_tup1) ^ set(test_tup2))\n"
1771
+ },
1772
+ {
1773
+ assertions: "\nassert extract_even((4, 5, (7, 6, (2, 4)), 6, 8)) == (4, (6, (2, 4)), 6, 8)\nassert extract_even((5, 6, (8, 7, (4, 8)), 7, 9)) == (6, (8, (4, 8)))\nassert extract_even((5, 6, (9, 8, (4, 6)), 8, 10)) == (6, (8, (4, 6)), 8, 10)\n",
1774
+ entryPoint: "extract_even",
1775
+ id: "Mbpp/580",
1776
+ prompt: "\"\"\"\nWrite a function to remove uneven elements in the nested mixed tuple.\nassert extract_even((4, 5, (7, 6, (2, 4)), 6, 8)) == (4, (6, (2, 4)), 6, 8)\n\"\"\"\n",
1777
+ solution: "\ndef even_ele(test_tuple, ): \n\tres = tuple() \n\tfor ele in test_tuple: \n\t\tif isinstance(ele, tuple): \n\t\t\tres += (even_ele(ele), ) \n\t\telif ele % 2 == 0: \n\t\t\tres += (ele, ) \n\treturn res \ndef extract_even(test_tuple):\n\treturn even_ele(test_tuple)\n"
1778
+ },
1779
+ {
1780
+ assertions: "\nassert surface_Area(3,4) == 33\nassert surface_Area(4,5) == 56\nassert surface_Area(1,2) == 5\n",
1781
+ entryPoint: "surface_Area",
1782
+ id: "Mbpp/581",
1783
+ prompt: "\"\"\"\nWrite a python function to find the surface area of a square pyramid with a given base edge and height.\nassert surface_Area(3,4) == 33\n\"\"\"\n",
1784
+ solution: "\ndef surface_Area(b,s): \n return 2 * b * s + pow(b,2) \n"
1785
+ },
1786
+ {
1787
+ assertions: "\nassert catalan_number(10)==16796\nassert catalan_number(9)==4862\nassert catalan_number(7)==429\n",
1788
+ entryPoint: "catalan_number",
1789
+ id: "Mbpp/583",
1790
+ prompt: "\"\"\"\nWrite a function which returns nth catalan number.\nassert catalan_number(10)==16796\n\"\"\"\n",
1791
+ solution: "\ndef catalan_number(num):\n if num <= 1:\n return 1 \n res_num = 0\n for i in range(num):\n res_num += catalan_number(i) * catalan_number(num - i - 1)\n return res_num\n"
1792
+ },
1793
+ {
1794
+ assertions: "\nassert expensive_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],1)==[{'name': 'Item-2', 'price': 555.22}]\nassert expensive_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}, {'name': 'Item-3', 'price': 45.09}],2)==[{'name': 'Item-2', 'price': 555.22},{'name': 'Item-1', 'price': 101.1}]\nassert expensive_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}, {'name': 'Item-3', 'price': 45.09},{'name': 'Item-4', 'price': 22.75}],1)==[{'name': 'Item-2', 'price': 555.22}]\n",
1795
+ entryPoint: "expensive_items",
1796
+ id: "Mbpp/585",
1797
+ prompt: "\"\"\"\nWrite a function to find the n most expensive items in a given dataset.\nassert expensive_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],1)==[{'name': 'Item-2', 'price': 555.22}]\n\"\"\"\n",
1798
+ solution: "\nimport heapq\ndef expensive_items(items,n):\n expensive_items = heapq.nlargest(n, items, key=lambda s: s['price'])\n return expensive_items\n"
1799
+ },
1800
+ {
1801
+ assertions: "\nassert split_Arr([12,10,5,6,52,36],2) == [5,6,52,36,12,10]\nassert split_Arr([1,2,3,4],1) == [2,3,4,1]\nassert split_Arr([0,1,2,3,4,5,6,7],3) == [3,4,5,6,7,0,1,2]\n",
1802
+ entryPoint: "split_Arr",
1803
+ id: "Mbpp/586",
1804
+ prompt: "\"\"\"\nWrite a python function to split a list at the nth eelment and add the first part to the end.\nassert split_Arr([12,10,5,6,52,36],2) == [5,6,52,36,12,10]\n\"\"\"\n",
1805
+ solution: "\ndef split_Arr(l, n):\n return l[n:] + l[:n]\n"
1806
+ },
1807
+ {
1808
+ assertions: "\nassert list_tuple([5, 10, 7, 4, 15, 3])==(5, 10, 7, 4, 15, 3)\nassert list_tuple([2, 4, 5, 6, 2, 3, 4, 4, 7])==(2, 4, 5, 6, 2, 3, 4, 4, 7)\nassert list_tuple([58,44,56])==(58,44,56)\n",
1809
+ entryPoint: "list_tuple",
1810
+ id: "Mbpp/587",
1811
+ prompt: "\"\"\"\nWrite a function to convert a list to a tuple.\nassert list_tuple([5, 10, 7, 4, 15, 3])==(5, 10, 7, 4, 15, 3)\n\"\"\"\n",
1812
+ solution: "\ndef list_tuple(listx):\n return tuple(listx)\n"
1813
+ },
1814
+ {
1815
+ assertions: "\nassert big_diff([1,2,3,4]) == 3\nassert big_diff([4,5,12]) == 8\nassert big_diff([9,2,3]) == 7\n",
1816
+ entryPoint: "big_diff",
1817
+ id: "Mbpp/588",
1818
+ prompt: "\"\"\"\nWrite a python function to find the difference between largest and smallest value in a given list.\nassert big_diff([1,2,3,4]) == 3\n\"\"\"\n",
1819
+ solution: "\ndef big_diff(nums):\n return max(nums) - min(nums)\n"
1820
+ },
1821
+ {
1822
+ assertions: "\nassert perfect_squares(1,30)==[1, 4, 9, 16, 25]\nassert perfect_squares(50,100)==[64, 81, 100]\nassert perfect_squares(100,200)==[100, 121, 144, 169, 196]\n",
1823
+ entryPoint: "perfect_squares",
1824
+ id: "Mbpp/589",
1825
+ prompt: "\"\"\"\nWrite a function to find perfect squares between two given numbers.\nassert perfect_squares(1,30)==[1, 4, 9, 16, 25]\n\"\"\"\n",
1826
+ solution: "\nimport math\ndef perfect_squares(a, b):\n if a > b:\n a, b = b, a\n if b < 0:\n return []\n if a < 0:\n a = 0\n return list(filter(lambda x: math.sqrt(x).is_integer(), range(a, b+1)))\n"
1827
+ },
1828
+ {
1829
+ assertions: "\nassert polar_rect(3, 4)==((5.0, 0.9272952180016122), (-2+2.4492935982947064e-16j))\nassert polar_rect(4, 7)==((8.06225774829855, 1.0516502125483738), (-2+2.4492935982947064e-16j))\nassert polar_rect(15, 17)==((22.67156809750927, 0.8478169733934057), (-2+2.4492935982947064e-16j))\n",
1830
+ entryPoint: "polar_rect",
1831
+ id: "Mbpp/590",
1832
+ prompt: "\"\"\"\nWrite a function to convert polar coordinates to rectangular coordinates.\nassert polar_rect(3,4)==((5.0, 0.9272952180016122), (-2+2.4492935982947064e-16j))\n\"\"\"\n",
1833
+ solution: "\nimport cmath\ndef polar_rect(x,y):\n cn = cmath.polar(complex(x, y))\n cn1 = cmath.rect(2, cmath.pi)\n return (cn, cn1)\n"
1834
+ },
1835
+ {
1836
+ assertions: "\nassert swap_List([12, 35, 9, 56, 24]) == [24, 35, 9, 56, 12]\nassert swap_List([1, 2, 3]) == [3, 2, 1]\nassert swap_List([4, 5, 6]) == [6, 5, 4]\n",
1837
+ entryPoint: "swap_List",
1838
+ id: "Mbpp/591",
1839
+ prompt: "\"\"\"\nWrite a python function to interchange the first and last elements in a list.\nassert swap_List([12, 35, 9, 56, 24]) == [24, 35, 9, 56, 12]\n\"\"\"\n",
1840
+ solution: "\ndef swap_List(newList): \n return newList[-1:] + newList[1:-1] + newList[:1]\n"
1841
+ },
1842
+ {
1843
+ assertions: "\nassert sum_Of_product(3) == 15\nassert sum_Of_product(4) == 56\nassert sum_Of_product(1) == 1\n",
1844
+ entryPoint: "sum_Of_product",
1845
+ id: "Mbpp/592",
1846
+ prompt: "\"\"\"\nWrite a python function to find the sum of the product of consecutive binomial co-efficients.\nassert sum_Of_product(3) == 15\n\"\"\"\n",
1847
+ solution: "\ndef binomial_Coeff(n, k): \n C = [0] * (k + 1); \n C[0] = 1; # nC0 is 1 \n for i in range(1,n + 1): \n for j in range(min(i, k),0,-1): \n C[j] = C[j] + C[j - 1]; \n return C[k]; \ndef sum_Of_product(n): \n return binomial_Coeff(2 * n, n - 1); \n"
1848
+ },
1849
+ {
1850
+ assertions: "\nassert removezero_ip(\"216.08.094.196\")==('216.8.94.196')\nassert removezero_ip(\"12.01.024\")==('12.1.24')\nassert removezero_ip(\"216.08.094.0196\")==('216.8.94.196')\n",
1851
+ entryPoint: "removezero_ip",
1852
+ id: "Mbpp/593",
1853
+ prompt: "\"\"\"\nWrite a function to remove leading zeroes from an ip address.\nassert removezero_ip(\"216.08.094.196\")==('216.8.94.196')\n\"\"\"\n",
1854
+ solution: "\nimport re\ndef removezero_ip(ip):\n return re.sub('\\.[0]*', '.', ip)\n"
1855
+ },
1856
+ {
1857
+ assertions: "\nassert diff_even_odd([1,3,5,7,4,1,6,8])==3\nassert diff_even_odd([1,2,3,4,5,6,7,8,9,10])==1\nassert diff_even_odd([1,5,7,9,10])==9\n",
1858
+ entryPoint: "diff_even_odd",
1859
+ id: "Mbpp/594",
1860
+ prompt: "\"\"\"\nWrite a function to find the difference of the first even and first odd number of a given list.\nassert diff_even_odd([1,3,5,7,4,1,6,8])==3\n\"\"\"\n",
1861
+ solution: "\ndef diff_even_odd(list1):\n first_even = next((el for el in list1 if el%2==0), -1)\n first_odd = next((el for el in list1 if el%2!=0), -1)\n return (first_even - first_odd)\n"
1862
+ },
1863
+ {
1864
+ assertions: "\nassert tuple_size((\"A\", 1, \"B\", 2, \"C\", 3) ) == sys.getsizeof((\"A\", 1, \"B\", 2, \"C\", 3))\nassert tuple_size((1, \"Raju\", 2, \"Nikhil\", 3, \"Deepanshu\") ) == sys.getsizeof((1, \"Raju\", 2, \"Nikhil\", 3, \"Deepanshu\"))\nassert tuple_size(((1, \"Lion\"), ( 2, \"Tiger\"), (3, \"Fox\"), (4, \"Wolf\")) ) == sys.getsizeof(((1, \"Lion\"), ( 2, \"Tiger\"), (3, \"Fox\"), (4, \"Wolf\")))\n",
1865
+ entryPoint: "tuple_size",
1866
+ id: "Mbpp/596",
1867
+ prompt: "\"\"\"\nWrite a function to find the size in bytes of the given tuple.\nassert tuple_size((\"A\", 1, \"B\", 2, \"C\", 3) ) == sys.getsizeof((\"A\", 1, \"B\", 2, \"C\", 3))\n\"\"\"\n",
1868
+ solution: "\nimport sys \ndef tuple_size(tuple_list):\n return sys.getsizeof(tuple_list)\n"
1869
+ },
1870
+ {
1871
+ assertions: "\nassert find_kth([2, 3, 6, 7, 9], [1, 4, 8, 10], 5) == 6\nassert find_kth([100, 112, 256, 349, 770], [72, 86, 113, 119, 265, 445, 892], 7) == 256\nassert find_kth([3, 4, 7, 8, 10], [2, 5, 9, 11], 6) == 8\n",
1872
+ entryPoint: "find_kth",
1873
+ id: "Mbpp/597",
1874
+ prompt: "\"\"\"\nWrite a function to find kth element from the given two sorted arrays.\nassert find_kth([2, 3, 6, 7, 9], [1, 4, 8, 10], 5) == 6\n\"\"\"\n",
1875
+ solution: "\ndef find_kth(arr1, arr2, k):\n\treturn sorted(arr1 + arr2)[k - 1]\n"
1876
+ },
1877
+ {
1878
+ assertions: "\nassert armstrong_number(153)==True\nassert armstrong_number(259)==False\nassert armstrong_number(4458)==False\n",
1879
+ entryPoint: "armstrong_number",
1880
+ id: "Mbpp/598",
1881
+ prompt: "\"\"\"\nWrite a function to check whether the given number is armstrong or not.\nassert armstrong_number(153)==True\n\"\"\"\n",
1882
+ solution: "\ndef armstrong_number(number):\n order = len(str(number))\n return sum([int(i) ** order for i in str(number)]) == number\n"
1883
+ },
1884
+ {
1885
+ assertions: "\nassert sum_average(10)==(55, 5.5)\nassert sum_average(15)==(120, 8.0)\nassert sum_average(20)==(210, 10.5)\n",
1886
+ entryPoint: "sum_average",
1887
+ id: "Mbpp/599",
1888
+ prompt: "\"\"\"\nWrite a function to find sum and average of first n natural numbers.\nassert sum_average(10)==(55, 5.5)\n\"\"\"\n",
1889
+ solution: "\ndef sum_average(number):\n sum_ = sum(range(1, number+1))\n average = sum_/number\n return sum_, average\n"
1890
+ },
1891
+ {
1892
+ assertions: "\nassert is_Even(1) == False\nassert is_Even(2) == True\nassert is_Even(3) == False\n",
1893
+ entryPoint: "is_Even",
1894
+ id: "Mbpp/600",
1895
+ prompt: "\"\"\"\nWrite a python function to check whether the given number is even or not.\nassert is_Even(1) == False\n\"\"\"\n",
1896
+ solution: "\ndef is_Even(n) : \n return n % 2 == 0\n"
1897
+ },
1898
+ {
1899
+ assertions: "\nassert first_repeated_char(\"abcabc\") == \"a\"\nassert first_repeated_char(\"abc\") == None\nassert first_repeated_char(\"123123\") == \"1\"\n",
1900
+ entryPoint: "first_repeated_char",
1901
+ id: "Mbpp/602",
1902
+ prompt: "\"\"\"\nWrite a python function to find the first repeated character in a given string.\nassert first_repeated_char(\"abcabc\") == \"a\"\n\"\"\"\n",
1903
+ solution: "\ndef first_repeated_char(str1):\n for index, c in enumerate(str1):\n if str1[:index + 1].count(c) > 1:\n return c\n return None\n"
1904
+ },
1905
+ {
1906
+ assertions: "\nassert get_ludic(10) == [1, 2, 3, 5, 7]\nassert get_ludic(25) == [1, 2, 3, 5, 7, 11, 13, 17, 23, 25]\nassert get_ludic(45) == [1, 2, 3, 5, 7, 11, 13, 17, 23, 25, 29, 37, 41, 43]\n",
1907
+ entryPoint: "get_ludic",
1908
+ id: "Mbpp/603",
1909
+ prompt: "\"\"\"\nWrite a function to get all lucid numbers smaller than or equal to a given integer.\nassert get_ludic(10) == [1, 2, 3, 5, 7]\n\"\"\"\n",
1910
+ solution: "\ndef get_ludic(n):\n\tludics = []\n\tfor i in range(1, n + 1):\n\t\tludics.append(i)\n\tindex = 1\n\twhile(index != len(ludics)):\n\t\tfirst_ludic = ludics[index]\n\t\tremove_index = index + first_ludic\n\t\twhile(remove_index < len(ludics)):\n\t\t\tludics.remove(ludics[remove_index])\n\t\t\tremove_index = remove_index + first_ludic - 1\n\t\tindex += 1\n\treturn ludics\n"
1911
+ },
1912
+ {
1913
+ assertions: "\nassert reverse_words(\"python program\")==(\"program python\")\nassert reverse_words(\"java language\")==(\"language java\")\nassert reverse_words(\"indian man\")==(\"man indian\")\n",
1914
+ entryPoint: "reverse_words",
1915
+ id: "Mbpp/604",
1916
+ prompt: "\"\"\"\nWrite a function to reverse words seperated by spaces in a given string.\nassert reverse_words(\"python program\")==(\"program python\")\n\"\"\"\n",
1917
+ solution: "\ndef reverse_words(s):\n\treturn ' '.join(reversed(s.split()))\n"
1918
+ },
1919
+ {
1920
+ assertions: "\nassert prime_num(13)==True\nassert prime_num(7)==True\nassert prime_num(-1010)==False\n",
1921
+ entryPoint: "prime_num",
1922
+ id: "Mbpp/605",
1923
+ prompt: "\"\"\"\nWrite a function to check if the given integer is a prime number.\nassert prime_num(13)==True\n\"\"\"\n",
1924
+ solution: "\nimport math\ndef prime_num(num):\n if num <= 1:\n return False\n for i in range(2, int(math.sqrt(num)) + 1):\n if num % i == 0:\n return False\n return True\n"
1925
+ },
1926
+ {
1927
+ assertions: "\nassert radian_degree(90)==1.5707963267948966\nassert radian_degree(60)==1.0471975511965976\nassert radian_degree(120)==2.0943951023931953\n",
1928
+ entryPoint: "radian_degree",
1929
+ id: "Mbpp/606",
1930
+ prompt: "\"\"\"\nWrite a function to convert degrees to radians.\nassert radian_degree(90)==1.5707963267948966\n\"\"\"\n",
1931
+ solution: "\nimport math\ndef radian_degree(degree):\n return degree * math.pi / 180\n"
1932
+ },
1933
+ {
1934
+ assertions: "\nassert find_literals('The quick brown fox jumps over the lazy dog.', 'fox') == ('fox', 16, 19)\nassert find_literals('Its been a very crazy procedure right', 'crazy') == ('crazy', 16, 21)\nassert find_literals('Hardest choices required strongest will', 'will') == ('will', 35, 39)\n",
1935
+ entryPoint: "find_literals",
1936
+ id: "Mbpp/607",
1937
+ prompt: "\"\"\"\nWrite a function to search a string for a regex pattern. The function should return the matching subtring, a start index and an end index.\nassert find_literals('The quick brown fox jumps over the lazy dog.', 'fox') == ('fox', 16, 19)\n\"\"\"\n",
1938
+ solution: "\nimport re\ndef find_literals(text, pattern):\n match = re.search(pattern, text)\n if match is None:\n return None\n s = match.start()\n e = match.end()\n return (match.re.pattern, s, e)\n"
1939
+ },
1940
+ {
1941
+ assertions: "\nassert bell_Number(2) == 2\nassert bell_Number(3) == 5\nassert bell_Number(4) == 15\n",
1942
+ entryPoint: "bell_Number",
1943
+ id: "Mbpp/608",
1944
+ prompt: "\"\"\"\nWrite a python function to find nth bell number.\nassert bell_Number(2) == 2\n\"\"\"\n",
1945
+ solution: "\ndef bell_Number(n): \n bell = [[0 for i in range(n+1)] for j in range(n+1)] \n bell[0][0] = 1\n for i in range(1, n+1):\n bell[i][0] = bell[i-1][i-1]\n for j in range(1, i+1): \n bell[i][j] = bell[i-1][j-1] + bell[i][j-1] \n return bell[n][0] \n"
1946
+ },
1947
+ {
1948
+ assertions: "\nassert remove_kth_element([1,1,2,3,4,4,5,1],3)==[1, 1, 3, 4, 4, 5, 1]\nassert remove_kth_element([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4],4)==[0, 0, 1, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4]\nassert remove_kth_element([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10],5)==[10,10,15,19, 18, 17, 26, 26, 17, 18, 10]\n",
1949
+ entryPoint: "remove_kth_element",
1950
+ id: "Mbpp/610",
1951
+ prompt: "\"\"\"\nWrite a python function which takes a list and returns a list with the same elements, but the k'th element removed.\nassert remove_kth_element([1,1,2,3,4,4,5,1],3)==[1, 1, 3, 4, 4, 5, 1]\n\"\"\"\n",
1952
+ solution: "\ndef remove_kth_element(list1, k):\n return list1[:k-1] + list1[k:]\n"
1953
+ },
1954
+ {
1955
+ assertions: "\nassert max_of_nth([[5, 6, 7], [1, 3, 5], [8, 9, 19]], 2) == 19\nassert max_of_nth([[6, 7, 8], [2, 4, 6], [9, 10, 20]], 1) == 10\nassert max_of_nth([[7, 8, 9], [3, 5, 7], [10, 11, 21]], 1) == 11\n",
1956
+ entryPoint: "max_of_nth",
1957
+ id: "Mbpp/611",
1958
+ prompt: "\"\"\"\nWrite a function which given a matrix represented as a list of lists returns the max of the n'th column.\nassert max_of_nth([[5, 6, 7], [1, 3, 5], [8, 9, 19]], 2) == 19\n\"\"\"\n",
1959
+ solution: "\ndef max_of_nth(test_list, N):\n return max([sub[N] for sub in test_list])\n"
1960
+ },
1961
+ {
1962
+ assertions: "\nassert merge([['x', 'y'], ['a', 'b'], ['m', 'n']]) == [['x', 'a', 'm'], ['y', 'b', 'n']]\nassert merge([[1, 2], [3, 4], [5, 6], [7, 8]]) == [[1, 3, 5, 7], [2, 4, 6, 8]]\nassert merge([[[1], [2]], [[3], [4]], [[5], [6]], [[7], [8]]]) == [[[1], [3], [5], [7]], [[2], [4], [6], [8]]]\n",
1963
+ entryPoint: "merge",
1964
+ id: "Mbpp/612",
1965
+ prompt: "\"\"\"\nWrite a python function which takes a list of lists, where each sublist has two elements, and returns a list of two lists where the first list has the first element of each sublist and the second one has the second.\nassert merge([['x', 'y'], ['a', 'b'], ['m', 'n']]) == [['x', 'a', 'm'], ['y', 'b', 'n']]\n\"\"\"\n",
1966
+ solution: "\ndef merge(lst): \n return [list(ele) for ele in list(zip(*lst))] \n"
1967
+ },
1968
+ {
1969
+ assertions: "\nassert cummulative_sum([(1, 3), (5, 6, 7), (2, 6)]) == 30\nassert cummulative_sum([(2, 4), (6, 7, 8), (3, 7)]) == 37\nassert cummulative_sum([(3, 5), (7, 8, 9), (4, 8)]) == 44\n",
1970
+ entryPoint: "cummulative_sum",
1971
+ id: "Mbpp/614",
1972
+ prompt: "\"\"\"\nWrite a function to find the cumulative sum of all the values that are present in the given tuple list.\nassert cummulative_sum([(1, 3), (5, 6, 7), (2, 6)]) == 30\n\"\"\"\n",
1973
+ solution: "\ndef cummulative_sum(test_list):\n return sum(map(sum, test_list))\n"
1974
+ },
1975
+ {
1976
+ assertions: "\nassert 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]\nassert average_tuple(((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3)))== [25.5, -18.0, 3.75]\nassert 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]\n",
1977
+ entryPoint: "average_tuple",
1978
+ id: "Mbpp/615",
1979
+ prompt: "\"\"\"\nWrite a function which takes a tuple of tuples and returns the average value for each tuple as a list.\nassert 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]\n\"\"\"\n",
1980
+ solution: "\ndef average_tuple(nums):\n result = [sum(x) / len(x) for x in zip(*nums)]\n return result\n"
1981
+ },
1982
+ {
1983
+ assertions: "\nassert tuple_modulo((10, 4, 5, 6), (5, 6, 7, 5)) == (0, 4, 5, 1)\nassert tuple_modulo((11, 5, 6, 7), (6, 7, 8, 6)) == (5, 5, 6, 1)\nassert tuple_modulo((12, 6, 7, 8), (7, 8, 9, 7)) == (5, 6, 7, 1)\n",
1984
+ entryPoint: "tuple_modulo",
1985
+ id: "Mbpp/616",
1986
+ prompt: "\"\"\"\nWrite a function which takes two tuples of the same length and performs the element wise modulo.\nassert tuple_modulo((10, 4, 5, 6), (5, 6, 7, 5)) == (0, 4, 5, 1)\n\"\"\"\n",
1987
+ solution: "\ndef tuple_modulo(test_tup1, test_tup2):\n res = tuple(ele1 % ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) \n return (res) \n"
1988
+ },
1989
+ {
1990
+ assertions: "\nassert div_list([4,5,6],[1, 2, 3])==[4.0,2.5,2.0]\nassert div_list([3,2],[1,4])==[3.0, 0.5]\nassert div_list([90,120],[50,70])==[1.8, 1.7142857142857142]\n",
1991
+ entryPoint: "div_list",
1992
+ id: "Mbpp/618",
1993
+ prompt: "\"\"\"\nWrite a function to divide two lists element wise.\nassert div_list([4,5,6],[1, 2, 3])==[4.0,2.5,2.0]\n\"\"\"\n",
1994
+ solution: "\ndef div_list(nums1,nums2):\n result = map(lambda x, y: x / y, nums1, nums2)\n return list(result)\n"
1995
+ },
1996
+ {
1997
+ assertions: "\nassert move_num('I1love143you55three3000thousand') == 'Iloveyouthreethousand1143553000'\nassert move_num('Avengers124Assemble') == 'AvengersAssemble124'\nassert move_num('Its11our12path13to14see15things16do17things') == 'Itsourpathtoseethingsdothings11121314151617'\n",
1998
+ entryPoint: "move_num",
1999
+ id: "Mbpp/619",
2000
+ prompt: "\"\"\"\nWrite a function to move all the numbers to the end of the given string.\nassert move_num('I1love143you55three3000thousand') == 'Iloveyouthreethousand1143553000'\n\"\"\"\n",
2001
+ solution: "\ndef move_num(test_str):\n num_str = ''.join(i for i in test_str if i.isdigit())\n else_str = ''.join(i for i in test_str if not i.isdigit())\n return else_str + num_str\n"
2002
+ },
2003
+ {
2004
+ assertions: "\nassert largest_subset([ 1, 3, 6, 13, 17, 18 ]) == 4\nassert largest_subset([10, 5, 3, 15, 20]) == 3\nassert largest_subset([18, 1, 3, 6, 13, 17]) == 4\n",
2005
+ entryPoint: "largest_subset",
2006
+ id: "Mbpp/620",
2007
+ prompt: "\"\"\"\nWrite a function to find the size of the largest subset of a list of numbers so that every pair is divisible.\nassert largest_subset([ 1, 3, 6, 13, 17, 18 ]) == 4\n\"\"\"\n",
2008
+ solution: "\ndef largest_subset(a):\n\tn = len(a)\n\tdp = [0 for _ in range(n)]\n\tdp[n - 1] = 1; \n\tfor i in range(n - 2, -1, -1):\n\t\tmxm = 0\n\t\tfor j in range(i + 1, n):\n\t\t\tif a[j] % a[i] == 0 or a[i] % a[j] == 0:\n\t\t\t\tmxm = max(mxm, dp[j])\n\t\tdp[i] = 1 + mxm\n\treturn max(dp)\n"
2009
+ },
2010
+ {
2011
+ assertions: "\nassert get_median([1, 12, 15, 26, 38], [2, 13, 17, 30, 45], 5) == 16.0\nassert get_median([2, 4, 8, 9], [7, 13, 19, 28], 4) == 8.5\nassert get_median([3, 6, 14, 23, 36, 42], [2, 18, 27, 39, 49, 55], 6) == 25.0\n",
2012
+ entryPoint: "get_median",
2013
+ id: "Mbpp/622",
2014
+ prompt: "\"\"\"\nWrite a function to find the median of two sorted lists of same size.\nassert get_median([1, 12, 15, 26, 38], [2, 13, 17, 30, 45], 5) == 16.0\n\"\"\"\n",
2015
+ solution: "\ndef get_median(arr1, arr2, n):\n i = 0\n j = 0\n m1 = -1\n m2 = -1\n count = 0\n while count < n + 1:\n count += 1\n if i == n:\n m1 = m2\n m2 = arr2[0]\n break\n elif j == n:\n m1 = m2\n m2 = arr1[0]\n break\n if arr1[i] <= arr2[j]:\n m1 = m2\n m2 = arr1[i]\n i += 1\n else:\n m1 = m2\n m2 = arr2[j]\n j += 1\n return (m1 + m2)/2\n"
2016
+ },
2017
+ {
2018
+ assertions: "\nassert nth_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2)==[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\nassert nth_nums([10,20,30],3)==([1000, 8000, 27000])\nassert nth_nums([12,15],5)==([248832, 759375])\n",
2019
+ entryPoint: "nth_nums",
2020
+ id: "Mbpp/623",
2021
+ prompt: "\"\"\"\nWrite a function to compute the n-th power of each number in a list.\nassert nth_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2)==[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n\"\"\"\n",
2022
+ solution: "\ndef nth_nums(nums, n):\n nth_nums = list(map(lambda x: x ** n, nums))\n return nth_nums\n"
2023
+ },
2024
+ {
2025
+ assertions: "\nassert is_upper(\"person\") ==\"PERSON\"\nassert is_upper(\"final\") == \"FINAL\"\nassert is_upper(\"Valid\") == \"VALID\"\n",
2026
+ entryPoint: "is_upper",
2027
+ id: "Mbpp/624",
2028
+ prompt: "\"\"\"\nWrite a python function to convert a given string to uppercase.\nassert is_upper(\"person\") ==\"PERSON\"\n\"\"\"\n",
2029
+ solution: "\ndef is_upper(string):\n return string.upper()\n"
2030
+ },
2031
+ {
2032
+ assertions: "\nassert triangle_area(-1) == None\nassert triangle_area(0) == 0\nassert triangle_area(2) == 4\n",
2033
+ entryPoint: "triangle_area",
2034
+ id: "Mbpp/626",
2035
+ prompt: "\"\"\"\nWrite a python function to find the area of the largest triangle that can be inscribed in a semicircle with a given radius.\nassert triangle_area(-1) == None\n\"\"\"\n",
2036
+ solution: "\ndef triangle_area(r) : \n if r < 0 : \n return None\n return r * r \n"
2037
+ },
2038
+ {
2039
+ assertions: "\nassert replace_spaces(\"My Name is Dawood\") == 'My%20Name%20is%20Dawood'\nassert replace_spaces(\"I am a Programmer\") == 'I%20am%20a%20Programmer'\nassert replace_spaces(\"I love Coding\") == 'I%20love%20Coding'\n",
2040
+ entryPoint: "replace_spaces",
2041
+ id: "Mbpp/628",
2042
+ prompt: "\"\"\"\nWrite a function to replace all spaces in the given string with '%20'.\nassert replace_spaces(\"My Name is Dawood\") == 'My%20Name%20is%20Dawood'\n\"\"\"\n",
2043
+ solution: "\ndef replace_spaces(string):\n return string.replace(\" \", \"%20\")\n"
2044
+ },
2045
+ {
2046
+ assertions: "\nassert Split([1,2,3,4,5]) == [2,4]\nassert Split([4,5,6,7,8,0,1]) == [4,6,8,0]\nassert Split ([8,12,15,19]) == [8,12]\n",
2047
+ entryPoint: "Split",
2048
+ id: "Mbpp/629",
2049
+ prompt: "\"\"\"\nWrite a python function to find even numbers from a list of numbers.\nassert Split([1,2,3,4,5]) == [2,4]\n\"\"\"\n",
2050
+ solution: "\ndef Split(l): \n return [num for num in l if num % 2 == 0]\n"
2051
+ },
2052
+ {
2053
+ assertions: "\nassert get_coordinates((3, 4)) == [[2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5]]\nassert get_coordinates((4, 5)) ==[[3, 4], [3, 5], [3, 6], [4, 4], [4, 5], [4, 6], [5, 4], [5, 5], [5, 6]]\nassert get_coordinates((5, 6)) == [[4, 5], [4, 6], [4, 7], [5, 5], [5, 6], [5, 7], [6, 5], [6, 6], [6, 7]]\n",
2054
+ entryPoint: "get_coordinates",
2055
+ id: "Mbpp/630",
2056
+ prompt: "\"\"\"\nWrite a function to extract all the adjacent coordinates of the given coordinate tuple.\nassert get_coordinates((3, 4)) == [[2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5]]\n\"\"\"\n",
2057
+ solution: "\ndef adjac(ele, sub = []): \n if not ele: \n yield sub \n else: \n yield from [idx for j in range(ele[0] - 1, ele[0] + 2) \n for idx in adjac(ele[1:], sub + [j])] \ndef get_coordinates(test_tup):\n return list(adjac(test_tup))\n"
2058
+ },
2059
+ {
2060
+ assertions: "\nassert replace_spaces('Jumanji The Jungle') == 'Jumanji_The_Jungle'\nassert replace_spaces('The_Avengers') == 'The Avengers'\nassert replace_spaces('Fast and Furious') == 'Fast_and_Furious'\n",
2061
+ entryPoint: "replace_spaces",
2062
+ id: "Mbpp/631",
2063
+ prompt: "\"\"\"\nWrite a function to replace whitespaces with an underscore and vice versa in a given string.\nassert replace_spaces('Jumanji The Jungle') == 'Jumanji_The_Jungle'\n\"\"\"\n",
2064
+ solution: "\ndef replace_spaces(text):\n return \"\".join(\" \" if c == \"_\" else (\"_\" if c == \" \" else c) for c in text)\n"
2065
+ },
2066
+ {
2067
+ assertions: "\nassert move_zero([1,0,2,0,3,4]) == [1,2,3,4,0,0]\nassert move_zero([2,3,2,0,0,4,0,5,0]) == [2,3,2,4,5,0,0,0,0]\nassert move_zero([0,1,0,1,1]) == [1,1,1,0,0]\n",
2068
+ entryPoint: "move_zero",
2069
+ id: "Mbpp/632",
2070
+ prompt: "\"\"\"\nWrite a python function to move all zeroes to the end of the given list.\nassert move_zero([1,0,2,0,3,4]) == [1,2,3,4,0,0]\n\"\"\"\n",
2071
+ solution: "\ndef move_zero(num_list):\n zeros = [0] * num_list.count(0)\n front = [i for i in num_list if i != 0]\n return front + zeros\n"
2072
+ },
2073
+ {
2074
+ assertions: "\nassert pair_xor_Sum([5,9,7,6],4) == 47\nassert pair_xor_Sum([7,3,5],3) == 12\nassert pair_xor_Sum([7,3],2) == 4\n",
2075
+ entryPoint: "pair_xor_Sum",
2076
+ id: "Mbpp/633",
2077
+ prompt: "\"\"\"\nWrite a python function to find the sum of xor of all pairs of numbers in the given list.\nassert pair_xor_Sum([5,9,7,6],4) == 47\n\"\"\"\n",
2078
+ solution: "\ndef pair_xor_Sum(arr,n) : \n ans = 0 \n for i in range(0,n) : \n for j in range(i + 1,n) : \n ans = ans + (arr[i] ^ arr[j]) \n return ans \n"
2079
+ },
2080
+ {
2081
+ assertions: "\nassert heap_sort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\nassert heap_sort([25, 35, 22, 85, 14, 65, 75, 25, 58])==[14, 22, 25, 25, 35, 58, 65, 75, 85]\nassert heap_sort( [7, 1, 9, 5])==[1,5,7,9]\n",
2082
+ entryPoint: "heap_sort",
2083
+ id: "Mbpp/635",
2084
+ prompt: "\"\"\"\nWrite a function to sort the given list.\nassert heap_sort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n\"\"\"\n",
2085
+ solution: "\nimport heapq as hq\ndef heap_sort(iterable):\n hq.heapify(iterable)\n return [hq.heappop(iterable) for _ in range(len(iterable))]\n"
2086
+ },
2087
+ {
2088
+ assertions: "\nassert noprofit_noloss(1500,1200)==False\nassert noprofit_noloss(100,100)==True\nassert noprofit_noloss(2000,5000)==False\n",
2089
+ entryPoint: "noprofit_noloss",
2090
+ id: "Mbpp/637",
2091
+ prompt: "\"\"\"\nWrite a function to check whether the given amount has no profit and no loss\nassert noprofit_noloss(1500,1200)==False\n\"\"\"\n",
2092
+ solution: "\ndef noprofit_noloss(actual_cost, sale_amount): \n return actual_cost == sale_amount\n"
2093
+ },
2094
+ {
2095
+ assertions: "\nassert wind_chill(120,35)==40\nassert wind_chill(40,20)==19\nassert wind_chill(10,8)==6\n",
2096
+ entryPoint: "wind_chill",
2097
+ id: "Mbpp/638",
2098
+ prompt: "\"\"\"\nWrite 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.\nassert wind_chill(120,35)==40\n\"\"\"\n",
2099
+ solution: "\nimport math\ndef wind_chill(v,t):\n windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16)\n return int(round(windchill, 0))\n"
2100
+ },
2101
+ {
2102
+ assertions: "\nassert sample_nam(['sally', 'Dylan', 'rebecca', 'Diana', 'Joanne', 'keith'])==16\nassert sample_nam([\"php\", \"res\", \"Python\", \"abcd\", \"Java\", \"aaa\"])==10\nassert sample_nam([\"abcd\", \"Python\", \"abba\", \"aba\"])==6\n",
2103
+ entryPoint: "sample_nam",
2104
+ id: "Mbpp/639",
2105
+ prompt: "\"\"\"\nWrite a function to sum the length of the names of a given list of names after removing the names that start with a lowercase letter.\nassert sample_nam(['sally', 'Dylan', 'rebecca', 'Diana', 'Joanne', 'keith'])==16\n\"\"\"\n",
2106
+ solution: "\ndef sample_nam(sample_names):\n sample_names=list(filter(lambda el:el[0].isupper() and el[1:].islower(),sample_names))\n return len(''.join(sample_names))\n"
2107
+ },
2108
+ {
2109
+ assertions: "\nassert is_nonagonal(10) == 325\nassert is_nonagonal(15) == 750\nassert is_nonagonal(18) == 1089\n",
2110
+ entryPoint: "is_nonagonal",
2111
+ id: "Mbpp/641",
2112
+ prompt: "\"\"\"\nWrite a function to find the nth nonagonal number.\nassert is_nonagonal(10) == 325\n\"\"\"\n",
2113
+ solution: "\ndef is_nonagonal(n): \n\treturn int(n * (7 * n - 5) / 2) \n"
2114
+ },
2115
+ {
2116
+ assertions: "\nassert text_match_wordz_middle(\"pythonzabc.\")==True\nassert text_match_wordz_middle(\"zxyabc.\")==False\nassert text_match_wordz_middle(\" lang .\")==False\n",
2117
+ entryPoint: "text_match_wordz_middle",
2118
+ id: "Mbpp/643",
2119
+ prompt: "\"\"\"\nWrite a function that checks if a strings contains 'z', except at the start and end of the word.\nassert text_match_wordz_middle(\"pythonzabc.\")==True\n\"\"\"\n",
2120
+ solution: "\nimport re\ndef text_match_wordz_middle(text):\n\treturn re.search(r'\\Bz\\B', text) is not None\n"
2121
+ },
2122
+ {
2123
+ assertions: "\nassert reverse_Array_Upto_K([1, 2, 3, 4, 5, 6],4) == [4, 3, 2, 1, 5, 6]\nassert reverse_Array_Upto_K([4, 5, 6, 7], 2) == [5, 4, 6, 7]\nassert reverse_Array_Upto_K([9, 8, 7, 6, 5],3) == [7, 8, 9, 6, 5]\n",
2124
+ entryPoint: "reverse_Array_Upto_K",
2125
+ id: "Mbpp/644",
2126
+ prompt: "\"\"\"\nWrite a python function to reverse an array upto a given position.\nassert reverse_Array_Upto_K([1, 2, 3, 4, 5, 6],4) == [4, 3, 2, 1, 5, 6]\n\"\"\"\n",
2127
+ solution: "\ndef reverse_Array_Upto_K(input, k): \n return input[k-1::-1] + input[k:]\n"
2128
+ },
2129
+ {
2130
+ assertions: "\nassert add_dict_to_tuple((4, 5, 6), {\"MSAM\" : 1, \"is\" : 2, \"best\" : 3} ) == (4, 5, 6, {'MSAM': 1, 'is': 2, 'best': 3})\nassert add_dict_to_tuple((1, 2, 3), {\"UTS\" : 2, \"is\" : 3, \"Worst\" : 4} ) == (1, 2, 3, {'UTS': 2, 'is': 3, 'Worst': 4})\nassert add_dict_to_tuple((8, 9, 10), {\"POS\" : 3, \"is\" : 4, \"Okay\" : 5} ) == (8, 9, 10, {'POS': 3, 'is': 4, 'Okay': 5})\n",
2131
+ entryPoint: "add_dict_to_tuple",
2132
+ id: "Mbpp/720",
2133
+ prompt: "\"\"\"\nWrite a function to add a dictionary to the tuple. The output should be a tuple.\nassert add_dict_to_tuple((4, 5, 6), {\"MSAM\" : 1, \"is\" : 2, \"best\" : 3} ) == (4, 5, 6, {'MSAM': 1, 'is': 2, 'best': 3})\n\"\"\"\n",
2134
+ solution: "\ndef add_dict_to_tuple(test_tup, test_dict):\n return test_tup + (test_dict, )\n"
2135
+ },
2136
+ {
2137
+ assertions: "\nassert maxAverageOfPath([[1, 2, 3], [6, 5, 4], [7, 3, 9]]) == 5.2\nassert maxAverageOfPath([[2, 3, 4], [7, 6, 5], [8, 4, 10]]) == 6.2\nassert maxAverageOfPath([[3, 4, 5], [8, 7, 6], [9, 5, 11]]) == 7.2\nassert maxAverageOfPath([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == 5.8\n",
2138
+ entryPoint: "maxAverageOfPath",
2139
+ id: "Mbpp/721",
2140
+ prompt: "\"\"\"\nGiven a square matrix of size N*N given as a list of lists, where each cell is associated with a specific cost. A path is defined as a specific sequence of cells that starts from the top-left cell move only right or down and ends on bottom right cell. We want to find a path with the maximum average over all existing paths. Average is computed as total cost divided by the number of cells visited in the path.\nassert maxAverageOfPath([[1, 2, 3], [6, 5, 4], [7, 3, 9]]) == 5.2\n\"\"\"\n",
2141
+ solution: "\ndef maxAverageOfPath(cost):\n N = len(cost)\n dp = [[0 for _ in range(N + 1)] for _ in range(N + 1)]\n dp[0][0] = cost[0][0]\n for i in range(1, N):\n dp[i][0] = dp[i - 1][0] + cost[i][0]\n for j in range(1, N):\n dp[0][j] = dp[0][j - 1] + cost[0][j]\n for i in range(1, N):\n for j in range(1, N):\n dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + cost[i][j]\n # all paths are of length 2 * N - 1, so just divide by that\n return dp[N - 1][N - 1] / (2 * N - 1)\n"
2142
+ },
2143
+ {
2144
+ assertions: "\nassert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},6.0,70)=={'Cierra Vega': (6.2, 70)}\nassert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},5.9,67)=={'Cierra Vega': (6.2, 70),'Kierra Gentry': (6.0, 68)}\nassert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},5.7,64)=={'Cierra Vega': (6.2, 70),'Alden Cantrell': (5.9, 65),'Kierra Gentry': (6.0, 68),'Pierre Cox': (5.8, 66)}\n",
2145
+ entryPoint: "filter_data",
2146
+ id: "Mbpp/722",
2147
+ prompt: "\"\"\"\nThe input is given as - a dictionary with a student name as a key and a tuple of float (student_height, student_weight) as a value, - minimal height, - minimal weight. Write a function to filter students that have height and weight above the minimum.\nassert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},6.0,70)=={'Cierra Vega': (6.2, 70)}\n\"\"\"\n",
2148
+ solution: "\ndef filter_data(students,h,w):\n return {k: s for k, s in students.items() if s[0] >= h and s[1] >= w}\n"
2149
+ },
2150
+ {
2151
+ assertions: "\nassert count_same_pair([1, 2, 3, 4, 5, 6, 7, 8],[2, 2, 3, 1, 2, 6, 7, 9])==4\nassert count_same_pair([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==11\nassert count_same_pair([2, 4, -6, -9, 11, -12, 14, -5, 17],[2, 1, 2, -1, -5, 6, 4, -3, -2])==1\nassert count_same_pair([0, 1, 1, 2],[0, 1, 2, 2])==3\n",
2152
+ entryPoint: "count_same_pair",
2153
+ id: "Mbpp/723",
2154
+ prompt: "\"\"\"\nThe input is defined as two lists of the same length. Write a function to count indices where the lists have the same values.\nassert count_same_pair([1, 2, 3, 4, 5, 6, 7, 8],[2, 2, 3, 1, 2, 6, 7, 9])==4\n\"\"\"\n",
2155
+ solution: "\nfrom operator import eq\ndef count_same_pair(nums1, nums2):\n result = sum(map(eq, nums1, nums2))\n return result\n"
2156
+ },
2157
+ {
2158
+ assertions: "\nassert power_base_sum(2,100)==115\nassert power_base_sum(8,10)==37\nassert power_base_sum(8,15)==62\nassert power_base_sum(3,3)==9\n",
2159
+ entryPoint: "power_base_sum",
2160
+ id: "Mbpp/724",
2161
+ prompt: "\"\"\"\nWrite a function that takes base and power as arguments and calculate the sum of all digits of the base to the specified power.\nassert power_base_sum(2,100)==115\n\"\"\"\n",
2162
+ solution: "\ndef power_base_sum(base, power):\n return sum([int(i) for i in str(pow(base, power))])\n"
2163
+ },
2164
+ {
2165
+ assertions: "\nassert extract_quotation('Cortex \"A53\" Based \"multi\" tasking \"Processor\"') == ['A53', 'multi', 'Processor']\nassert extract_quotation('Cast your \"favorite\" entertainment \"apps\"') == ['favorite', 'apps']\nassert extract_quotation('Watch content \"4k Ultra HD\" resolution with \"HDR 10\" Support') == ['4k Ultra HD', 'HDR 10']\nassert extract_quotation(\"Watch content '4k Ultra HD' resolution with 'HDR 10' Support\") == []\n",
2166
+ entryPoint: "extract_quotation",
2167
+ id: "Mbpp/725",
2168
+ prompt: "\"\"\"\nWrite a function to extract values between quotation marks \" \" of the given string.\nassert extract_quotation('Cortex \"A53\" Based \"multi\" tasking \"Processor\"') == ['A53', 'multi', 'Processor']\n\"\"\"\n",
2169
+ solution: "\nimport re\ndef extract_quotation(text1):\n return re.findall(r'\"(.*?)\"', text1)\n"
2170
+ },
2171
+ {
2172
+ assertions: "\nassert multiply_elements((1, 5, 7, 8, 10)) == (5, 35, 56, 80)\nassert multiply_elements((2, 4, 5, 6, 7)) == (8, 20, 30, 42)\nassert multiply_elements((12, 13, 14, 9, 15)) == (156, 182, 126, 135)\nassert multiply_elements((12,)) == ()\n",
2173
+ entryPoint: "multiply_elements",
2174
+ id: "Mbpp/726",
2175
+ prompt: "\"\"\"\nWrite a function that takes as input a tuple of numbers (t_1,...,t_{N+1}) and returns a tuple of length N where the i-th element of the tuple is equal to t_i * t_{i+1}.\nassert multiply_elements((1, 5, 7, 8, 10)) == (5, 35, 56, 80)\n\"\"\"\n",
2176
+ solution: "\ndef multiply_elements(test_tup):\n return tuple(i * j for i, j in zip(test_tup, test_tup[1:]))\n"
2177
+ },
2178
+ {
2179
+ assertions: "\nassert sum_list([10,20,30],[15,25,35])==[25,45,65]\nassert sum_list([1,2,3],[5,6,7])==[6,8,10]\nassert sum_list([15,20,30],[15,45,75])==[30,65,105]\n",
2180
+ entryPoint: "sum_list",
2181
+ id: "Mbpp/728",
2182
+ prompt: "\"\"\"\nWrite a function takes as input two lists [a_1,...,a_n], [b_1,...,b_n] and returns [a_1+b_1,...,a_n+b_n].\nassert sum_list([10,20,30],[15,25,35])==[25,45,65]\n\"\"\"\n",
2183
+ solution: "\ndef sum_list(lst1,lst2):\n return [a + b for a, b in zip(lst1, lst2)] \n"
2184
+ },
2185
+ {
2186
+ assertions: "\nassert consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4 ])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4]\nassert consecutive_duplicates([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10])==[10, 15, 19, 18, 17, 26, 17, 18, 10]\nassert consecutive_duplicates(['a', 'a', 'b', 'c', 'd', 'd'])==['a', 'b', 'c', 'd']\nassert consecutive_duplicates(['a', 'a', 'b', 'c', 'd', 'd', 'a', 'a'])==['a', 'b', 'c', 'd', 'a']\n",
2187
+ entryPoint: "consecutive_duplicates",
2188
+ id: "Mbpp/730",
2189
+ prompt: "\"\"\"\nWrite a function to remove consecutive duplicates of a given list.\nassert consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4 ])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4]\n\"\"\"\n",
2190
+ solution: "\nfrom itertools import groupby\ndef consecutive_duplicates(nums):\n return [key for key, _ in groupby(nums)] \n"
2191
+ },
2192
+ {
2193
+ assertions: "\nassert lateralsurface_cone(5,12)==204.20352248333654\nassert lateralsurface_cone(10,15)==566.3586699569488\nassert lateralsurface_cone(19,17)==1521.8090132193388\n",
2194
+ entryPoint: "lateralsurface_cone",
2195
+ id: "Mbpp/731",
2196
+ prompt: "\"\"\"\nWrite a function to find the lateral surface area of a cone given radius r and the height h.\nassert lateralsurface_cone(5,12)==204.20352248333654\n\"\"\"\n",
2197
+ solution: "\nimport math\ndef lateralsurface_cone(r,h):\n l = math.sqrt(r * r + h * h)\n return math.pi * r * l\n"
2198
+ },
2199
+ {
2200
+ assertions: "\nassert replace_specialchar('Python language, Programming language.')==('Python:language::Programming:language:')\nassert replace_specialchar('a b c,d e f')==('a:b:c:d:e:f')\nassert replace_specialchar('ram reshma,ram rahim')==('ram:reshma:ram:rahim')\n",
2201
+ entryPoint: "replace_specialchar",
2202
+ id: "Mbpp/732",
2203
+ prompt: "\"\"\"\nWrite a function to replace all occurrences of spaces, commas, or dots with a colon.\nassert replace_specialchar('Python language, Programming language.')==('Python:language::Programming:language:')\n\"\"\"\n",
2204
+ solution: "\nimport re\ndef replace_specialchar(text):\n return re.sub(\"[ ,.]\", \":\", text)\n"
2205
+ },
2206
+ {
2207
+ assertions: "\nassert find_first_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 1\nassert find_first_occurrence([2, 3, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 2\nassert find_first_occurrence([1, 2, 4, 5, 6, 6, 8, 9, 9, 9], 6) == 4\n",
2208
+ entryPoint: "find_first_occurrence",
2209
+ id: "Mbpp/733",
2210
+ prompt: "\"\"\"\nWrite a function to find the index of the first occurrence of a given number in a sorted array.\nassert find_first_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 1\n\"\"\"\n",
2211
+ solution: "\ndef find_first_occurrence(A, x):\n (left, right) = (0, len(A) - 1)\n result = -1\n while left <= right:\n mid = (left + right) // 2\n if x == A[mid]:\n result = mid\n right = mid - 1\n elif x < A[mid]:\n right = mid - 1\n else:\n left = mid + 1\n return result\n"
2212
+ },
2213
+ {
2214
+ assertions: "\nassert sum_Of_Subarray_Prod([1,2,3]) == 20\nassert sum_Of_Subarray_Prod([1,2]) == 5\nassert sum_Of_Subarray_Prod([1,2,3,4]) == 84\n",
2215
+ entryPoint: "sum_Of_Subarray_Prod",
2216
+ id: "Mbpp/734",
2217
+ prompt: "\"\"\"\nWrite a python function to find sum of products of all possible sublists of a given list. \nassert sum_Of_Subarray_Prod([1,2,3]) == 20\n\"\"\"\n",
2218
+ solution: "\ndef sum_Of_Subarray_Prod(arr):\n result = 0 # final result\n partial = 0 # partial sum\n # stimulate the recursion\n while arr != []:\n partial = arr[-1] * (1 + partial)\n result += partial\n arr.pop()\n return result\n"
2219
+ },
2220
+ {
2221
+ assertions: "\nassert toggle_middle_bits(9) == 15\nassert toggle_middle_bits(10) == 12\nassert toggle_middle_bits(11) == 13\nassert toggle_middle_bits(0b1000001) == 0b1111111\nassert toggle_middle_bits(0b1001101) == 0b1110011\n",
2222
+ entryPoint: "toggle_middle_bits",
2223
+ id: "Mbpp/735",
2224
+ prompt: "\"\"\"\nWrite a python function to toggle bits of the number except the first and the last bit. \nassert toggle_middle_bits(9) == 15\n\"\"\"\n",
2225
+ solution: "\ndef toggle_middle_bits(n): \n binary = bin(n)[2:]\n toggled = ''.join(['0' if i == '1' else '1' for i in binary[1:-1]])\n return int(binary[0] + toggled + binary[-1], 2)\n"
2226
+ },
2227
+ {
2228
+ assertions: "\nassert left_insertion([1,2,4,5],6)==4\nassert left_insertion([1,2,4,5],3)==2\nassert left_insertion([1,2,4,5],7)==4\n",
2229
+ entryPoint: "left_insertion",
2230
+ id: "Mbpp/736",
2231
+ prompt: "\"\"\"\nWrite a function to locate the left insertion point for a specified value in sorted order. \nassert left_insertion([1,2,4,5],6)==4\n\"\"\"\n",
2232
+ solution: "\nimport bisect\ndef left_insertion(a, x):\n return bisect.bisect_left(a, x)\n"
2233
+ },
2234
+ {
2235
+ assertions: "\nassert check_str(\"annie\")\nassert not check_str(\"dawood\")\nassert check_str(\"Else\")\n",
2236
+ entryPoint: "check_str",
2237
+ id: "Mbpp/737",
2238
+ prompt: "\"\"\"\nWrite a function to check whether the given string is starting with a vowel or not using regex.\nassert check_str(\"annie\")\n\"\"\"\n",
2239
+ solution: "\nimport re \ndef check_str(string): \n\tregex = '^[aeiouAEIOU][A-Za-z0-9_]*'\n\treturn re.search(regex, string)\n"
2240
+ },
2241
+ {
2242
+ assertions: "\nassert find_Index(2) == 4\nassert find_Index(3) == 14\nassert find_Index(4) == 45\n",
2243
+ entryPoint: "find_Index",
2244
+ id: "Mbpp/739",
2245
+ prompt: "\"\"\"\nWrite a python function to find the index of smallest triangular number with n digits. \nassert find_Index(2) == 4\n\"\"\"\n",
2246
+ solution: "\nimport math \ndef find_Index(n): \n x = math.sqrt(2 * math.pow(10,(n - 1)))\n return round(x)\n"
2247
+ },
2248
+ {
2249
+ assertions: "\nassert tuple_to_dict((1, 5, 7, 10, 13, 5)) == {1: 5, 7: 10, 13: 5}\nassert tuple_to_dict((1, 2, 3, 4, 5, 6)) == {1: 2, 3: 4, 5: 6}\nassert tuple_to_dict((7, 8, 9, 10, 11, 12)) == {7: 8, 9: 10, 11: 12}\n",
2250
+ entryPoint: "tuple_to_dict",
2251
+ id: "Mbpp/740",
2252
+ prompt: "\"\"\"\nWrite a function to convert the given tuple to a key-value dictionary using adjacent elements. \nassert tuple_to_dict((1, 5, 7, 10, 13, 5)) == {1: 5, 7: 10, 13: 5}\n\"\"\"\n",
2253
+ solution: "\ndef tuple_to_dict(test_tup):\n return dict(test_tup[idx : idx + 2] for idx in range(0, len(test_tup), 2))\n"
2254
+ },
2255
+ {
2256
+ assertions: "\nassert all_Characters_Same(\"python\") == False\nassert all_Characters_Same(\"aaa\") == True\nassert all_Characters_Same(\"data\") == False\n",
2257
+ entryPoint: "all_Characters_Same",
2258
+ id: "Mbpp/741",
2259
+ prompt: "\"\"\"\nWrite a python function to check whether all the characters are same or not.\nassert all_Characters_Same(\"python\") == False\n\"\"\"\n",
2260
+ solution: "\ndef all_Characters_Same(s) :\n return all(ch == s[0] for ch in s[1:])\n"
2261
+ },
2262
+ {
2263
+ assertions: "\nassert math.isclose(area_tetrahedron(3), 15.588457268119894, rel_tol=0.001)\nassert math.isclose(area_tetrahedron(20), 692.8203230275509, rel_tol=0.001)\nassert math.isclose(area_tetrahedron(10), 173.20508075688772, rel_tol=0.001)\n",
2264
+ entryPoint: "area_tetrahedron",
2265
+ id: "Mbpp/742",
2266
+ prompt: "\"\"\"\nWrite a function to caluclate the area of a tetrahedron.\nassert area_tetrahedron(3)==15.588457268119894\n\"\"\"\n",
2267
+ solution: "\nimport math\ndef area_tetrahedron(side):\n return math.sqrt(3)*(side*side)\n"
2268
+ },
2269
+ {
2270
+ assertions: "\nassert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],3)==[8, 9, 10, 1, 2, 3, 4, 5, 6, 7]\nassert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2)==[9, 10, 1, 2, 3, 4, 5, 6, 7, 8]\nassert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],5)==[6, 7, 8, 9, 10, 1, 2, 3, 4, 5]\n",
2271
+ entryPoint: "rotate_right",
2272
+ id: "Mbpp/743",
2273
+ prompt: "\"\"\"\nWrite a function to rotate a given list by specified number of items to the right direction. \nassert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],3)==[8, 9, 10, 1, 2, 3, 4, 5, 6, 7]\n\"\"\"\n",
2274
+ solution: "\ndef rotate_right(l, m):\n return l[-m:] + l[:-m]\n"
2275
+ },
2276
+ {
2277
+ assertions: "\nassert check_none((10, 4, 5, 6, None)) == True\nassert check_none((7, 8, 9, 11, 14)) == False\nassert check_none((1, 2, 3, 4, None)) == True\n",
2278
+ entryPoint: "check_none",
2279
+ id: "Mbpp/744",
2280
+ prompt: "\"\"\"\nWrite a function to check if the given tuple has any none value or not.\nassert check_none((10, 4, 5, 6, None)) == True\n\"\"\"\n",
2281
+ solution: "\ndef check_none(test_tup):\n return any(ele is None for ele in test_tup)\n"
2282
+ },
2283
+ {
2284
+ assertions: "\nassert divisible_by_digits(1,22)==[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]\nassert divisible_by_digits(1,15)==[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15]\nassert divisible_by_digits(20,25)==[22, 24]\n",
2285
+ entryPoint: "divisible_by_digits",
2286
+ id: "Mbpp/745",
2287
+ prompt: "\"\"\"\nWrite a function to find numbers within a given range from startnum ti endnum where every number is divisible by every digit it contains. \nassert divisible_by_digits(1,22)==[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]\n\"\"\"\n",
2288
+ solution: "\ndef divisible_by_digits(startnum, endnum):\n return [n for n in range(startnum, endnum+1) \\\n if not any(map(lambda x: int(x) == 0 or n%int(x) != 0, str(n)))]\n"
2289
+ },
2290
+ {
2291
+ assertions: "\nassert capital_words_spaces(\"Python\") == 'Python'\nassert capital_words_spaces(\"PythonProgrammingExamples\") == 'Python Programming Examples'\nassert capital_words_spaces(\"GetReadyToBeCodingFreak\") == 'Get Ready To Be Coding Freak'\n",
2292
+ entryPoint: "capital_words_spaces",
2293
+ id: "Mbpp/748",
2294
+ prompt: "\"\"\"\nWrite a function to put spaces between words starting with capital letters in a given string.\nassert capital_words_spaces(\"Python\") == 'Python'\n\"\"\"\n",
2295
+ solution: "\nimport re\ndef capital_words_spaces(str1):\n return re.sub(r\"(\\w)([A-Z])\", r\"\\1 \\2\", str1)\n"
2296
+ },
2297
+ {
2298
+ assertions: "\nassert sort_numeric_strings( ['4','12','45','7','0','100','200','-12','-500'])==[-500, -12, 0, 4, 7, 12, 45, 100, 200]\nassert sort_numeric_strings(['2','3','8','4','7','9','8','2','6','5','1','6','1','2','3','4','6','9','1','2'])==[1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8, 9, 9]\nassert sort_numeric_strings(['1','3','5','7','1', '3','13', '15', '17','5', '7 ','9','1', '11'])==[1, 1, 1, 3, 3, 5, 5, 7, 7, 9, 11, 13, 15, 17]\n",
2299
+ entryPoint: "sort_numeric_strings",
2300
+ id: "Mbpp/749",
2301
+ prompt: "\"\"\"\nWrite a function to sort a given list of strings of numbers numerically. \nassert sort_numeric_strings( ['4','12','45','7','0','100','200','-12','-500'])==[-500, -12, 0, 4, 7, 12, 45, 100, 200]\n\"\"\"\n",
2302
+ solution: "\ndef sort_numeric_strings(nums_str):\n return sorted([int(x) for x in nums_str])\n"
2303
+ },
2304
+ {
2305
+ assertions: "\nassert add_tuple([5, 6, 7], (9, 10)) == [5, 6, 7, 9, 10]\nassert add_tuple([6, 7, 8], (10, 11)) == [6, 7, 8, 10, 11]\nassert add_tuple([7, 8, 9], (11, 12)) == [7, 8, 9, 11, 12]\n",
2306
+ entryPoint: "add_tuple",
2307
+ id: "Mbpp/750",
2308
+ prompt: "\"\"\"\nWrite a function to add the given tuple to the given list.\nassert add_tuple([5, 6, 7], (9, 10)) == [5, 6, 7, 9, 10]\n\"\"\"\n",
2309
+ solution: "\ndef add_tuple(test_list, test_tup):\n return test_list + list(test_tup)\n"
2310
+ },
2311
+ {
2312
+ assertions: "\nassert check_min_heap([1, 2, 3, 4, 5, 6]) == True\nassert check_min_heap([2, 3, 4, 5, 10, 15]) == True\nassert check_min_heap([2, 10, 4, 5, 3, 15]) == False\n",
2313
+ entryPoint: "check_min_heap",
2314
+ id: "Mbpp/751",
2315
+ prompt: "\"\"\"\nWrite a function to check if the given array represents min heap or not. \nassert check_min_heap([1, 2, 3, 4, 5, 6]) == True\n\"\"\"\n",
2316
+ solution: "\ndef check_min_heap_helper(arr, i):\n if 2 * i + 2 > len(arr):\n return True\n left_child = (arr[i] <= arr[2 * i + 1]) and check_min_heap_helper(arr, 2 * i + 1)\n right_child = (2 * i + 2 == len(arr)) or \\\n (arr[i] <= arr[2 * i + 2] and \\\n check_min_heap_helper(arr, 2 * i + 2))\n return left_child and right_child\ndef check_min_heap(arr):\n return check_min_heap_helper(arr, 0)\n"
2317
+ },
2318
+ {
2319
+ assertions: "\nassert jacobsthal_num(5) == 11\nassert jacobsthal_num(2) == 1\nassert jacobsthal_num(4) == 5\nassert jacobsthal_num(13) == 2731\n",
2320
+ entryPoint: "jacobsthal_num",
2321
+ id: "Mbpp/752",
2322
+ prompt: "\"\"\"\nWrite a function to find the nth jacobsthal number. 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341, 683, 1365, 2731, ...\nassert jacobsthal_num(5) == 11\n\"\"\"\n",
2323
+ solution: "\ndef jacobsthal_num(n): \n\tdp = [0] * (n + 1) \n\tdp[0] = 0\n\tdp[1] = 1\n\tfor i in range(2, n+1): \n\t\tdp[i] = dp[i - 1] + 2 * dp[i - 2] \n\treturn dp[n]\n"
2324
+ },
2325
+ {
2326
+ assertions: "\nassert min_k([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2) == [('Akash', 2), ('Akshat', 4)]\nassert min_k([('Sanjeev', 11), ('Angat', 5), ('Akash', 3), ('Nepin', 9)], 3) == [('Akash', 3), ('Angat', 5), ('Nepin', 9)]\nassert min_k([('tanmay', 14), ('Amer', 11), ('Ayesha', 9), ('SKD', 16)], 1) == [('Ayesha', 9)]\n",
2327
+ entryPoint: "min_k",
2328
+ id: "Mbpp/753",
2329
+ prompt: "\"\"\"\nWrite a function to find minimum k records from tuple list. - in this case a verbatim copy of test cases\nassert min_k([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2) == [('Akash', 2), ('Akshat', 4)]\n\"\"\"\n",
2330
+ solution: "\ndef min_k(test_list, K):\n res = sorted(test_list, key = lambda x: x[1])[:K]\n return (res) \n"
2331
+ },
2332
+ {
2333
+ assertions: "\nassert 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]\nassert 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]\nassert 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]\nassert extract_index_list([1, 2, 3, 4, 6, 6, 6],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7])==[]\n",
2334
+ entryPoint: "extract_index_list",
2335
+ id: "Mbpp/754",
2336
+ prompt: "\"\"\"\nWe 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.\nassert 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]\n\"\"\"\n",
2337
+ solution: "\ndef extract_index_list(l1, l2, l3):\n return [a for a, b, c in zip(l1, l2, l3) if a == b == c]\n"
2338
+ },
2339
+ {
2340
+ assertions: "\nassert second_smallest([1, 2, -8, -2, 0, -2])==-2\nassert second_smallest([1, 1, -0.5, 0, 2, -2, -2])==-0.5\nassert second_smallest([2,2])==None\nassert second_smallest([2,2,2])==None\n",
2341
+ entryPoint: "second_smallest",
2342
+ id: "Mbpp/755",
2343
+ prompt: "\"\"\"\nWrite a function to find the second smallest number in a list.\nassert second_smallest([1, 2, -8, -2, 0, -2])==-2\n\"\"\"\n",
2344
+ solution: "\ndef second_smallest(numbers):\n sorted_set = sorted(set(numbers))\n if len(sorted_set) < 2:\n return None\n return sorted_set[1]\n"
2345
+ },
2346
+ {
2347
+ assertions: "\nassert count_reverse_pairs([\"julia\", \"best\", \"tseb\", \"for\", \"ailuj\"])== 2\nassert count_reverse_pairs([\"geeks\", \"best\", \"for\", \"skeeg\"]) == 1\nassert count_reverse_pairs([\"makes\", \"best\", \"sekam\", \"for\", \"rof\"]) == 2\n",
2348
+ entryPoint: "count_reverse_pairs",
2349
+ id: "Mbpp/757",
2350
+ prompt: "\"\"\"\nWrite a function to count the pairs of reverse strings in the given string list. \nassert count_reverse_pairs([\"julia\", \"best\", \"tseb\", \"for\", \"ailuj\"])== 2\n\"\"\"\n",
2351
+ solution: "\ndef count_reverse_pairs(test_list):\n return sum(test_list[i+1:].count(s[::-1]) for i, s in enumerate(test_list))\n"
2352
+ },
2353
+ {
2354
+ assertions: "\nassert unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]] )=={(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1}\nassert unique_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']])=={('green', 'orange'): 2, ('black',): 1, ('white',): 1}\nassert unique_sublists([[10, 20, 30, 40], [60, 70, 50, 50], [90, 100, 200]])=={(10, 20, 30, 40): 1, (60, 70, 50, 50): 1, (90, 100, 200): 1}\nassert unique_sublists([['john']])=={('john',): 1}\n",
2355
+ entryPoint: "unique_sublists",
2356
+ id: "Mbpp/758",
2357
+ prompt: "\"\"\"\nWrite a function to count lists within a list. The function should return a dictionary where every list is converted to a tuple and the value of such tuple is the number of its occurencies in the original list.\nassert unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]] )=={(1, 3): 2, (5, 7): 2, (13, 15, 17): 1, (9, 11): 1}\n\"\"\"\n",
2358
+ solution: "\ndef unique_sublists(list1):\n return {tuple(x): list1.count(x) for x in list1}\n"
2359
+ },
2360
+ {
2361
+ assertions: "\nassert is_decimal('123.11')==True\nassert is_decimal('e666.86')==False\nassert is_decimal('3.124587')==False\nassert is_decimal('1.11')==True\nassert is_decimal('1.1.11')==False\n",
2362
+ entryPoint: "is_decimal",
2363
+ id: "Mbpp/759",
2364
+ prompt: "\"\"\"\nWrite a function to check whether a given string is a decimal number with a precision of 2.\nassert is_decimal('123.11')==True\n\"\"\"\n",
2365
+ solution: "\ndef is_decimal(num):\n import re\n dnumre = re.compile(r\"\"\"^[0-9]+(\\.[0-9]{1,2})?$\"\"\")\n return dnumre.search(num) is not None\n"
2366
+ },
2367
+ {
2368
+ assertions: "\nassert unique_Element([1,1,1]) == True\nassert unique_Element([1,2,1,2]) == False\nassert unique_Element([1,2,3,4,5]) == False\n",
2369
+ entryPoint: "unique_Element",
2370
+ id: "Mbpp/760",
2371
+ prompt: "\"\"\"\nWrite a python function to check whether a list of numbers contains only one distinct element or not.\nassert unique_Element([1,1,1]) == True\n\"\"\"\n",
2372
+ solution: "\ndef unique_Element(arr):\n return arr.count(arr[0]) == len(arr)\n"
2373
+ },
2374
+ {
2375
+ assertions: "\nassert check_monthnumber_number(6)==True\nassert check_monthnumber_number(2)==False\nassert check_monthnumber_number(12)==False\n",
2376
+ entryPoint: "check_monthnumber_number",
2377
+ id: "Mbpp/762",
2378
+ prompt: "\"\"\"\nWrite a function to check whether the given month number contains 30 days or not. Months are given as number from 1 to 12.\nassert check_monthnumber_number(6)==True\n\"\"\"\n",
2379
+ solution: "\ndef check_monthnumber_number(monthnum3):\n return monthnum3==4 or monthnum3==6 or monthnum3==9 or monthnum3==11\n"
2380
+ },
2381
+ {
2382
+ assertions: "\nassert find_min_diff((1,5,3,19,18,25),6) == 1\nassert find_min_diff((4,3,2,6),4) == 1\nassert find_min_diff((30,5,20,9),4) == 4\n",
2383
+ entryPoint: "find_min_diff",
2384
+ id: "Mbpp/763",
2385
+ prompt: "\"\"\"\nWrite a python function to find the minimum difference between any two elements in a given array. \nassert find_min_diff((1,5,3,19,18,25),6) == 1\n\"\"\"\n",
2386
+ solution: "\ndef find_min_diff(arr,n): \n arr = sorted(arr) \n diff = 10**20 \n for i in range(n-1): \n if arr[i+1] - arr[i] < diff: \n diff = arr[i+1] - arr[i] \n return diff \n"
2387
+ },
2388
+ {
2389
+ assertions: "\nassert number_ctr('program2bedone') == 1\nassert number_ctr('3wonders') == 1\nassert number_ctr('123') == 3\nassert number_ctr('3wond-1ers2') == 3\n",
2390
+ entryPoint: "number_ctr",
2391
+ id: "Mbpp/764",
2392
+ prompt: "\"\"\"\nWrite a python function to count number of digits in a given string.\nassert number_ctr('program2bedone') == 1\n\"\"\"\n",
2393
+ solution: "\ndef number_ctr(s):\n return sum(c.isdigit() for c in s)\n"
2394
+ },
2395
+ {
2396
+ assertions: "\nassert is_polite(7) == 11\nassert is_polite(4) == 7\nassert is_polite(9) == 13\n",
2397
+ entryPoint: "is_polite",
2398
+ id: "Mbpp/765",
2399
+ prompt: "\"\"\"\nWrite a function to find nth polite number. geeksforgeeks.org/n-th-polite-number/\nassert is_polite(7) == 11\n\"\"\"\n",
2400
+ solution: "\nimport math \ndef is_polite(n): \n\tn = n + 1\n\treturn (int)(n+(math.log((n + math.log(n, 2)), 2))) \n"
2401
+ },
2402
+ {
2403
+ assertions: "\nassert pair_wise([1,1,2,3,3,4,4,5])==[(1, 1), (1, 2), (2, 3), (3, 3), (3, 4), (4, 4), (4, 5)]\nassert pair_wise([1,5,7,9,10])==[(1, 5), (5, 7), (7, 9), (9, 10)]\nassert pair_wise([5,1,9,7,10])==[(5, 1), (1, 9), (9, 7), (7, 10)]\nassert pair_wise([1,2,3,4,5,6,7,8,9,10])==[(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9), (9, 10)]\n",
2404
+ entryPoint: "pair_wise",
2405
+ id: "Mbpp/766",
2406
+ prompt: "\"\"\"\nWrite a function to return a list of all pairs of consecutive items in a given list.\nassert pair_wise([1,1,2,3,3,4,4,5])==[(1, 1), (1, 2), (2, 3), (3, 3), (3, 4), (4, 4), (4, 5)]\n\"\"\"\n",
2407
+ solution: "\ndef pair_wise(l1):\n return list(zip(l1, l1[1:]))\n"
2408
+ },
2409
+ {
2410
+ assertions: "\nassert get_pairs_count([1,1,1,1],2) == 6\nassert get_pairs_count([1,5,7,-1,5],6) == 3\nassert get_pairs_count([1,-2,3],1) == 1\nassert get_pairs_count([-1,-2,3],-3) == 1\n",
2411
+ entryPoint: "get_pairs_count",
2412
+ id: "Mbpp/767",
2413
+ prompt: "\"\"\"\nWrite 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,\nassert get_pairs_count([1,1,1,1],2) == 6\n\"\"\"\n",
2414
+ solution: "\ndef get_pairs_count(arr, sum_):\n cnt = 0\n for n in arr:\n cnt += arr.count(sum_ - n)\n if sum_ - n == n:\n cnt -= 1\n return cnt / 2\n"
2415
+ },
2416
+ {
2417
+ assertions: "\nassert (Diff([10, 15, 20, 25, 30, 35, 40], [25, 40, 35])) == [10, 20, 30, 15]\nassert (Diff([1,2,3,4,5], [6,7,1])) == [2,3,4,5,6,7]\nassert (Diff([1,2,3], [6,7,1])) == [2,3,6,7]\n",
2418
+ entryPoint: "Diff",
2419
+ id: "Mbpp/769",
2420
+ prompt: "\"\"\"\nWrite a python function to get the difference between two lists.\nassert (Diff([10, 15, 20, 25, 30, 35, 40], [25, 40, 35])) == [10, 20, 30, 15]\n\"\"\"\n",
2421
+ solution: "\ndef Diff(li1,li2):\n return list(set(li1)-set(li2)) + list(set(li2)-set(li1))\n \n"
2422
+ },
2423
+ {
2424
+ assertions: "\nassert odd_num_sum(2) == 82\nassert odd_num_sum(3) == 707\nassert odd_num_sum(4) == 3108\n",
2425
+ entryPoint: "odd_num_sum",
2426
+ id: "Mbpp/770",
2427
+ prompt: "\"\"\"\nWrite a python function to find the sum of fourth power of first n odd natural numbers.\nassert odd_num_sum(2) == 82\n\"\"\"\n",
2428
+ solution: "\ndef odd_num_sum(n) : \n j = 0\n sm = 0\n for i in range(1,n + 1) : \n j = (2*i-1) \n sm = sm + (j*j*j*j) \n return sm \n"
2429
+ },
2430
+ {
2431
+ assertions: "\nassert check_expression(\"{()}[{}]\") == True\nassert check_expression(\"{()}[{]\") == False\nassert check_expression(\"{()}[{}][]({})\") == True\n",
2432
+ entryPoint: "check_expression",
2433
+ id: "Mbpp/771",
2434
+ prompt: "\"\"\"\nWrite a function to check if the given expression is balanced or not. \nassert check_expression(\"{()}[{}]\") == True\n\"\"\"\n",
2435
+ solution: "\nfrom collections import deque\ndef check_expression(exp):\n if len(exp) == 0 or len(exp) % 2 == 1:\n return False\n stack = deque()\n for ch in exp:\n if ch == '(' or ch == '{' or ch == '[':\n stack.append(ch)\n if ch == ')' or ch == '}' or ch == ']':\n if not stack:\n return False\n top = stack.pop()\n if (top == '(' and ch != ')') or (top == '{' and ch != '}' or (top == '[' and ch != ']')):\n return False\n return not stack\n"
2436
+ },
2437
+ {
2438
+ assertions: "\nassert remove_length('The person is most value tet', 3) == 'person is most value'\nassert remove_length('If you told me about this ok', 4) == 'If you me about ok'\nassert remove_length('Forces of darkeness is come into the play', 4) == 'Forces of darkeness is the'\n",
2439
+ entryPoint: "remove_length",
2440
+ id: "Mbpp/772",
2441
+ prompt: "\"\"\"\nWrite a function to remove all the words with k length in the given string.\nassert remove_length('The person is most value tet', 3) == 'person is most value'\n\"\"\"\n",
2442
+ solution: "\ndef remove_length(test_str, K):\n return ' '.join([i for i in test_str.split() if len(i) != K])\n"
2443
+ },
2444
+ {
2445
+ assertions: "\nassert occurance_substring('python programming, python language','python')==('python', 0, 6)\nassert occurance_substring('python programming,programming language','programming')==('programming', 7, 18)\nassert occurance_substring('python programming,programming language','language')==('language', 31, 39)\nassert occurance_substring('c++ programming, c++ language','python')==None\n",
2446
+ entryPoint: "occurance_substring",
2447
+ id: "Mbpp/773",
2448
+ prompt: "\"\"\"\nWrite a function to find the occurrence and position of the substrings within a string. Return None if there is no match.\nassert occurance_substring('python programming, python language','python')==('python', 0, 6)\n\"\"\"\n",
2449
+ solution: "\nimport re\ndef occurance_substring(text,pattern):\n for match in re.finditer(pattern, text):\n s = match.start()\n e = match.end()\n return (text[s:e], s, e)\n return None\n"
2450
+ },
2451
+ {
2452
+ assertions: "\nassert odd_position([2,1,4,3,6,7,6,3]) == True\nassert odd_position([4,1,2]) == True\nassert odd_position([1,2,3]) == False\n",
2453
+ entryPoint: "odd_position",
2454
+ id: "Mbpp/775",
2455
+ prompt: "\"\"\"\nWrite a python function to check whether every odd index contains odd numbers of a given list.\nassert odd_position([2,1,4,3,6,7,6,3]) == True\n\"\"\"\n",
2456
+ solution: "\ndef odd_position(nums):\n\treturn all(n % 2 == 1 for n in nums[1::2])\n"
2457
+ },
2458
+ {
2459
+ assertions: "\nassert find_sum([1,2,3,1,1,4,5,6]) == 21\nassert find_sum([1,10,9,4,2,10,10,45,4]) == 71\nassert find_sum([12,10,9,45,2,10,10,45,10]) == 78\n",
2460
+ entryPoint: "find_sum",
2461
+ id: "Mbpp/777",
2462
+ prompt: "\"\"\"\nWrite a python function to find the sum of non-repeated elements in a given list.\nassert find_sum([1,2,3,1,1,4,5,6]) == 21\n\"\"\"\n",
2463
+ solution: "\ndef find_sum(arr): \n return sum(set(arr))\n"
2464
+ },
2465
+ {
2466
+ assertions: "\nassert pack_consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4])==[[0, 0], [1], [2], [3], [4, 4], [5], [6, 6, 6], [7], [8], [9], [4, 4]]\nassert pack_consecutive_duplicates([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10])==[[10, 10], [15], [19], [18, 18], [17], [26, 26], [17], [18], [10]]\nassert pack_consecutive_duplicates(['a', 'a', 'b', 'c', 'd', 'd'])==[['a', 'a'], ['b'], ['c'], ['d', 'd']]\n",
2467
+ entryPoint: "pack_consecutive_duplicates",
2468
+ id: "Mbpp/778",
2469
+ prompt: "\"\"\"\nWrite a function to pack consecutive duplicates of a given list elements into sublists.\nassert pack_consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4])==[[0, 0], [1], [2], [3], [4, 4], [5], [6, 6, 6], [7], [8], [9], [4, 4]]\n\"\"\"\n",
2470
+ solution: "\nfrom itertools import groupby\ndef pack_consecutive_duplicates(list1):\n return [list(group) for _, group in groupby(list1)]\n"
2471
+ },
2472
+ {
2473
+ assertions: "\nassert find_combinations([(1, 2, 3), (3, 4, 5)]) == [(4, 6, 8)]\nassert find_combinations([(2, 4), (6, 7), (5, 1), (6, 10)]) == [(8, 11), (7, 5), (8, 14), (11, 8), (12, 17), (11, 11)]\nassert find_combinations([(3, 5), (7, 8), (6, 2), (7, 11)]) == [(10, 13), (9, 7), (10, 16), (13, 10), (14, 19), (13, 13)]\nassert find_combinations([(4, 6), (8, 9), (7, 3), (8, 12)]) == [(12, 15), (11, 9), (12, 18), (15, 12), (16, 21), (15, 15)]\n",
2474
+ entryPoint: "find_combinations",
2475
+ id: "Mbpp/780",
2476
+ prompt: "\"\"\"\nWrite a function to find the combinations of sums with tuples in the given tuple list. \nassert find_combinations([(2, 4), (6, 7), (5, 1), (6, 10)]) == [(8, 11), (7, 5), (8, 14), (11, 8), (12, 17), (11, 11)]\n\"\"\"\n",
2477
+ solution: "\nfrom itertools import combinations \ndef find_combinations(test_list):\n return [tuple(map(sum, zip(*t))) for t in combinations(test_list, 2)]\n"
2478
+ },
2479
+ {
2480
+ assertions: "\nassert count_divisors(10)\nassert not count_divisors(100)\nassert count_divisors(125)\n",
2481
+ entryPoint: "count_divisors",
2482
+ id: "Mbpp/781",
2483
+ prompt: "\"\"\"\nWrite a python function to check whether the count of divisors is even. \nassert count_divisors(10)\n\"\"\"\n",
2484
+ solution: "\nimport math \ndef count_divisors(n) : \n cnt = 0\n for i in range(1, (int)(math.sqrt(n)) + 1) : \n if (n % i == 0) : \n if (n / i == i) : \n cnt = cnt + 1\n else : \n cnt = cnt + 2\n return cnt % 2 == 0\n"
2485
+ },
2486
+ {
2487
+ assertions: "\nassert odd_length_sum([1,2,4]) == 14\nassert odd_length_sum([1,2,1,2]) == 15\nassert odd_length_sum([1,7]) == 8\n",
2488
+ entryPoint: "odd_length_sum",
2489
+ id: "Mbpp/782",
2490
+ prompt: "\"\"\"\nWrite a python function to find the sum of all odd length subarrays. \nassert odd_length_sum([1,2,4]) == 14\n\"\"\"\n",
2491
+ solution: "\ndef odd_length_sum(arr):\n sum_ = 0\n n = len(arr)\n for i in range(n):\n # arr[i] occurs (i + 1) * (n - i) times in all subarrays\n times = ((i + 1) * (n - i) + 1) // 2\n sum_ += arr[i] * times\n return sum_\n"
2492
+ },
2493
+ {
2494
+ assertions: "\nassert mul_even_odd([1,3,5,7,4,1,6,8])==4\nassert mul_even_odd([1,2,3,4,5,6,7,8,9,10])==2\nassert mul_even_odd([1,5,7,9,10])==10\n",
2495
+ entryPoint: "mul_even_odd",
2496
+ id: "Mbpp/784",
2497
+ prompt: "\"\"\"\nWrite a function to find the product of first even and odd number of a given list.\nassert mul_even_odd([1,3,5,7,4,1,6,8])==4\n\"\"\"\n",
2498
+ solution: "\ndef mul_even_odd(list1):\n first_even = next((el for el in list1 if el%2==0),-1)\n first_odd = next((el for el in list1 if el%2!=0),-1)\n return (first_even*first_odd)\n"
2499
+ },
2500
+ {
2501
+ assertions: "\nassert tuple_str_int(\"(7, 8, 9)\") == (7, 8, 9)\nassert tuple_str_int(\"(1, 2, 3)\") == (1, 2, 3)\nassert tuple_str_int(\"(4, 5, 6)\") == (4, 5, 6)\nassert tuple_str_int(\"(7, 81, 19)\") == (7, 81, 19)\n",
2502
+ entryPoint: "tuple_str_int",
2503
+ id: "Mbpp/785",
2504
+ prompt: "\"\"\"\nWrite a function to convert tuple string to integer tuple.\nassert tuple_str_int(\"(7, 8, 9)\") == (7, 8, 9)\n\"\"\"\n",
2505
+ solution: "\ndef tuple_str_int(test_str):\n return tuple(int(num) for num in test_str.replace('(', '').replace(')', '').replace('...', '').split(', '))\n"
2506
+ },
2507
+ {
2508
+ assertions: "\nassert right_insertion([1,2,4,5],6)==4\nassert right_insertion([1,2,4,5],3)==2\nassert right_insertion([1,2,4,5],7)==4\n",
2509
+ entryPoint: "right_insertion",
2510
+ id: "Mbpp/786",
2511
+ prompt: "\"\"\"\nWrite a function to locate the right insertion point for a specified value in sorted order.\nassert right_insertion([1,2,4,5],6)==4\n\"\"\"\n",
2512
+ solution: "\nimport bisect\ndef right_insertion(a, x):\n return bisect.bisect_right(a, x)\n"
2513
+ },
2514
+ {
2515
+ assertions: "\nassert not text_match_three(\"ac\")\nassert not text_match_three(\"dc\")\nassert text_match_three(\"abbbba\")\nassert text_match_three(\"caacabbbba\")\n",
2516
+ entryPoint: "text_match_three",
2517
+ id: "Mbpp/787",
2518
+ prompt: "\"\"\"\nWrite a function that matches a string that has an a followed by three 'b'.\nassert not text_match_three(\"ac\")\n\"\"\"\n",
2519
+ solution: "\nimport re\ndef text_match_three(text):\n patterns = 'ab{3}?'\n return re.search(patterns, text)\n"
2520
+ },
2521
+ {
2522
+ assertions: "\nassert new_tuple([\"WEB\", \"is\"], \"best\") == ('WEB', 'is', 'best')\nassert new_tuple([\"We\", \"are\"], \"Developers\") == ('We', 'are', 'Developers')\nassert new_tuple([\"Part\", \"is\"], \"Wrong\") == ('Part', 'is', 'Wrong')\n",
2523
+ entryPoint: "new_tuple",
2524
+ id: "Mbpp/788",
2525
+ prompt: "\"\"\"\nWrite a function to create a new tuple from the given string and list.\nassert new_tuple([\"WEB\", \"is\"], \"best\") == ('WEB', 'is', 'best')\n\"\"\"\n",
2526
+ solution: "\ndef new_tuple(test_list, test_str):\n return tuple(test_list + [test_str])\n"
2527
+ },
2528
+ {
2529
+ assertions: "\nassert even_position([3,2,1]) == False\nassert even_position([1,2,3]) == False\nassert even_position([2,1,4]) == True\n",
2530
+ entryPoint: "even_position",
2531
+ id: "Mbpp/790",
2532
+ prompt: "\"\"\"\nWrite a python function to check whether every even index contains even numbers of a given list.\nassert even_position([3,2,1]) == False\n\"\"\"\n",
2533
+ solution: "\ndef even_position(nums):\n\treturn all(nums[i]%2==i%2 for i in range(len(nums)))\n"
2534
+ },
2535
+ {
2536
+ assertions: "\nassert remove_nested((1, 5, 7, (4, 6), 10)) == (1, 5, 7, 10)\nassert remove_nested((2, 6, 8, (5, 7), 11)) == (2, 6, 8, 11)\nassert remove_nested((3, 7, 9, (6, 8), 12)) == (3, 7, 9, 12)\nassert remove_nested((3, 7, 9, (6, 8), (5,12), 12)) == (3, 7, 9, 12)\n",
2537
+ entryPoint: "remove_nested",
2538
+ id: "Mbpp/791",
2539
+ prompt: "\"\"\"\nWrite a function to remove tuples from the given tuple.\nassert remove_nested((1, 5, 7, (4, 6), 10)) == (1, 5, 7, 10)\n\"\"\"\n",
2540
+ solution: "\ndef remove_nested(test_tup):\n return tuple(e for e in test_tup if not isinstance(e, tuple))\n"
2541
+ },
2542
+ {
2543
+ assertions: "\nassert count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]]) == 4\nassert count_list([[1,2],[2,3],[4,5]]) == 3\nassert count_list([[1,0],[2,0]]) == 2\n",
2544
+ entryPoint: "count_list",
2545
+ id: "Mbpp/792",
2546
+ prompt: "\"\"\"\nWrite a python function to count the number of lists in a given number of lists.\nassert count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]]) == 4\n\"\"\"\n",
2547
+ solution: "\ndef count_list(input_list): \n return sum(isinstance(e, list) for e in input_list)\n"
2548
+ },
2549
+ {
2550
+ assertions: "\nassert last([1,2,3],1) == 0\nassert last([1,1,1,2,3,4],1) == 2\nassert last([2,2,3,3,6,8,9],3) == 3\n",
2551
+ entryPoint: "last",
2552
+ id: "Mbpp/793",
2553
+ prompt: "\"\"\"\nWrite a python function to find the last position of an element in a sorted array.\nassert last([1,2,3],1) == 0\n\"\"\"\n",
2554
+ solution: "\ndef last(arr,x):\n return len(arr)-arr[::-1].index(x) - 1\n"
2555
+ },
2556
+ {
2557
+ assertions: "\nassert text_starta_endb(\"aabbbb\")\nassert not text_starta_endb(\"aabAbbbc\")\nassert not text_starta_endb(\"accddbbjjj\")\n",
2558
+ entryPoint: "text_starta_endb",
2559
+ id: "Mbpp/794",
2560
+ prompt: "\"\"\"\nWrite a function that matches a string that has an 'a' followed by anything, ending in 'b'.\nassert text_starta_endb(\"aabbbb\")\n\"\"\"\n",
2561
+ solution: "\nimport re\ndef text_starta_endb(text):\n patterns = 'a.*?b$'\n return re.search(patterns, text)\n"
2562
+ },
2563
+ {
2564
+ assertions: "\nassert return_sum({'a': 100, 'b':200, 'c':300}) == 600\nassert return_sum({'a': 25, 'b':18, 'c':45}) == 88\nassert return_sum({'a': 36, 'b':39, 'c':49}) == 124\n",
2565
+ entryPoint: "return_sum",
2566
+ id: "Mbpp/796",
2567
+ prompt: "\"\"\"\nWrite function to find the sum of all items in the given dictionary.\nassert return_sum({'a': 100, 'b':200, 'c':300}) == 600\n\"\"\"\n",
2568
+ solution: "\ndef return_sum(d):\n return sum(d.values())\n"
2569
+ },
2570
+ {
2571
+ assertions: "\nassert sum_in_range(2,5) == 8\nassert sum_in_range(5,7) == 12\nassert sum_in_range(7,13) == 40\n",
2572
+ entryPoint: "sum_in_range",
2573
+ id: "Mbpp/797",
2574
+ prompt: "\"\"\"\nWrite a python function to find the sum of all odd natural numbers within the range l and r.\nassert sum_in_range(2,5) == 8\n\"\"\"\n",
2575
+ solution: "\ndef sum_odd(n): \n terms = (n + 1) // 2\n sum1 = terms * terms \n return sum1 \ndef sum_in_range(l,r): \n return sum_odd(r) - sum_odd(l - 1)\n"
2576
+ },
2577
+ {
2578
+ assertions: "\nassert _sum([1, 2, 3]) == 6\nassert _sum([15, 12, 13, 10]) == 50\nassert _sum([0, 1, 2]) == 3\n",
2579
+ entryPoint: "_sum",
2580
+ id: "Mbpp/798",
2581
+ prompt: "\"\"\"\nWrite a python function to find the sum of an array.\nassert _sum([1, 2, 3]) == 6\n\"\"\"\n",
2582
+ solution: "\ndef _sum(arr): \n return sum(arr)\n"
2583
+ },
2584
+ {
2585
+ assertions: "\nassert left_rotate(16,2) == 64\nassert left_rotate(10,2) == 40\nassert left_rotate(99,3) == 792\nassert left_rotate(99,3) == 792\nassert left_rotate(0b0001,3) == 0b1000\nassert left_rotate(0b0101,3) == 0b101000\nassert left_rotate(0b11101,3) == 0b11101000\n",
2586
+ entryPoint: "left_rotate",
2587
+ id: "Mbpp/799",
2588
+ prompt: "\"\"\"\nWrite a function to that rotate left bits by d bits a given number. We assume that the number is 32 bit.\nassert left_rotate(16,2) == 64\n\"\"\"\n",
2589
+ solution: "\ndef left_rotate(n,d): \n INT_BITS = 32\n return (n << d)|(n >> (INT_BITS - d)) \n"
2590
+ },
2591
+ {
2592
+ assertions: "\nassert remove_all_spaces('python program')==('pythonprogram')\nassert remove_all_spaces('python programming language')==('pythonprogramminglanguage')\nassert remove_all_spaces('python program')==('pythonprogram')\nassert remove_all_spaces(' python program')=='pythonprogram'\n",
2593
+ entryPoint: "remove_all_spaces",
2594
+ id: "Mbpp/800",
2595
+ prompt: "\"\"\"\nWrite a function to remove all whitespaces from a string.\nassert remove_all_spaces('python program')==('pythonprogram')\n\"\"\"\n",
2596
+ solution: "\ndef remove_all_spaces(text):\n return text.replace(' ', '')\n"
2597
+ },
2598
+ {
2599
+ assertions: "\nassert test_three_equal(1,1,1) == 3\nassert test_three_equal(-1,-2,-3) == 0\nassert test_three_equal(1,2,2) == 2\n",
2600
+ entryPoint: "test_three_equal",
2601
+ id: "Mbpp/801",
2602
+ prompt: "\"\"\"\nWrite a python function to count the number of equal numbers from three given integers.\nassert test_three_equal(1,1,1) == 3\n\"\"\"\n",
2603
+ solution: "\ndef test_three_equal(x,y,z):\n result = set([x,y,z])\n if len(result) == 3:\n return 0\n elif len(result) == 2:\n return 2\n else:\n return 3\n"
2604
+ },
2605
+ {
2606
+ assertions: "\nassert not is_perfect_square(10)\nassert is_perfect_square(36)\nassert not is_perfect_square(14)\nassert is_perfect_square(14*14)\nassert not is_perfect_square(125)\nassert is_perfect_square(125*125)\n",
2607
+ entryPoint: "is_perfect_square",
2608
+ id: "Mbpp/803",
2609
+ prompt: "\"\"\"\nWrite a function to check whether the given number is a perfect square or not. \nassert not is_perfect_square(10)\n\"\"\"\n",
2610
+ solution: "\ndef is_perfect_square(n) :\n if n < 0:\n return False\n return n**(1/2) == int(n**(1/2))\n"
2611
+ },
2612
+ {
2613
+ assertions: "\nassert is_product_even([1,2,3])\nassert is_product_even([1,2,1,4])\nassert not is_product_even([1,1])\n",
2614
+ entryPoint: "is_product_even",
2615
+ id: "Mbpp/804",
2616
+ prompt: "\"\"\"\nWrite a function to check whether the product of numbers in a list is even or not.\nassert is_product_even([1,2,3])\n\"\"\"\n",
2617
+ solution: "\ndef is_product_even(arr): \n return any(x % 2 == 0 for x in arr)\n"
2618
+ },
2619
+ {
2620
+ assertions: "\nassert max_sum_list([[1,2,3], [4,5,6], [10,11,12], [7,8,9]])==[10, 11, 12]\nassert max_sum_list([[3,2,1], [6,5,4], [12,11,10]])==[12,11,10]\nassert max_sum_list([[2,3,1]])==[2,3,1]\n",
2621
+ entryPoint: "max_sum_list",
2622
+ id: "Mbpp/805",
2623
+ prompt: "\"\"\"\nWrite a function that returns the list in a list of lists whose sum of elements is the highest.\nassert max_sum_list([[1,2,3], [4,5,6], [10,11,12], [7,8,9]])==[10, 11, 12]\n\"\"\"\n",
2624
+ solution: "\ndef max_sum_list(lists):\n return max(lists, key=sum)\n"
2625
+ },
2626
+ {
2627
+ assertions: "\nassert max_run_uppercase('GeMKSForGERksISBESt') == 5\nassert max_run_uppercase('PrECIOusMOVemENTSYT') == 6\nassert max_run_uppercase('GooGLEFluTTER') == 4\n",
2628
+ entryPoint: "max_run_uppercase",
2629
+ id: "Mbpp/806",
2630
+ prompt: "\"\"\"\nWrite a function to find maximum run of uppercase characters in the given string.\nassert max_run_uppercase('GeMKSForGERksISBESt') == 5\n\"\"\"\n",
2631
+ solution: "\ndef max_run_uppercase(test_str):\n cnt = 0\n res = 0\n for idx in range(0, len(test_str)):\n if test_str[idx].isupper():\n cnt += 1\n else:\n res = cnt\n cnt = 0\n if test_str[len(test_str) - 1].isupper():\n res = cnt\n return res\n"
2632
+ },
2633
+ {
2634
+ assertions: "\nassert first_odd([1,3,5]) == 1\nassert first_odd([2,4,1,3]) == 1\nassert first_odd ([8,9,1]) == 9\n",
2635
+ entryPoint: "first_odd",
2636
+ id: "Mbpp/807",
2637
+ prompt: "\"\"\"\nWrite a python function to find the first odd number in a given list of numbers.\nassert first_odd([1,3,5]) == 1\n\"\"\"\n",
2638
+ solution: "\ndef first_odd(nums):\n first_odd = next((el for el in nums if el%2!=0), None)\n return first_odd\n"
2639
+ },
2640
+ {
2641
+ assertions: "\nassert check_K((10, 4, 5, 6, 8), 6) == True\nassert check_K((1, 2, 3, 4, 5, 6), 7) == False\nassert check_K((7, 8, 9, 44, 11, 12), 11) == True\n",
2642
+ entryPoint: "check_K",
2643
+ id: "Mbpp/808",
2644
+ prompt: "\"\"\"\nWrite a function to check if the given tuples contain the k or not.\nassert check_K((10, 4, 5, 6, 8), 6) == True\n\"\"\"\n",
2645
+ solution: "\ndef check_K(test_tup, K):\n return K in test_tup\n"
2646
+ },
2647
+ {
2648
+ assertions: "\nassert check_smaller((1, 2, 3), (2, 3, 4)) == False\nassert check_smaller((4, 5, 6), (3, 4, 5)) == True\nassert check_smaller((11, 12, 13), (10, 11, 12)) == True\n",
2649
+ entryPoint: "check_smaller",
2650
+ id: "Mbpp/809",
2651
+ prompt: "\"\"\"\nWrite a function to check if each element of second tuple is smaller than its corresponding element in the first tuple.\nassert check_smaller((1, 2, 3), (2, 3, 4)) == False\n\"\"\"\n",
2652
+ solution: "\ndef check_smaller(test_tup1, test_tup2):\n return all(x > y for x, y in zip(test_tup1, test_tup2))\n"
2653
+ }
2654
+ ];
2655
+
2656
+ export { mbppplus as default };