File size: 209,408 Bytes
e3077c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
{"input": "Write a function to find the longest chain which can be formed from the given set of pairs.", "answer": "class Pair(object): \r\n\tdef __init__(self, a, b): \r\n\t\tself.a = a \r\n\t\tself.b = b \r\ndef max_chain_length(arr, n): \r\n\tmax = 0\r\n\tmcl = [1 for i in range(n)] \r\n\tfor i in range(1, n): \r\n\t\tfor j in range(0, i): \r\n\t\t\tif (arr[i].a > arr[j].b and\r\n\t\t\t\tmcl[i] < mcl[j] + 1): \r\n\t\t\t\tmcl[i] = mcl[j] + 1\r\n\tfor i in range(n): \r\n\t\tif (max < mcl[i]): \r\n\t\t\tmax = mcl[i] \r\n\treturn max", "source": "mbpp", "task_id": "601", "test_cases": "assert max_chain_length([Pair(5, 24), Pair(15, 25),Pair(27, 40), Pair(50, 60)], 4) == 3\nassert max_chain_length([Pair(1, 2), Pair(3, 4),Pair(5, 6), Pair(7, 8)], 4) == 4\nassert max_chain_length([Pair(19, 10), Pair(11, 12),Pair(13, 14), Pair(15, 16), Pair(31, 54)], 5) == 5", "difficulty": "code"}
{"input": "Write a python function to find the first repeated character in a given string.", "answer": "def first_repeated_char(str1):\r\n  for index,c in enumerate(str1):\r\n    if str1[:index+1].count(c) > 1:\r\n      return c \r\n  return \"None\"", "source": "mbpp", "task_id": "602", "test_cases": "assert first_repeated_char(\"abcabc\") == \"a\"\nassert first_repeated_char(\"abc\") == \"None\"\nassert first_repeated_char(\"123123\") == \"1\"", "difficulty": "code"}
{"input": "Write a function to get a lucid number smaller than or equal to n.", "answer": "def get_ludic(n):\r\n\tludics = []\r\n\tfor i in range(1, n + 1):\r\n\t\tludics.append(i)\r\n\tindex = 1\r\n\twhile(index != len(ludics)):\r\n\t\tfirst_ludic = ludics[index]\r\n\t\tremove_index = index + first_ludic\r\n\t\twhile(remove_index < len(ludics)):\r\n\t\t\tludics.remove(ludics[remove_index])\r\n\t\t\tremove_index = remove_index + first_ludic - 1\r\n\t\tindex += 1\r\n\treturn ludics", "source": "mbpp", "task_id": "603", "test_cases": "assert 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]", "difficulty": "code"}
{"input": "Write a function to reverse words in a given string.", "answer": "def reverse_words(s):\r\n        return ' '.join(reversed(s.split()))", "source": "mbpp", "task_id": "604", "test_cases": "assert reverse_words(\"python program\")==(\"program python\")\nassert reverse_words(\"java language\")==(\"language java\")\nassert reverse_words(\"indian man\")==(\"man indian\")", "difficulty": "code"}
{"input": "Write a function to check if the given integer is a prime number.", "answer": "def prime_num(num):\r\n  if num >=1:\r\n   for i in range(2, num//2):\r\n     if (num % i) == 0:\r\n                return False\r\n     else:\r\n                return True\r\n  else:\r\n          return False", "source": "mbpp", "task_id": "605", "test_cases": "assert prime_num(13)==True\nassert prime_num(7)==True\nassert prime_num(-1010)==False", "difficulty": "code"}
{"input": "Write a function to convert degrees to radians.", "answer": "import math\r\ndef radian_degree(degree):\r\n radian = degree*(math.pi/180)\r\n return radian", "source": "mbpp", "task_id": "606", "test_cases": "assert radian_degree(90)==1.5707963267948966\nassert radian_degree(60)==1.0471975511965976\nassert radian_degree(120)==2.0943951023931953", "difficulty": "code"}
{"input": "Write a function to search a literals string in a string and also find the location within the original string where the pattern occurs by using regex.", "answer": "import re\r\npattern = 'fox'\r\ntext = 'The quick brown fox jumps over the lazy dog.'\r\ndef find_literals(text, pattern):\r\n  match = re.search(pattern, text)\r\n  s = match.start()\r\n  e = match.end()\r\n  return (match.re.pattern, s, e)", "source": "mbpp", "task_id": "607", "test_cases": "assert 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)", "difficulty": "code"}
{"input": "Write a python function to find nth bell number.", "answer": "def bell_Number(n): \r\n    bell = [[0 for i in range(n+1)] for j in range(n+1)] \r\n    bell[0][0] = 1\r\n    for i in range(1, n+1):\r\n        bell[i][0] = bell[i-1][i-1]\r\n        for j in range(1, i+1): \r\n            bell[i][j] = bell[i-1][j-1] + bell[i][j-1] \r\n    return bell[n][0]", "source": "mbpp", "task_id": "608", "test_cases": "assert bell_Number(2) == 2\nassert bell_Number(3) == 5\nassert bell_Number(4) == 15", "difficulty": "code"}
{"input": "Write a python function to find minimum possible value for the given periodic function.", "answer": "def floor_Min(A,B,N):\r\n    x = max(B - 1,N)\r\n    return (A*x) // B", "source": "mbpp", "task_id": "609", "test_cases": "assert floor_Min(10,20,30) == 15\nassert floor_Min(1,2,1) == 0\nassert floor_Min(11,10,9) == 9", "difficulty": "code"}
{"input": "Write a python function to remove the k'th element from a given list.", "answer": "def remove_kth_element(list1, L):\r\n    return  list1[:L-1] + list1[L:]", "source": "mbpp", "task_id": "610", "test_cases": "assert 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]", "difficulty": "code"}
{"input": "Write a function to find the maximum of nth column from the given tuple list.", "answer": "def max_of_nth(test_list, N):\r\n  res = max([sub[N] for sub in test_list])\r\n  return (res)", "source": "mbpp", "task_id": "611", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a python function to merge the first and last elements separately in a list of lists.", "answer": "def merge(lst):  \r\n    return [list(ele) for ele in list(zip(*lst))]", "source": "mbpp", "task_id": "612", "test_cases": "assert 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([['x', 'y','z' ], ['a', 'b','c'], ['m', 'n','o']]) == [['x', 'a', 'm'], ['y', 'b', 'n'],['z', 'c','o']]", "difficulty": "code"}
{"input": "Write a function to find the maximum value in record list as tuple attribute in the given tuple list.", "answer": "def maximum_value(test_list):\r\n  res = [(key, max(lst)) for key, lst in test_list]\r\n  return (res)", "source": "mbpp", "task_id": "613", "test_cases": "assert maximum_value([('key1', [3, 4, 5]), ('key2', [1, 4, 2]), ('key3', [9, 3])]) == [('key1', 5), ('key2', 4), ('key3', 9)]\nassert maximum_value([('key1', [4, 5, 6]), ('key2', [2, 5, 3]), ('key3', [10, 4])]) == [('key1', 6), ('key2', 5), ('key3', 10)]\nassert maximum_value([('key1', [5, 6, 7]), ('key2', [3, 6, 4]), ('key3', [11, 5])]) == [('key1', 7), ('key2', 6), ('key3', 11)]", "difficulty": "code"}
{"input": "Write a function to find the cumulative sum of all the values that are present in the given tuple list.", "answer": "def cummulative_sum(test_list):\r\n  res = sum(map(sum, test_list))\r\n  return (res)", "source": "mbpp", "task_id": "614", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a function to find average value of the numbers in a given tuple of tuples.", "answer": "def average_tuple(nums):\r\n    result = [sum(x) / len(x) for x in zip(*nums)]\r\n    return result", "source": "mbpp", "task_id": "615", "test_cases": "assert average_tuple(((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4)))==[30.5, 34.25, 27.0, 23.25]\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]", "difficulty": "code"}
{"input": "Write a function to perfom the modulo of tuple elements in the given two tuples.", "answer": "def tuple_modulo(test_tup1, test_tup2):\r\n  res = tuple(ele1 % ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) \r\n  return (res)", "source": "mbpp", "task_id": "616", "test_cases": "assert 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)", "difficulty": "code"}
{"input": "Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane.", "answer": "def min_Jumps(a, b, d): \r\n    temp = a \r\n    a = min(a, b) \r\n    b = max(temp, b) \r\n    if (d >= b): \r\n        return (d + b - 1) / b \r\n    if (d == 0): \r\n        return 0\r\n    if (d == a): \r\n        return 1\r\n    else:\r\n        return 2", "source": "mbpp", "task_id": "617", "test_cases": "assert min_Jumps(3,4,11)==3.5\nassert min_Jumps(3,4,0)==0\nassert min_Jumps(11,14,11)==1", "difficulty": "code"}
{"input": "Write a function to divide two lists using map and lambda function.", "answer": "def div_list(nums1,nums2):\r\n  result = map(lambda x, y: x / y, nums1, nums2)\r\n  return list(result)", "source": "mbpp", "task_id": "618", "test_cases": "assert 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]", "difficulty": "code"}
{"input": "Write a function to move all the numbers in it to the given string.", "answer": "def move_num(test_str):\r\n  res = ''\r\n  dig = ''\r\n  for ele in test_str:\r\n    if ele.isdigit():\r\n      dig += ele\r\n    else:\r\n      res += ele\r\n  res += dig\r\n  return (res)", "source": "mbpp", "task_id": "619", "test_cases": "assert move_num('I1love143you55three3000thousand') == 'Iloveyouthreethousand1143553000'\nassert move_num('Avengers124Assemble') == 'AvengersAssemble124'\nassert move_num('Its11our12path13to14see15things16do17things') == 'Itsourpathtoseethingsdothings11121314151617'", "difficulty": "code"}
{"input": "Write a function to find the largest subset where each pair is divisible.", "answer": "def largest_subset(a, n):\r\n\tdp = [0 for i in range(n)]\r\n\tdp[n - 1] = 1; \r\n\tfor i in range(n - 2, -1, -1):\r\n\t\tmxm = 0;\r\n\t\tfor j in range(i + 1, n):\r\n\t\t\tif a[j] % a[i] == 0 or a[i] % a[j] == 0:\r\n\t\t\t\tmxm = max(mxm, dp[j])\r\n\t\tdp[i] = 1 + mxm\r\n\treturn max(dp)", "source": "mbpp", "task_id": "620", "test_cases": "assert largest_subset([ 1, 3, 6, 13, 17, 18 ], 6) == 4\nassert largest_subset([10, 5, 3, 15, 20], 5) == 3\nassert largest_subset([18, 1, 3, 6, 13, 17], 6) == 4", "difficulty": "code"}
{"input": "Write a function to increment the numeric values in the given strings by k.", "answer": "def increment_numerics(test_list, K):\r\n  res = [str(int(ele) + K) if ele.isdigit() else ele for ele in test_list]\r\n  return res", "source": "mbpp", "task_id": "621", "test_cases": "assert increment_numerics([\"MSM\", \"234\", \"is\", \"98\", \"123\", \"best\", \"4\"] , 6) == ['MSM', '240', 'is', '104', '129', 'best', '10']\nassert increment_numerics([\"Dart\", \"356\", \"is\", \"88\", \"169\", \"Super\", \"6\"] , 12) == ['Dart', '368', 'is', '100', '181', 'Super', '18']\nassert increment_numerics([\"Flutter\", \"451\", \"is\", \"44\", \"96\", \"Magnificent\", \"12\"] , 33) == ['Flutter', '484', 'is', '77', '129', 'Magnificent', '45']", "difficulty": "code"}
{"input": "Write a function to find the median of two sorted arrays of same size.", "answer": "def get_median(arr1, arr2, n):\r\n  i = 0\r\n  j = 0\r\n  m1 = -1\r\n  m2 = -1\r\n  count = 0\r\n  while count < n + 1:\r\n    count += 1\r\n    if i == n:\r\n      m1 = m2\r\n      m2 = arr2[0]\r\n      break\r\n    elif j == n:\r\n      m1 = m2\r\n      m2 = arr1[0]\r\n      break\r\n    if arr1[i] <= arr2[j]:\r\n      m1 = m2\r\n      m2 = arr1[i]\r\n      i += 1\r\n    else:\r\n      m1 = m2\r\n      m2 = arr2[j]\r\n      j += 1\r\n  return (m1 + m2)/2", "source": "mbpp", "task_id": "622", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a function to find the n-th power of individual elements in a list using lambda function.", "answer": "def nth_nums(nums,n):\r\n nth_nums = list(map(lambda x: x ** n, nums))\r\n return nth_nums", "source": "mbpp", "task_id": "623", "test_cases": "assert 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])", "difficulty": "code"}
{"input": "Write a python function to convert the given string to upper case.", "answer": "def is_upper(string):\r\n  return (string.upper())", "source": "mbpp", "task_id": "624", "test_cases": "assert is_upper(\"person\") ==\"PERSON\"\nassert is_upper(\"final\") == \"FINAL\"\nassert is_upper(\"Valid\") == \"VALID\"", "difficulty": "code"}
{"input": "Write a python function to interchange first and last elements in a given list.", "answer": "def swap_List(newList): \r\n    size = len(newList) \r\n    temp = newList[0] \r\n    newList[0] = newList[size - 1] \r\n    newList[size - 1] = temp   \r\n    return newList", "source": "mbpp", "task_id": "625", "test_cases": "assert swap_List([1,2,3]) == [3,2,1]\nassert swap_List([1,2,3,4,4]) == [4,2,3,4,1]\nassert swap_List([4,5,6]) == [6,5,4]", "difficulty": "code"}
{"input": "Write a python function to find the largest triangle that can be inscribed in the semicircle.", "answer": "def triangle_area(r) :  \r\n    if r < 0 : \r\n        return -1\r\n    return r * r", "source": "mbpp", "task_id": "626", "test_cases": "assert triangle_area(0) == 0\nassert triangle_area(-1) == -1\nassert triangle_area(2) == 4", "difficulty": "code"}
{"input": "Write a python function to find the smallest missing number from the given array.", "answer": "def find_First_Missing(array,start,end): \r\n    if (start > end): \r\n        return end + 1\r\n    if (start != array[start]): \r\n        return start; \r\n    mid = int((start + end) / 2) \r\n    if (array[mid] == mid): \r\n        return find_First_Missing(array,mid+1,end) \r\n    return find_First_Missing(array,start,mid)", "source": "mbpp", "task_id": "627", "test_cases": "assert find_First_Missing([0,1,2,3],0,3) == 4\nassert find_First_Missing([0,1,2,6,9],0,4) == 3\nassert find_First_Missing([2,3,5,8,9],0,4) == 0", "difficulty": "code"}
{"input": "Write a function to replace all spaces in the given string with character * list item * list item * list item * list item '%20'.", "answer": "MAX=1000;\r\ndef replace_spaces(string):\r\n  string=string.strip()\r\n  i=len(string)\r\n  space_count=string.count(' ')\r\n  new_length = i + space_count*2\r\n  if new_length > MAX:\r\n    return -1\r\n  index = new_length-1\r\n  string=list(string)\r\n  for f in range(i-2, new_length-2):\r\n    string.append('0')\r\n  for j in range(i-1, 0, -1):\r\n    if string[j] == ' ':\r\n      string[index] = '0'\r\n      string[index-1] = '2'\r\n      string[index-2] = '%'\r\n      index=index-3\r\n    else:\r\n      string[index] = string[j]\r\n      index -= 1\r\n  return ''.join(string)", "source": "mbpp", "task_id": "628", "test_cases": "assert 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'", "difficulty": "code"}
{"input": "Write a python function to find even numbers from a mixed list.", "answer": "def Split(list): \r\n    ev_li = [] \r\n    for i in list: \r\n        if (i % 2 == 0): \r\n            ev_li.append(i)  \r\n    return ev_li", "source": "mbpp", "task_id": "629", "test_cases": "assert 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]", "difficulty": "code"}
{"input": "Write a function to extract all the adjacent coordinates of the given coordinate tuple.", "answer": "def adjac(ele, sub = []): \r\n  if not ele: \r\n     yield sub \r\n  else: \r\n     yield from [idx for j in range(ele[0] - 1, ele[0] + 2) \r\n                for idx in adjac(ele[1:], sub + [j])] \r\ndef get_coordinates(test_tup):\r\n  res = list(adjac(test_tup))\r\n  return (res)", "source": "mbpp", "task_id": "630", "test_cases": "assert 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]]", "difficulty": "code"}
{"input": "Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.", "answer": "import re\r\ntext = 'Python Exercises'\r\ndef replace_spaces(text):\r\n  text =text.replace (\" \", \"_\")\r\n  return (text)\r\n  text =text.replace (\"_\", \" \")\r\n  return (text)", "source": "mbpp", "task_id": "631", "test_cases": "assert replace_spaces('Jumanji The Jungle') == 'Jumanji_The_Jungle'\nassert replace_spaces('The Avengers') == 'The_Avengers'\nassert replace_spaces('Fast and Furious') == 'Fast_and_Furious'", "difficulty": "code"}
{"input": "Write a python function to move all zeroes to the end of the given list.", "answer": "def move_zero(num_list):\r\n    a = [0 for i in range(num_list.count(0))]\r\n    x = [ i for i in num_list if i != 0]\r\n    x.extend(a)\r\n    return (x)", "source": "mbpp", "task_id": "632", "test_cases": "assert 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]", "difficulty": "code"}
{"input": "Write a python function to find the sum of xor of all pairs of numbers in the given array.", "answer": "def pair_OR_Sum(arr,n) : \r\n    ans = 0 \r\n    for i in range(0,n) :    \r\n        for j in range(i + 1,n) :   \r\n            ans = ans + (arr[i] ^ arr[j])          \r\n    return ans", "source": "mbpp", "task_id": "633", "test_cases": "assert pair_OR_Sum([5,9,7,6],4) == 47\nassert pair_OR_Sum([7,3,5],3) == 12\nassert pair_OR_Sum([7,3],2) == 4", "difficulty": "code"}
{"input": "Write a python function to find the sum of fourth power of first n even natural numbers.", "answer": "def even_Power_Sum(n): \r\n    sum = 0; \r\n    for i in range(1,n + 1): \r\n        j = 2*i; \r\n        sum = sum + (j*j*j*j); \r\n    return sum;", "source": "mbpp", "task_id": "634", "test_cases": "assert even_Power_Sum(2) == 272\nassert even_Power_Sum(3) == 1568\nassert even_Power_Sum(4) == 5664", "difficulty": "code"}
{"input": "Write a function to push all values into a heap and then pop off the smallest values one at a time.", "answer": "import heapq as hq\r\ndef heap_sort(iterable):\r\n    h = []\r\n    for value in iterable:\r\n        hq.heappush(h, value)\r\n    return [hq.heappop(h) for i in range(len(h))]", "source": "mbpp", "task_id": "635", "test_cases": "assert 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]", "difficulty": "code"}
{"input": "Write a python function to check if roots of a quadratic equation are reciprocal of each other or not.", "answer": "def Check_Solution(a,b,c): \r\n    if (a == c): \r\n        return (\"Yes\"); \r\n    else: \r\n        return (\"No\");", "source": "mbpp", "task_id": "636", "test_cases": "assert Check_Solution(2,0,2) == \"Yes\"\nassert Check_Solution(2,-5,2) == \"Yes\"\nassert Check_Solution(1,2,3) == \"No\"", "difficulty": "code"}
{"input": "Write a function to check whether the given amount has no profit and no loss", "answer": "def noprofit_noloss(actual_cost,sale_amount): \r\n  if(sale_amount == actual_cost):\r\n    return True\r\n  else:\r\n    return False", "source": "mbpp", "task_id": "637", "test_cases": "assert noprofit_noloss(1500,1200)==False\nassert noprofit_noloss(100,100)==True\nassert noprofit_noloss(2000,5000)==False", "difficulty": "code"}
{"input": "Write a function to calculate wind chill index.", "answer": "import math\r\ndef wind_chill(v,t):\r\n windchill = 13.12 + 0.6215*t -  11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16)\r\n return int(round(windchill, 0))", "source": "mbpp", "task_id": "638", "test_cases": "assert wind_chill(120,35)==40\nassert wind_chill(40,70)==86\nassert wind_chill(10,100)==116", "difficulty": "code"}
{"input": "Write 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.", "answer": "def sample_nam(sample_names):\r\n  sample_names=list(filter(lambda el:el[0].isupper() and el[1:].islower(),sample_names))\r\n  return len(''.join(sample_names))", "source": "mbpp", "task_id": "639", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a function to remove the parenthesis area in a string.", "answer": "import re\r\ndef remove_parenthesis(items):\r\n for item in items:\r\n    return (re.sub(r\" ?\\([^)]+\\)\", \"\", item))", "source": "mbpp", "task_id": "640", "test_cases": "assert remove_parenthesis([\"python (chrome)\"])==(\"python\")\nassert remove_parenthesis([\"string(.abc)\"])==(\"string\")\nassert remove_parenthesis([\"alpha(num)\"])==(\"alpha\")", "difficulty": "code"}
{"input": "Write a function to find the nth nonagonal number.", "answer": "def is_nonagonal(n): \r\n\treturn int(n * (7 * n - 5) / 2)", "source": "mbpp", "task_id": "641", "test_cases": "assert is_nonagonal(10) == 325\nassert is_nonagonal(15) == 750\nassert is_nonagonal(18) == 1089", "difficulty": "code"}
{"input": "Write a function to remove similar rows from the given tuple matrix.", "answer": "def remove_similar_row(test_list):\r\n  res = set(sorted([tuple(sorted(set(sub))) for sub in test_list]))\r\n  return (res)", "source": "mbpp", "task_id": "642", "test_cases": "assert remove_similar_row([[(4, 5), (3, 2)], [(2, 2), (4, 6)], [(3, 2), (4, 5)]] ) == {((2, 2), (4, 6)), ((3, 2), (4, 5))}\nassert remove_similar_row([[(5, 6), (4, 3)], [(3, 3), (5, 7)], [(4, 3), (5, 6)]] ) == {((4, 3), (5, 6)), ((3, 3), (5, 7))}\nassert remove_similar_row([[(6, 7), (5, 4)], [(4, 4), (6, 8)], [(5, 4), (6, 7)]] ) =={((4, 4), (6, 8)), ((5, 4), (6, 7))}", "difficulty": "code"}
{"input": "Write a function that matches a word containing 'z', not at the start or end of the word.", "answer": "import re\r\ndef text_match_wordz_middle(text):\r\n        patterns = '\\Bz\\B'\r\n        if re.search(patterns,  text):\r\n                return 'Found a match!'\r\n        else:\r\n                return('Not matched!')", "source": "mbpp", "task_id": "643", "test_cases": "assert text_match_wordz_middle(\"pythonzabc.\")==('Found a match!')\nassert text_match_wordz_middle(\"xyzabc.\")==('Found a match!')\nassert text_match_wordz_middle(\"  lang  .\")==('Not matched!')", "difficulty": "code"}
{"input": "Write a python function to reverse an array upto a given position.", "answer": "def reverse_Array_Upto_K(input, k): \r\n  return (input[k-1::-1] + input[k:])", "source": "mbpp", "task_id": "644", "test_cases": "assert 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]", "difficulty": "code"}
{"input": "Write a function to find the product of it’s kth index in the given tuples.", "answer": "def get_product(val) : \r\n\tres = 1\r\n\tfor ele in val: \r\n\t\tres *= ele \r\n\treturn res \r\ndef find_k_product(test_list, K):\r\n  res = get_product([sub[K] for sub in test_list])\r\n  return (res)", "source": "mbpp", "task_id": "645", "test_cases": "assert find_k_product([(5, 6, 7), (1, 3, 5), (8, 9, 19)], 2) == 665\nassert find_k_product([(6, 7, 8), (2, 4, 6), (9, 10, 20)], 1) == 280\nassert find_k_product([(7, 8, 9), (3, 5, 7), (10, 11, 21)], 0) == 210", "difficulty": "code"}
{"input": "Write a python function to count number of cubes of size k in a cube of size n.", "answer": "def No_of_cubes(N,K):\r\n    No = 0\r\n    No = (N - K + 1)\r\n    No = pow(No, 3)\r\n    return No", "source": "mbpp", "task_id": "646", "test_cases": "assert No_of_cubes(2,1) == 8\nassert No_of_cubes(5,2) == 64\nassert No_of_cubes(1,1) == 1", "difficulty": "code"}
{"input": "Write a function to split a string at uppercase letters.", "answer": "import re\r\ndef split_upperstring(text):\r\n return (re.findall('[A-Z][^A-Z]*', text))", "source": "mbpp", "task_id": "647", "test_cases": "assert split_upperstring(\"PythonProgramLanguage\")==['Python','Program','Language']\nassert split_upperstring(\"PythonProgram\")==['Python','Program']\nassert split_upperstring(\"ProgrammingLanguage\")==['Programming','Language']", "difficulty": "code"}
{"input": "Write a function to exchange the position of every n-th value with (n+1)th value and (n+1)th value with n-th value in a given list.", "answer": "from itertools import zip_longest, chain, tee\r\ndef exchange_elements(lst):\r\n    lst1, lst2 = tee(iter(lst), 2)\r\n    return list(chain.from_iterable(zip_longest(lst[1::2], lst[::2])))", "source": "mbpp", "task_id": "648", "test_cases": "assert exchange_elements([0,1,2,3,4,5])==[1, 0, 3, 2, 5, 4] \nassert exchange_elements([5,6,7,8,9,10])==[6,5,8,7,10,9] \nassert exchange_elements([25,35,45,55,75,95])==[35,25,55,45,95,75] ", "difficulty": "code"}
{"input": "Write a python function to calculate the sum of the numbers in a list between the indices of a specified range.", "answer": "def sum_Range_list(nums, m, n):                                                                                                                                                                                                \r\n    sum_range = 0                                                                                                                                                                                                         \r\n    for i in range(m, n+1, 1):                                                                                                                                                                                        \r\n        sum_range += nums[i]                                                                                                                                                                                                  \r\n    return sum_range", "source": "mbpp", "task_id": "649", "test_cases": "assert sum_Range_list([2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12],8,10) == 29\nassert sum_Range_list([1,2,3,4,5],1,2) == 5\nassert sum_Range_list([1,0,1,2,5,6],4,5) == 11", "difficulty": "code"}
{"input": "Write a python function to check whether the given two arrays are equal or not.", "answer": "def are_Equal(arr1,arr2,n,m):\r\n    if (n != m):\r\n        return False\r\n    arr1.sort()\r\n    arr2.sort()\r\n    for i in range(0,n - 1):\r\n        if (arr1[i] != arr2[i]):\r\n            return False\r\n    return True", "source": "mbpp", "task_id": "650", "test_cases": "assert are_Equal([1,2,3],[3,2,1],3,3) == True\nassert are_Equal([1,1,1],[2,2,2],3,3) == False\nassert are_Equal([8,9],[4,5,6],2,3) == False", "difficulty": "code"}
{"input": "Write a function to check if one tuple is a subset of another tuple.", "answer": "def check_subset(test_tup1, test_tup2):\r\n  res = set(test_tup2).issubset(test_tup1)\r\n  return (res)", "source": "mbpp", "task_id": "651", "test_cases": "assert check_subset((10, 4, 5, 6), (5, 10)) == True\nassert check_subset((1, 2, 3, 4), (5, 6)) == False\nassert check_subset((7, 8, 9, 10), (10, 8)) == True", "difficulty": "code"}
{"input": "Write a function to flatten the given tuple matrix into the tuple list with each tuple representing each column.", "answer": "def matrix_to_list(test_list):\r\n  temp = [ele for sub in test_list for ele in sub]\r\n  res = list(zip(*temp))\r\n  return (str(res))", "source": "mbpp", "task_id": "652", "test_cases": "assert matrix_to_list([[(4, 5), (7, 8)], [(10, 13), (18, 17)], [(0, 4), (10, 1)]]) == '[(4, 7, 10, 18, 0, 10), (5, 8, 13, 17, 4, 1)]'\nassert matrix_to_list([[(5, 6), (8, 9)], [(11, 14), (19, 18)], [(1, 5), (11, 2)]]) == '[(5, 8, 11, 19, 1, 11), (6, 9, 14, 18, 5, 2)]'\nassert matrix_to_list([[(6, 7), (9, 10)], [(12, 15), (20, 21)], [(23, 7), (15, 8)]]) == '[(6, 9, 12, 20, 23, 15), (7, 10, 15, 21, 7, 8)]'", "difficulty": "code"}
{"input": "Write a function to group a sequence of key-value pairs into a dictionary of lists using collections module.", "answer": "from collections import defaultdict\r\ndef grouping_dictionary(l):\r\n    d = defaultdict(list)\r\n    for k, v in l:\r\n        d[k].append(v)\r\n    return d", "source": "mbpp", "task_id": "653", "test_cases": "assert grouping_dictionary([('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)])== ({'yellow': [1, 3], 'blue': [2, 4], 'red': [1]})\nassert grouping_dictionary([('yellow', 10), ('blue', 20), ('yellow', 30), ('blue', 40), ('red', 10)])== ({'yellow': [10, 30], 'blue': [20, 40], 'red': [10]})\nassert grouping_dictionary([('yellow', 15), ('blue', 25), ('yellow', 35), ('blue', 45), ('red', 15)])== ({'yellow': [15, 35], 'blue': [25, 45], 'red': [15]})", "difficulty": "code"}
{"input": "Write a function to find the perimeter of a rectangle.", "answer": "def rectangle_perimeter(l,b):\r\n  perimeter=2*(l+b)\r\n  return perimeter", "source": "mbpp", "task_id": "654", "test_cases": "assert rectangle_perimeter(10,20)==60\nassert rectangle_perimeter(10,5)==30\nassert rectangle_perimeter(4,2)==12", "difficulty": "code"}
{"input": "Write a python function to find the sum of fifth power of n natural numbers.", "answer": "def fifth_Power_Sum(n) : \r\n    sm = 0 \r\n    for i in range(1,n+1) : \r\n        sm = sm + (i*i*i*i*i) \r\n    return sm", "source": "mbpp", "task_id": "655", "test_cases": "assert fifth_Power_Sum(2) == 33\nassert fifth_Power_Sum(4) == 1300\nassert fifth_Power_Sum(3) == 276", "difficulty": "code"}
{"input": "Write a python function to find the minimum sum of absolute differences of two arrays.", "answer": "def find_Min_Sum(a,b,n): \r\n    a.sort() \r\n    b.sort() \r\n    sum = 0  \r\n    for i in range(n): \r\n        sum = sum + abs(a[i] - b[i]) \r\n    return sum", "source": "mbpp", "task_id": "656", "test_cases": "assert find_Min_Sum([3,2,1],[2,1,3],3) == 0\nassert find_Min_Sum([1,2,3],[4,5,6],3) == 9\nassert find_Min_Sum([4,1,8,7],[2,3,6,5],4) == 6", "difficulty": "code"}
{"input": "Write a python function to find the first digit in factorial of a given number.", "answer": "import math \r\ndef first_Digit(n) : \r\n    fact = 1\r\n    for i in range(2,n + 1) : \r\n        fact = fact * i \r\n        while (fact % 10 == 0) :  \r\n            fact = int(fact / 10) \r\n    while (fact >= 10) : \r\n        fact = int(fact / 10) \r\n    return math.floor(fact)", "source": "mbpp", "task_id": "657", "test_cases": "assert first_Digit(5) == 1\nassert first_Digit(10) == 3\nassert first_Digit(7) == 5", "difficulty": "code"}
{"input": "Write a function to find the item with maximum occurrences in a given list.", "answer": "def max_occurrences(list1):\r\n    max_val = 0\r\n    result = list1[0] \r\n    for i in list1:\r\n        occu = list1.count(i)\r\n        if occu > max_val:\r\n            max_val = occu\r\n            result = i \r\n    return result", "source": "mbpp", "task_id": "658", "test_cases": "assert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,4,6,9,1,2])==2\nassert max_occurrences([1, 3,5, 7,1, 3,13, 15, 17,5, 7,9,1, 11])==1\nassert max_occurrences([1, 2, 3,2, 4, 5,1, 1, 1])==1", "difficulty": "code"}
{"input": "Write a python function to print duplicants from a list of integers.", "answer": "def Repeat(x): \r\n    _size = len(x) \r\n    repeated = [] \r\n    for i in range(_size): \r\n        k = i + 1\r\n        for j in range(k, _size): \r\n            if x[i] == x[j] and x[i] not in repeated: \r\n                repeated.append(x[i]) \r\n    return repeated", "source": "mbpp", "task_id": "659", "test_cases": "assert Repeat([10, 20, 30, 20, 20, 30, 40, 50, -20, 60, 60, -20, -20]) == [20, 30, -20, 60]\nassert Repeat([-1, 1, -1, 8]) == [-1]\nassert Repeat([1, 2, 3, 1, 2,]) == [1, 2]", "difficulty": "code"}
{"input": "Write a python function to choose points from two ranges such that no point lies in both the ranges.", "answer": "def find_Points(l1,r1,l2,r2): \r\n    x = min(l1,l2) if (l1 != l2) else -1\r\n    y = max(r1,r2) if (r1 != r2) else -1\r\n    return (x,y)", "source": "mbpp", "task_id": "660", "test_cases": "assert find_Points(5,10,1,5) == (1,10)\nassert find_Points(3,5,7,9) == (3,9)\nassert find_Points(1,5,2,8) == (1,8)", "difficulty": "code"}
{"input": "Write a function to find the maximum sum that can be formed which has no three consecutive elements present.", "answer": "def max_sum_of_three_consecutive(arr, n): \r\n\tsum = [0 for k in range(n)] \r\n\tif n >= 1: \r\n\t\tsum[0] = arr[0] \r\n\tif n >= 2: \r\n\t\tsum[1] = arr[0] + arr[1] \r\n\tif n > 2: \r\n\t\tsum[2] = max(sum[1], max(arr[1] + arr[2], arr[0] + arr[2])) \r\n\tfor i in range(3, n): \r\n\t\tsum[i] = max(max(sum[i-1], sum[i-2] + arr[i]), arr[i] + arr[i-1] + sum[i-3]) \r\n\treturn sum[n-1]", "source": "mbpp", "task_id": "661", "test_cases": "assert max_sum_of_three_consecutive([100, 1000, 100, 1000, 1], 5) == 2101\nassert max_sum_of_three_consecutive([3000, 2000, 1000, 3, 10], 5) == 5013\nassert max_sum_of_three_consecutive([1, 2, 3, 4, 5, 6, 7, 8], 8) == 27", "difficulty": "code"}
{"input": "Write a function to sort a list in a dictionary.", "answer": "def sorted_dict(dict1):\r\n  sorted_dict = {x: sorted(y) for x, y in dict1.items()}\r\n  return sorted_dict", "source": "mbpp", "task_id": "662", "test_cases": "assert sorted_dict({'n1': [2, 3, 1], 'n2': [5, 1, 2], 'n3': [3, 2, 4]})=={'n1': [1, 2, 3], 'n2': [1, 2, 5], 'n3': [2, 3, 4]}\nassert sorted_dict({'n1': [25,37,41], 'n2': [41,54,63], 'n3': [29,38,93]})=={'n1': [25, 37, 41], 'n2': [41, 54, 63], 'n3': [29, 38, 93]}\nassert sorted_dict({'n1': [58,44,56], 'n2': [91,34,58], 'n3': [100,200,300]})=={'n1': [44, 56, 58], 'n2': [34, 58, 91], 'n3': [100, 200, 300]}", "difficulty": "code"}
{"input": "Write a function to find the largest possible value of k such that k modulo x is y.", "answer": "import sys \r\ndef find_max_val(n, x, y): \r\n\tans = -sys.maxsize \r\n\tfor k in range(n + 1): \r\n\t\tif (k % x == y): \r\n\t\t\tans = max(ans, k) \r\n\treturn (ans if (ans >= 0 and\r\n\t\t\t\t\tans <= n) else -1)", "source": "mbpp", "task_id": "663", "test_cases": "assert find_max_val(15, 10, 5) == 15\nassert find_max_val(187, 10, 5) == 185\nassert find_max_val(16, 11, 1) == 12", "difficulty": "code"}
{"input": "Write a python function to find the average of even numbers till a given even number.", "answer": "def average_Even(n) : \r\n    if (n% 2!= 0) : \r\n        return (\"Invalid Input\") \r\n        return -1  \r\n    sm = 0\r\n    count = 0\r\n    while (n>= 2) : \r\n        count = count+1\r\n        sm = sm+n \r\n        n = n-2\r\n    return sm // count", "source": "mbpp", "task_id": "664", "test_cases": "assert average_Even(2) == 2\nassert average_Even(4) == 3\nassert average_Even(100) == 51", "difficulty": "code"}
{"input": "Write a python function to shift first element to the end of given list.", "answer": "def move_last(num_list):\r\n    a = [num_list[0] for i in range(num_list.count(num_list[0]))]\r\n    x = [ i for i in num_list if i != num_list[0]]\r\n    x.extend(a)\r\n    return (x)", "source": "mbpp", "task_id": "665", "test_cases": "assert move_last([1,2,3,4]) == [2,3,4,1]\nassert move_last([2,3,4,1,5,0]) == [3,4,1,5,0,2]\nassert move_last([5,4,3,2,1]) == [4,3,2,1,5]", "difficulty": "code"}
{"input": "Write a function to count occurrence of a character in a string.", "answer": "def count_char(string,char):\r\n count = 0\r\n for i in range(len(string)):\r\n    if(string[i] == char):\r\n        count = count + 1\r\n return count", "source": "mbpp", "task_id": "666", "test_cases": "assert count_char(\"Python\",'o')==1\nassert count_char(\"little\",'t')==2\nassert count_char(\"assert\",'s')==2", "difficulty": "code"}
{"input": "Write a python function to count number of vowels in the string.", "answer": "def Check_Vow(string, vowels): \r\n    final = [each for each in string if each in vowels] \r\n    return(len(final))", "source": "mbpp", "task_id": "667", "test_cases": "assert Check_Vow('corner','AaEeIiOoUu') == 2\nassert Check_Vow('valid','AaEeIiOoUu') == 2\nassert Check_Vow('true','AaEeIiOoUu') ==2", "difficulty": "code"}
{"input": "Write a python function to replace multiple occurence of character by single.", "answer": "import re \r\ndef replace(string, char): \r\n    pattern = char + '{2,}'\r\n    string = re.sub(pattern, char, string) \r\n    return string", "source": "mbpp", "task_id": "668", "test_cases": "assert replace('peep','e') == 'pep'\nassert replace('Greek','e') == 'Grek'\nassert replace('Moon','o') == 'Mon'", "difficulty": "code"}
{"input": "Write a function to check whether the given ip address is valid or not using regex.", "answer": "import re \r\nregex = '''^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.( \r\n\t\t\t25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.( \r\n\t\t\t25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.( \r\n\t\t\t25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$'''\r\ndef check_IP(Ip): \r\n\tif(re.search(regex, Ip)): \r\n\t\treturn (\"Valid IP address\") \r\n\telse: \r\n\t\treturn (\"Invalid IP address\")", "source": "mbpp", "task_id": "669", "test_cases": "assert check_IP(\"192.168.0.1\") == 'Valid IP address'\nassert check_IP(\"110.234.52.124\") == 'Valid IP address'\nassert check_IP(\"366.1.2.2\") == 'Invalid IP address'", "difficulty": "code"}
{"input": "Write a python function to check whether a sequence of numbers has a decreasing trend or not.", "answer": "def decreasing_trend(nums):\r\n    if (sorted(nums)== nums):\r\n        return True\r\n    else:\r\n        return False", "source": "mbpp", "task_id": "670", "test_cases": "assert decreasing_trend([-4,-3,-2,-1]) == True\nassert decreasing_trend([1,2,3]) == True\nassert decreasing_trend([3,2,1]) == False", "difficulty": "code"}
{"input": "Write a python function to set the right most unset bit.", "answer": "import math \r\ndef get_Pos_Of_Right_most_Set_Bit(n): \r\n    return int(math.log2(n&-n)+1)   \r\ndef set_Right_most_Unset_Bit(n): \r\n    if (n == 0): \r\n        return 1\r\n    if ((n & (n + 1)) == 0):     \r\n        return n \r\n    pos = get_Pos_Of_Right_most_Set_Bit(~n)      \r\n    return ((1 << (pos - 1)) | n)", "source": "mbpp", "task_id": "671", "test_cases": "assert set_Right_most_Unset_Bit(21) == 23\nassert set_Right_most_Unset_Bit(11) == 15\nassert set_Right_most_Unset_Bit(15) == 15", "difficulty": "code"}
{"input": "Write a function to find maximum of three numbers.", "answer": "def max_of_three(num1,num2,num3): \r\n    if (num1 >= num2) and (num1 >= num3):\r\n       lnum = num1\r\n    elif (num2 >= num1) and (num2 >= num3):\r\n       lnum = num2\r\n    else:\r\n       lnum = num3\r\n    return lnum", "source": "mbpp", "task_id": "672", "test_cases": "assert max_of_three(10,20,30)==30\nassert max_of_three(55,47,39)==55\nassert max_of_three(10,49,30)==49", "difficulty": "code"}
{"input": "Write a python function to convert a list of multiple integers into a single integer.", "answer": "def convert(list): \r\n    s = [str(i) for i in list] \r\n    res = int(\"\".join(s))  \r\n    return (res)", "source": "mbpp", "task_id": "673", "test_cases": "assert convert([1,2,3]) == 123\nassert convert([4,5,6]) == 456\nassert convert([7,8,9]) == 789", "difficulty": "code"}
{"input": "Write a function to remove duplicate words from a given string using collections module.", "answer": "from collections import OrderedDict\r\ndef remove_duplicate(string):\r\n  result = ' '.join(OrderedDict((w,w) for w in string.split()).keys())\r\n  return result", "source": "mbpp", "task_id": "674", "test_cases": "assert remove_duplicate(\"Python Exercises Practice Solution Exercises\")==(\"Python Exercises Practice Solution\")\nassert remove_duplicate(\"Python Exercises Practice Solution Python\")==(\"Python Exercises Practice Solution\")\nassert remove_duplicate(\"Python Exercises Practice Solution Practice\")==(\"Python Exercises Practice Solution\")", "difficulty": "code"}
{"input": "Write a function to add two integers. however, if the sum is between the given range it will return 20.", "answer": "def sum_nums(x, y,m,n):\r\n    sum_nums= x + y\r\n    if sum_nums in range(m, n):\r\n        return 20\r\n    else:\r\n        return sum_nums", "source": "mbpp", "task_id": "675", "test_cases": "assert sum_nums(2,10,11,20)==20\nassert sum_nums(15,17,1,10)==32\nassert sum_nums(10,15,5,30)==20", "difficulty": "code"}
{"input": "Write a function to remove everything except alphanumeric characters from the given string by using regex.", "answer": "import re\r\ndef remove_extra_char(text1):\r\n  pattern = re.compile('[\\W_]+')\r\n  return (pattern.sub('', text1))", "source": "mbpp", "task_id": "676", "test_cases": "assert remove_extra_char('**//Google Android// - 12. ') == 'GoogleAndroid12'\nassert remove_extra_char('****//Google Flutter//*** - 36. ') == 'GoogleFlutter36'\nassert remove_extra_char('**//Google Firebase// - 478. ') == 'GoogleFirebase478'", "difficulty": "code"}
{"input": "Write a function to check if the triangle is valid or not.", "answer": "def validity_triangle(a,b,c):\r\n total = a + b + c\r\n if total == 180:\r\n    return True\r\n else:\r\n    return False", "source": "mbpp", "task_id": "677", "test_cases": "assert validity_triangle(60,50,90)==False\nassert validity_triangle(45,75,60)==True\nassert validity_triangle(30,50,100)==True", "difficulty": "code"}
{"input": "Write a python function to remove spaces from a given string.", "answer": "def remove_spaces(str1):\r\n  str1 = str1.replace(' ','')\r\n  return str1", "source": "mbpp", "task_id": "678", "test_cases": "assert remove_spaces(\"a b c\") == \"abc\"\nassert remove_spaces(\"1 2 3\") == \"123\"\nassert remove_spaces(\" b c\") == \"bc\"", "difficulty": "code"}
{"input": "Write a function to access dictionary key’s element by index.", "answer": "def access_key(ditionary,key):\r\n  return list(ditionary)[key]", "source": "mbpp", "task_id": "679", "test_cases": "assert access_key({'physics': 80, 'math': 90, 'chemistry': 86},0)== 'physics'\nassert access_key({'python':10, 'java': 20, 'C++':30},2)== 'C++'\nassert access_key({'program':15,'computer':45},1)== 'computer'", "difficulty": "code"}
{"input": "Write a python function to check whether a sequence of numbers has an increasing trend or not.", "answer": "def increasing_trend(nums):\r\n    if (sorted(nums)== nums):\r\n        return True\r\n    else:\r\n        return False", "source": "mbpp", "task_id": "680", "test_cases": "assert increasing_trend([1,2,3,4]) == True\nassert increasing_trend([4,3,2,1]) == False\nassert increasing_trend([0,1,4,9]) == True", "difficulty": "code"}
{"input": "Write a python function to find the smallest prime divisor of a number.", "answer": "def smallest_Divisor(n): \r\n    if (n % 2 == 0): \r\n        return 2; \r\n    i = 3;  \r\n    while (i*i <= n): \r\n        if (n % i == 0): \r\n            return i; \r\n        i += 2; \r\n    return n;", "source": "mbpp", "task_id": "681", "test_cases": "assert smallest_Divisor(10) == 2\nassert smallest_Divisor(25) == 5\nassert smallest_Divisor(31) == 31", "difficulty": "code"}
{"input": "Write a function to multiply two lists using map and lambda function.", "answer": "def mul_list(nums1,nums2):\r\n  result = map(lambda x, y: x * y, nums1, nums2)\r\n  return list(result)", "source": "mbpp", "task_id": "682", "test_cases": "assert mul_list([1, 2, 3],[4,5,6])==[4,10,18]\nassert mul_list([1,2],[3,4])==[3,8]\nassert mul_list([90,120],[50,70])==[4500,8400]", "difficulty": "code"}
{"input": "Write a python function to check whether the given number can be represented by sum of two squares or not.", "answer": "def sum_Square(n) : \r\n    i = 1 \r\n    while i*i <= n : \r\n        j = 1\r\n        while (j*j <= n) : \r\n            if (i*i+j*j == n) : \r\n                return True\r\n            j = j+1\r\n        i = i+1     \r\n    return False", "source": "mbpp", "task_id": "683", "test_cases": "assert sum_Square(25) == True\nassert sum_Square(24) == False\nassert sum_Square(17) == True", "difficulty": "code"}
{"input": "Write a python function to count occurences of a character in a repeated string.", "answer": "def count_Char(str,x): \r\n    count = 0\r\n    for i in range(len(str)):  \r\n        if (str[i] == x) : \r\n            count += 1\r\n    n = 10\r\n    repititions = n // len(str)  \r\n    count = count * repititions  \r\n    l = n % len(str)  \r\n    for i in range(l): \r\n        if (str[i] == x):  \r\n            count += 1\r\n    return count", "source": "mbpp", "task_id": "684", "test_cases": "assert count_Char(\"abcac\",'a') == 4\nassert count_Char(\"abca\",'c') == 2\nassert count_Char(\"aba\",'a') == 7", "difficulty": "code"}
{"input": "Write a python function to find sum of prime numbers between 1 to n.", "answer": "def sum_Of_Primes(n): \r\n    prime = [True] * (n + 1)  \r\n    p = 2\r\n    while p * p <= n: \r\n        if prime[p] == True:  \r\n            i = p * 2\r\n            while i <= n: \r\n                prime[i] = False\r\n                i += p \r\n        p += 1    \r\n    sum = 0\r\n    for i in range (2,n + 1): \r\n        if(prime[i]): \r\n            sum += i \r\n    return sum", "source": "mbpp", "task_id": "685", "test_cases": "assert sum_Of_Primes(10) == 17\nassert sum_Of_Primes(20) == 77\nassert sum_Of_Primes(5) == 10", "difficulty": "code"}
{"input": "Write a function to find the frequency of each element in the given list.", "answer": "from collections import defaultdict \r\ndef freq_element(test_tup):\r\n  res = defaultdict(int)\r\n  for ele in test_tup:\r\n    res[ele] += 1\r\n  return (str(dict(res)))", "source": "mbpp", "task_id": "686", "test_cases": "assert freq_element((4, 5, 4, 5, 6, 6, 5, 5, 4) ) == '{4: 3, 5: 4, 6: 2}'\nassert freq_element((7, 8, 8, 9, 4, 7, 6, 5, 4) ) == '{7: 2, 8: 2, 9: 1, 4: 2, 6: 1, 5: 1}'\nassert freq_element((1, 4, 3, 1, 4, 5, 2, 6, 2, 7) ) == '{1: 2, 4: 2, 3: 1, 5: 1, 2: 2, 6: 1, 7: 1}'", "difficulty": "code"}
{"input": "Write a function to find the greatest common divisor (gcd) of two integers by using recursion.", "answer": "def recur_gcd(a, b):\r\n\tlow = min(a, b)\r\n\thigh = max(a, b)\r\n\tif low == 0:\r\n\t\treturn high\r\n\telif low == 1:\r\n\t\treturn 1\r\n\telse:\r\n\t\treturn recur_gcd(low, high%low)", "source": "mbpp", "task_id": "687", "test_cases": "assert recur_gcd(12,14) == 2\nassert recur_gcd(13,17) == 1\nassert recur_gcd(9, 3) == 3", "difficulty": "code"}
{"input": "Write a function to get the length of a complex number.", "answer": "import cmath\r\ndef len_complex(a,b):\r\n  cn=complex(a,b)\r\n  length=abs(cn)\r\n  return length", "source": "mbpp", "task_id": "688", "test_cases": "assert len_complex(3,4)==5.0\nassert len_complex(9,10)==13.45362404707371\nassert len_complex(7,9)==11.40175425099138", "difficulty": "code"}
{"input": "## write a function to find the minimum number of jumps to reach the end of the array for the given array of integers where each element represents the max number of steps that can be made forward from that element. > indented block > indented block", "answer": "def min_jumps(arr, n):\r\n\tjumps = [0 for i in range(n)]\r\n\tif (n == 0) or (arr[0] == 0):\r\n\t\treturn float('inf')\r\n\tjumps[0] = 0\r\n\tfor i in range(1, n):\r\n\t\tjumps[i] = float('inf')\r\n\t\tfor j in range(i):\r\n\t\t\tif (i <= j + arr[j]) and (jumps[j] != float('inf')):\r\n\t\t\t\tjumps[i] = min(jumps[i], jumps[j] + 1)\r\n\t\t\t\tbreak\r\n\treturn jumps[n-1]", "source": "mbpp", "task_id": "689", "test_cases": "assert min_jumps([1, 3, 6, 1, 0, 9], 6) == 3\nassert min_jumps([1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9], 11) == 3\nassert min_jumps([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 11) == 10", "difficulty": "code"}
{"input": "Write a function to multiply consecutive numbers of a given list.", "answer": "def mul_consecutive_nums(nums):\r\n    result = [b*a for a, b in zip(nums[:-1], nums[1:])]\r\n    return result", "source": "mbpp", "task_id": "690", "test_cases": "assert mul_consecutive_nums([1, 1, 3, 4, 4, 5, 6, 7])==[1, 3, 12, 16, 20, 30, 42]\nassert mul_consecutive_nums([4, 5, 8, 9, 6, 10])==[20, 40, 72, 54, 60]\nassert mul_consecutive_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[2, 6, 12, 20, 30, 42, 56, 72, 90]", "difficulty": "code"}
{"input": "Write a function to group the 1st elements on the basis of 2nd elements in the given tuple list.", "answer": "from itertools import groupby \r\ndef group_element(test_list):\r\n  res = dict()\r\n  for key, val in groupby(sorted(test_list, key = lambda ele: ele[1]), key = lambda ele: ele[1]):\r\n    res[key] = [ele[0] for ele in val] \r\n  return (res)", "source": "mbpp", "task_id": "691", "test_cases": "assert group_element([(6, 5), (2, 7), (2, 5), (8, 7), (9, 8), (3, 7)]) == {5: [6, 2], 7: [2, 8, 3], 8: [9]}\nassert group_element([(7, 6), (3, 8), (3, 6), (9, 8), (10, 9), (4, 8)]) == {6: [7, 3], 8: [3, 9, 4], 9: [10]}\nassert group_element([(8, 7), (4, 9), (4, 7), (10, 9), (11, 10), (5, 9)]) == {7: [8, 4], 9: [4, 10, 5], 10: [11]}", "difficulty": "code"}
{"input": "Write a python function to find the last two digits in factorial of a given number.", "answer": "def last_Two_Digits(N): \r\n    if (N >= 10): \r\n        return\r\n    fac = 1\r\n    for i in range(1,N + 1): \r\n        fac = (fac * i) % 100\r\n    return (fac)", "source": "mbpp", "task_id": "692", "test_cases": "assert last_Two_Digits(7) == 40\nassert last_Two_Digits(5) == 20\nassert last_Two_Digits(2) == 2", "difficulty": "code"}
{"input": "Write a function to remove multiple spaces in a string by using regex.", "answer": "import re\r\ndef remove_multiple_spaces(text1):\r\n  return (re.sub(' +',' ',text1))", "source": "mbpp", "task_id": "693", "test_cases": "assert remove_multiple_spaces('Google      Assistant') == 'Google Assistant'\nassert remove_multiple_spaces('Quad      Core') == 'Quad Core'\nassert remove_multiple_spaces('ChromeCast      Built-in') == 'ChromeCast Built-in'", "difficulty": "code"}
{"input": "Write a function to extract unique values from the given dictionary values.", "answer": "def extract_unique(test_dict):\r\n  res = list(sorted({ele for val in test_dict.values() for ele in val}))\r\n  return res", "source": "mbpp", "task_id": "694", "test_cases": "assert extract_unique({'msm' : [5, 6, 7, 8],'is' : [10, 11, 7, 5],'best' : [6, 12, 10, 8],'for' : [1, 2, 5]} ) == [1, 2, 5, 6, 7, 8, 10, 11, 12]\nassert extract_unique({'Built' : [7, 1, 9, 4],'for' : [11, 21, 36, 14, 9],'ISP' : [4, 1, 21, 39, 47],'TV' : [1, 32, 38]} ) == [1, 4, 7, 9, 11, 14, 21, 32, 36, 38, 39, 47]\nassert extract_unique({'F' : [11, 13, 14, 17],'A' : [12, 11, 15, 18],'N' : [19, 21, 15, 36],'G' : [37, 36, 35]}) == [11, 12, 13, 14, 15, 17, 18, 19, 21, 35, 36, 37]", "difficulty": "code"}
{"input": "Write a function to check if each element of the second tuple is greater than its corresponding index in the first tuple.", "answer": "def check_greater(test_tup1, test_tup2):\r\n  res = all(x < y for x, y in zip(test_tup1, test_tup2))\r\n  return (res)", "source": "mbpp", "task_id": "695", "test_cases": "assert check_greater((10, 4, 5), (13, 5, 18)) == True\nassert check_greater((1, 2, 3), (2, 1, 4)) == False\nassert check_greater((4, 5, 6), (5, 6, 7)) == True", "difficulty": "code"}
{"input": "Write a function to zip two given lists of lists.", "answer": "def zip_list(list1,list2):  \r\n result = list(map(list.__add__, list1, list2)) \r\n return result", "source": "mbpp", "task_id": "696", "test_cases": "assert zip_list([[1, 3], [5, 7], [9, 11]] ,[[2, 4], [6, 8], [10, 12, 14]] )==[[1, 3, 2, 4], [5, 7, 6, 8], [9, 11, 10, 12, 14]]\nassert zip_list([[1, 2], [3, 4], [5, 6]] ,[[7, 8], [9, 10], [11, 12]] )==[[1, 2, 7, 8], [3, 4, 9, 10], [5, 6, 11, 12]]\nassert zip_list([['a','b'],['c','d']] , [['e','f'],['g','h']] )==[['a','b','e','f'],['c','d','g','h']]", "difficulty": "code"}
{"input": "Write a function to find number of even elements in the given list using lambda function.", "answer": "def count_even(array_nums):\r\n   count_even = len(list(filter(lambda x: (x%2 == 0) , array_nums)))\r\n   return count_even", "source": "mbpp", "task_id": "697", "test_cases": "assert count_even([1, 2, 3, 5, 7, 8, 9, 10])==3\nassert count_even([10,15,14,13,-18,12,-20])==5\nassert count_even([1, 2, 4, 8, 9])==3", "difficulty": "code"}
{"input": "Write a function to sort dictionary items by tuple product of keys for the given dictionary with tuple keys.", "answer": "def sort_dict_item(test_dict):\r\n  res = {key: test_dict[key] for key in sorted(test_dict.keys(), key = lambda ele: ele[1] * ele[0])}\r\n  return  (res)", "source": "mbpp", "task_id": "698", "test_cases": "assert sort_dict_item({(5, 6) : 3, (2, 3) : 9, (8, 4): 10, (6, 4): 12} ) == {(2, 3): 9, (6, 4): 12, (5, 6): 3, (8, 4): 10}\nassert sort_dict_item({(6, 7) : 4, (3, 4) : 10, (9, 5): 11, (7, 5): 13} ) == {(3, 4): 10, (7, 5): 13, (6, 7): 4, (9, 5): 11}\nassert sort_dict_item({(7, 8) : 5, (4, 5) : 11, (10, 6): 12, (8, 6): 14} ) == {(4, 5): 11, (8, 6): 14, (7, 8): 5, (10, 6): 12}", "difficulty": "code"}
{"input": "Write a python function to find the minimum number of swaps required to convert one binary string to another.", "answer": "def min_Swaps(str1,str2) : \r\n    count = 0\r\n    for i in range(len(str1)) : \r\n        if str1[i] != str2[i] : \r\n            count += 1\r\n    if count % 2 == 0 : \r\n        return (count // 2) \r\n    else : \r\n        return (\"Not Possible\")", "source": "mbpp", "task_id": "699", "test_cases": "assert min_Swaps(\"1101\",\"1110\") == 1\nassert min_Swaps(\"1111\",\"0100\") == \"Not Possible\"\nassert min_Swaps(\"1110000\",\"0001101\") == 3", "difficulty": "code"}
{"input": "Write a function to count the number of elements in a list which are within a specific range.", "answer": "def count_range_in_list(li, min, max):\r\n\tctr = 0\r\n\tfor x in li:\r\n\t\tif min <= x <= max:\r\n\t\t\tctr += 1\r\n\treturn ctr", "source": "mbpp", "task_id": "700", "test_cases": "assert count_range_in_list([10,20,30,40,40,40,70,80,99],40,100)==6\nassert count_range_in_list(['a','b','c','d','e','f'],'a','e')==5\nassert count_range_in_list([7,8,9,15,17,19,45],15,20)==3", "difficulty": "code"}
{"input": "Write a function to find the equilibrium index of the given array.", "answer": "def equilibrium_index(arr):\r\n  total_sum = sum(arr)\r\n  left_sum=0\r\n  for i, num in enumerate(arr):\r\n    total_sum -= num\r\n    if left_sum == total_sum:\r\n      return i\r\n    left_sum += num\r\n  return -1", "source": "mbpp", "task_id": "701", "test_cases": "assert equilibrium_index([1, 2, 3, 4, 1, 2, 3]) == 3\nassert equilibrium_index([-7, 1, 5, 2, -4, 3, 0]) == 3\nassert equilibrium_index([1, 2, 3]) == -1", "difficulty": "code"}
{"input": "Write a function to find the minimum number of elements that should be removed such that amax-amin<=k.", "answer": "def find_ind(key, i, n, \r\n\t\t\tk, arr):\r\n\tind = -1\r\n\tstart = i + 1\r\n\tend = n - 1;\r\n\twhile (start < end):\r\n\t\tmid = int(start +\r\n\t\t\t\t(end - start) / 2)\r\n\t\tif (arr[mid] - key <= k):\r\n\t\t\tind = mid\r\n\t\t\tstart = mid + 1\r\n\t\telse:\r\n\t\t\tend = mid\r\n\treturn ind\r\ndef removals(arr, n, k):\r\n\tans = n - 1\r\n\tarr.sort()\r\n\tfor i in range(0, n):\r\n\t\tj = find_ind(arr[i], i, \r\n\t\t\t\t\tn, k, arr)\r\n\t\tif (j != -1):\r\n\t\t\tans = min(ans, n -\r\n\t\t\t\t\t\t(j - i + 1))\r\n\treturn ans", "source": "mbpp", "task_id": "702", "test_cases": "assert removals([1, 3, 4, 9, 10,11, 12, 17, 20], 9, 4) == 5\nassert removals([1, 5, 6, 2, 8], 5, 2) == 3\nassert removals([1, 2, 3 ,4, 5, 6], 6, 3) == 2", "difficulty": "code"}
{"input": "Write a function to check whether the given key is present in the dictionary or not.", "answer": "def is_key_present(d,x):\r\n  if x in d:\r\n    return True\r\n  else:\r\n     return False", "source": "mbpp", "task_id": "703", "test_cases": "assert is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60},5)==True\nassert is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60},6)==True\nassert is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60},10)==False", "difficulty": "code"}
{"input": "Write a function to calculate the harmonic sum of n-1.", "answer": "def harmonic_sum(n):\r\n  if n < 2:\r\n    return 1\r\n  else:\r\n    return 1 / n + (harmonic_sum(n - 1))", "source": "mbpp", "task_id": "704", "test_cases": "assert harmonic_sum(10)==2.9289682539682538\nassert harmonic_sum(4)==2.083333333333333\nassert harmonic_sum(7)==2.5928571428571425 ", "difficulty": "code"}
{"input": "Write a function to sort a list of lists by length and value.", "answer": "def sort_sublists(list1):\r\n      list1.sort()  \r\n      list1.sort(key=len)\r\n      return  list1", "source": "mbpp", "task_id": "705", "test_cases": "assert sort_sublists([[2], [0], [1, 3], [0, 7], [9, 11], [13, 15, 17]])==[[0], [2], [0, 7], [1, 3], [9, 11], [13, 15, 17]]\nassert sort_sublists([[1], [2, 3], [4, 5, 6], [7], [10, 11]])==[[1], [7], [2, 3], [10, 11], [4, 5, 6]]\nassert sort_sublists([[\"python\"],[\"java\",\"C\",\"C++\"],[\"DBMS\"],[\"SQL\",\"HTML\"]])==[['DBMS'], ['python'], ['SQL', 'HTML'], ['java', 'C', 'C++']]", "difficulty": "code"}
{"input": "Write a function to find whether an array is subset of another array.", "answer": "def is_subset(arr1, m, arr2, n): \r\n\thashset = set() \r\n\tfor i in range(0, m): \r\n\t\thashset.add(arr1[i]) \r\n\tfor i in range(0, n): \r\n\t\tif arr2[i] in hashset: \r\n\t\t\tcontinue\r\n\t\telse: \r\n\t\t\treturn False\r\n\treturn True", "source": "mbpp", "task_id": "706", "test_cases": "assert is_subset([11, 1, 13, 21, 3, 7], 6, [11, 3, 7, 1], 4) == True\nassert is_subset([1, 2, 3, 4, 5, 6], 6, [1, 2, 4], 3) == True\nassert is_subset([10, 5, 2, 23, 19], 5, [19, 5, 3], 3) == False", "difficulty": "code"}
{"input": "Write a python function to count the total set bits from 1 to n.", "answer": "def count_Set_Bits(n) :  \r\n    n += 1; \r\n    powerOf2 = 2;   \r\n    cnt = n // 2;  \r\n    while (powerOf2 <= n) : \r\n        totalPairs = n // powerOf2;  \r\n        cnt += (totalPairs // 2) * powerOf2;  \r\n        if (totalPairs & 1) : \r\n            cnt += (n % powerOf2) \r\n        else : \r\n            cnt += 0\r\n        powerOf2 <<= 1;    \r\n    return cnt;", "source": "mbpp", "task_id": "707", "test_cases": "assert count_Set_Bits(16) == 33\nassert count_Set_Bits(2) == 2\nassert count_Set_Bits(14) == 28", "difficulty": "code"}
{"input": "Write a python function to convert a string to a list.", "answer": "def Convert(string): \r\n    li = list(string.split(\" \")) \r\n    return li", "source": "mbpp", "task_id": "708", "test_cases": "assert Convert('python program') == ['python','program']\nassert Convert('Data Analysis') ==['Data','Analysis']\nassert Convert('Hadoop Training') == ['Hadoop','Training']", "difficulty": "code"}
{"input": "Write a function to count unique keys for each value present in the tuple.", "answer": "from collections import defaultdict \r\ndef get_unique(test_list):\r\n  res = defaultdict(list)\r\n  for sub in test_list:\r\n    res[sub[1]].append(sub[0])\r\n  res = dict(res)\r\n  res_dict = dict()\r\n  for key in res:\r\n    res_dict[key] = len(list(set(res[key])))\r\n  return (str(res_dict))", "source": "mbpp", "task_id": "709", "test_cases": "assert get_unique([(3, 4), (1, 2), (2, 4), (8, 2), (7, 2), (8, 1), (9, 1), (8, 4), (10, 4)] ) == '{4: 4, 2: 3, 1: 2}'\nassert get_unique([(4, 5), (2, 3), (3, 5), (9, 3), (8, 3), (9, 2), (10, 2), (9, 5), (11, 5)] ) == '{5: 4, 3: 3, 2: 2}'\nassert get_unique([(6, 5), (3, 4), (2, 6), (11, 1), (8, 22), (8, 11), (4, 3), (14, 3), (11, 6)] ) == '{5: 1, 4: 1, 6: 2, 1: 1, 22: 1, 11: 1, 3: 2}'", "difficulty": "code"}
{"input": "Write a function to access the initial and last data of the given tuple record.", "answer": "def front_and_rear(test_tup):\r\n  res = (test_tup[0], test_tup[-1])\r\n  return (res)", "source": "mbpp", "task_id": "710", "test_cases": "assert front_and_rear((10, 4, 5, 6, 7)) == (10, 7)\nassert front_and_rear((1, 2, 3, 4, 5)) == (1, 5)\nassert front_and_rear((6, 7, 8, 9, 10)) == (6, 10)", "difficulty": "code"}
{"input": "Write a python function to check whether the product of digits of a number at even and odd places is equal or not.", "answer": "def product_Equal(n): \r\n    if n < 10: \r\n        return False\r\n    prodOdd = 1; prodEven = 1\r\n    while n > 0: \r\n        digit = n % 10\r\n        prodOdd *= digit \r\n        n = n//10\r\n        if n == 0: \r\n            break; \r\n        digit = n % 10\r\n        prodEven *= digit \r\n        n = n//10\r\n    if prodOdd == prodEven: \r\n        return True\r\n    return False", "source": "mbpp", "task_id": "711", "test_cases": "assert product_Equal(2841) == True\nassert product_Equal(1234) == False\nassert product_Equal(1212) == False", "difficulty": "code"}
{"input": "Write a function to remove duplicates from a list of lists.", "answer": "import itertools\r\ndef remove_duplicate(list1):\r\n list.sort(list1)\r\n remove_duplicate = list(list1 for list1,_ in itertools.groupby(list1))\r\n return remove_duplicate", "source": "mbpp", "task_id": "712", "test_cases": "assert remove_duplicate([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])==[[10, 20], [30, 56, 25], [33], [40]] \nassert remove_duplicate([\"a\", \"b\", \"a\", \"c\", \"c\"] )==[\"a\", \"b\", \"c\"]\nassert remove_duplicate([1, 3, 5, 6, 3, 5, 6, 1] )==[1, 3, 5, 6]", "difficulty": "code"}
{"input": "Write a function to check if the given tuple contains all valid values or not.", "answer": "def check_valid(test_tup):\r\n  res = not any(map(lambda ele: not ele, test_tup))\r\n  return (res)", "source": "mbpp", "task_id": "713", "test_cases": "assert check_valid((True, True, True, True) ) == True\nassert check_valid((True, False, True, True) ) == False\nassert check_valid((True, True, True, True) ) == True", "difficulty": "code"}
{"input": "Write a python function to count the number of distinct power of prime factor of given number.", "answer": "def count_Fac(n):  \r\n    m = n \r\n    count = 0\r\n    i = 2\r\n    while((i * i) <= m): \r\n        total = 0\r\n        while (n % i == 0): \r\n            n /= i \r\n            total += 1 \r\n        temp = 0\r\n        j = 1\r\n        while((temp + j) <= total): \r\n            temp += j \r\n            count += 1\r\n            j += 1 \r\n        i += 1\r\n    if (n != 1): \r\n        count += 1 \r\n    return count", "source": "mbpp", "task_id": "714", "test_cases": "assert count_Fac(24) == 3\nassert count_Fac(12) == 2\nassert count_Fac(4) == 1", "difficulty": "code"}
{"input": "Write a function to convert the given string of integers into a tuple.", "answer": "def str_to_tuple(test_str):\r\n  res = tuple(map(int, test_str.split(', ')))\r\n  return (res)", "source": "mbpp", "task_id": "715", "test_cases": "assert str_to_tuple(\"1, -5, 4, 6, 7\") == (1, -5, 4, 6, 7)\nassert str_to_tuple(\"1, 2, 3, 4, 5\") == (1, 2, 3, 4, 5)\nassert str_to_tuple(\"4, 6, 9, 11, 13, 14\") == (4, 6, 9, 11, 13, 14)", "difficulty": "code"}
{"input": "Write a function to find the perimeter of a rombus.", "answer": "def rombus_perimeter(a):\r\n  perimeter=4*a\r\n  return perimeter", "source": "mbpp", "task_id": "716", "test_cases": "assert rombus_perimeter(10)==40\nassert rombus_perimeter(5)==20\nassert rombus_perimeter(4)==16", "difficulty": "code"}
{"input": "Write a function to calculate the standard deviation.", "answer": "import math\r\nimport sys\r\ndef sd_calc(data):\r\n    n = len(data)\r\n    if n <= 1:\r\n        return 0.0\r\n    mean, sd = avg_calc(data), 0.0\r\n    for el in data:\r\n        sd += (float(el) - mean)**2\r\n    sd = math.sqrt(sd / float(n-1))\r\n    return sd\r\ndef avg_calc(ls):\r\n    n, mean = len(ls), 0.0\r\n    if n <= 1:\r\n        return ls[0]\r\n    for el in ls:\r\n        mean = mean + float(el)\r\n    mean = mean / float(n)\r\n    return mean", "source": "mbpp", "task_id": "717", "test_cases": "assert sd_calc([4, 2, 5, 8, 6])== 2.23606797749979\nassert sd_calc([1,2,3,4,5,6,7])==2.160246899469287\nassert sd_calc([5,9,10,15,6,4])==4.070217029430577", "difficulty": "code"}
{"input": "Write a function to create a list taking alternate elements from another given list.", "answer": "def alternate_elements(list1):\r\n    result=[]\r\n    for item in list1[::2]:\r\n        result.append(item)\r\n    return result", "source": "mbpp", "task_id": "718", "test_cases": "assert alternate_elements([\"red\", \"black\", \"white\", \"green\", \"orange\"])==['red', 'white', 'orange']\nassert alternate_elements([2, 0, 3, 4, 0, 2, 8, 3, 4, 2])==[2, 3, 0, 8, 4]\nassert alternate_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9]", "difficulty": "code"}
{"input": "Write a function that matches a string that has an a followed by zero or more b's.", "answer": "import re\r\ndef text_match(text):\r\n        patterns = 'ab*?'\r\n        if re.search(patterns,  text):\r\n                return 'Found a match!'\r\n        else:\r\n                return('Not matched!')", "source": "mbpp", "task_id": "719", "test_cases": "assert text_match(\"ac\")==('Found a match!')\nassert text_match(\"dc\")==('Not matched!')\nassert text_match(\"abba\")==('Found a match!')", "difficulty": "code"}
{"input": "Write a function to add a dictionary to the tuple.", "answer": "def add_dict_to_tuple(test_tup, test_dict):\r\n  test_tup = list(test_tup)\r\n  test_tup.append(test_dict)\r\n  test_tup = tuple(test_tup)\r\n  return (test_tup)", "source": "mbpp", "task_id": "720", "test_cases": "assert 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})", "difficulty": "code"}
{"input": "Write a function to find a path with the maximum average over all existing paths for the given square matrix of size n*n.", "answer": "M = 100\r\ndef maxAverageOfPath(cost, N): \r\n\tdp = [[0 for i in range(N + 1)] for j in range(N + 1)] \r\n\tdp[0][0] = cost[0][0] \r\n\tfor i in range(1, N): \r\n\t\tdp[i][0] = dp[i - 1][0] + cost[i][0] \r\n\tfor j in range(1, N): \r\n\t\tdp[0][j] = dp[0][j - 1] + cost[0][j] \r\n\tfor i in range(1, N): \r\n\t\tfor j in range(1, N): \r\n\t\t\tdp[i][j] = max(dp[i - 1][j], \r\n\t\t\t\t\t\tdp[i][j - 1]) + cost[i][j] \r\n\treturn dp[N - 1][N - 1] / (2 * N - 1)", "source": "mbpp", "task_id": "721", "test_cases": "assert maxAverageOfPath([[1, 2, 3], [6, 5, 4], [7, 3, 9]], 3) == 5.2\nassert maxAverageOfPath([[2, 3, 4], [7, 6, 5], [8, 4, 10]], 3) == 6.2\nassert maxAverageOfPath([[3, 4, 5], [8, 7, 6], [9, 5, 11]], 3) == 7.2 ", "difficulty": "code"}
{"input": "Write a function to filter the height and width of students which are stored in a dictionary.", "answer": "def filter_data(students,h,w):\r\n    result = {k: s for k, s in students.items() if s[0] >=h and s[1] >=w}\r\n    return result", "source": "mbpp", "task_id": "722", "test_cases": "assert 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)}", "difficulty": "code"}
{"input": "Write a function to count the same pair in two given lists using map function.", "answer": "from operator import eq\r\ndef count_same_pair(nums1, nums2):\r\n    result = sum(map(eq, nums1, nums2))\r\n    return result", "source": "mbpp", "task_id": "723", "test_cases": "assert 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, 3, 4, 6, 8])==1", "difficulty": "code"}
{"input": "Write a function to calculate the sum of all digits of the base to the specified power.", "answer": "def power_base_sum(base, power):\r\n    return sum([int(i) for i in str(pow(base, power))])", "source": "mbpp", "task_id": "724", "test_cases": "assert power_base_sum(2,100)==115\nassert power_base_sum(8,10)==37\nassert power_base_sum(8,15)==62", "difficulty": "code"}
{"input": "Write a function to extract values between quotation marks of the given string by using regex.", "answer": "import re\r\ndef extract_quotation(text1):\r\n  return (re.findall(r'\"(.*?)\"', text1))", "source": "mbpp", "task_id": "725", "test_cases": "assert 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']", "difficulty": "code"}
{"input": "Write a function to multiply the adjacent elements of the given tuple.", "answer": "def multiply_elements(test_tup):\r\n  res = tuple(i * j for i, j in zip(test_tup, test_tup[1:]))\r\n  return (res)", "source": "mbpp", "task_id": "726", "test_cases": "assert 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)", "difficulty": "code"}
{"input": "Write a function to remove all characters except letters and numbers using regex", "answer": "import re \r\ndef remove_char(S):\r\n  result = re.sub('[\\W_]+', '', S) \r\n  return result", "source": "mbpp", "task_id": "727", "test_cases": "assert remove_char(\"123abcjw:, .@! eiw\") == '123abcjweiw'\nassert remove_char(\"Hello1234:, ! Howare33u\") == 'Hello1234Howare33u'\nassert remove_char(\"Cool543Triks@:, Make@987Trips\") == 'Cool543TriksMake987Trips' ", "difficulty": "code"}
{"input": "Write a function to sum elements in two lists.", "answer": "def sum_list(lst1,lst2):\r\n  res_list = [lst1[i] + lst2[i] for i in range(len(lst1))] \r\n  return res_list", "source": "mbpp", "task_id": "728", "test_cases": "assert 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]", "difficulty": "code"}
{"input": "Write a function to add two lists using map and lambda function.", "answer": "def add_list(nums1,nums2):\r\n  result = map(lambda x, y: x + y, nums1, nums2)\r\n  return list(result)", "source": "mbpp", "task_id": "729", "test_cases": "assert add_list([1, 2, 3],[4,5,6])==[5, 7, 9]\nassert add_list([1,2],[3,4])==[4,6]\nassert add_list([10,20],[50,70])==[60,90]", "difficulty": "code"}
{"input": "Write a function to remove consecutive duplicates of a given list.", "answer": "from itertools import groupby\r\ndef consecutive_duplicates(nums):\r\n    return [key for key, group in groupby(nums)]", "source": "mbpp", "task_id": "730", "test_cases": "assert 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']", "difficulty": "code"}
{"input": "Write a function to find the lateral surface area of a cone.", "answer": "import math\r\ndef lateralsurface_cone(r,h):\r\n  l = math.sqrt(r * r + h * h)\r\n  LSA = math.pi * r  * l\r\n  return LSA", "source": "mbpp", "task_id": "731", "test_cases": "assert lateralsurface_cone(5,12)==204.20352248333654\nassert lateralsurface_cone(10,15)==566.3586699569488\nassert lateralsurface_cone(19,17)==1521.8090132193388", "difficulty": "code"}
{"input": "Write a function to replace all occurrences of spaces, commas, or dots with a colon.", "answer": "import re\r\ndef replace_specialchar(text):\r\n return (re.sub(\"[ ,.]\", \":\", text))", "source": "mbpp", "task_id": "732", "test_cases": "assert 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')", "difficulty": "code"}
{"input": "Write a function to find the index of the first occurrence of a given number in a sorted array.", "answer": "def find_first_occurrence(A, x):\r\n    (left, right) = (0, len(A) - 1)\r\n    result = -1\r\n    while left <= right:\r\n        mid = (left + right) // 2\r\n        if x == A[mid]:\r\n            result = mid\r\n            right = mid - 1\r\n        elif x < A[mid]:\r\n            right = mid - 1\r\n        else:\r\n            left = mid + 1\r\n    return result", "source": "mbpp", "task_id": "733", "test_cases": "assert 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([2, 4, 1, 5, 6, 6, 8, 9, 9, 9], 6) == 4", "difficulty": "code"}
{"input": "Write a python function to find sum of products of all possible subarrays.", "answer": "def sum_Of_Subarray_Prod(arr,n):\r\n    ans = 0\r\n    res = 0\r\n    i = n - 1\r\n    while (i >= 0):\r\n        incr = arr[i]*(1 + res)\r\n        ans += incr\r\n        res = incr\r\n        i -= 1\r\n    return (ans)", "source": "mbpp", "task_id": "734", "test_cases": "assert sum_Of_Subarray_Prod([1,2,3],3) == 20\nassert sum_Of_Subarray_Prod([1,2],2) == 5\nassert sum_Of_Subarray_Prod([1,2,3,4],4) == 84", "difficulty": "code"}
{"input": "Write a python function to toggle bits of the number except the first and the last bit.", "answer": "def set_middle_bits(n):  \r\n    n |= n >> 1; \r\n    n |= n >> 2; \r\n    n |= n >> 4; \r\n    n |= n >> 8; \r\n    n |= n >> 16;  \r\n    return (n >> 1) ^ 1\r\ndef toggle_middle_bits(n): \r\n    if (n == 1): \r\n        return 1\r\n    return n ^ set_middle_bits(n)", "source": "mbpp", "task_id": "735", "test_cases": "assert toggle_middle_bits(9) == 15\nassert toggle_middle_bits(10) == 12\nassert toggle_middle_bits(11) == 13", "difficulty": "code"}
{"input": "Write a function to locate the left insertion point for a specified value in sorted order.", "answer": "import bisect\r\ndef left_insertion(a, x):\r\n    i = bisect.bisect_left(a, x)\r\n    return i", "source": "mbpp", "task_id": "736", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a function to check whether the given string is starting with a vowel or not using regex.", "answer": "import re \r\nregex = '^[aeiouAEIOU][A-Za-z0-9_]*'\r\ndef check_str(string): \r\n\tif(re.search(regex, string)): \r\n\t\treturn (\"Valid\") \r\n\telse: \r\n\t\treturn (\"Invalid\")", "source": "mbpp", "task_id": "737", "test_cases": "assert check_str(\"annie\") == 'Valid'\nassert check_str(\"dawood\") == 'Invalid'\nassert check_str(\"Else\") == 'Valid'", "difficulty": "code"}
{"input": "Write a function to calculate the geometric sum of n-1.", "answer": "def geometric_sum(n):\r\n  if n < 0:\r\n    return 0\r\n  else:\r\n    return 1 / (pow(2, n)) + geometric_sum(n - 1)", "source": "mbpp", "task_id": "738", "test_cases": "assert geometric_sum(7) == 1.9921875\nassert geometric_sum(4) == 1.9375\nassert geometric_sum(8) == 1.99609375", "difficulty": "code"}
{"input": "Write a python function to find the index of smallest triangular number with n digits.", "answer": "import math \r\ndef find_Index(n): \r\n    x = math.sqrt(2 * math.pow(10,(n - 1))); \r\n    return round(x);", "source": "mbpp", "task_id": "739", "test_cases": "assert find_Index(2) == 4\nassert find_Index(3) == 14\nassert find_Index(4) == 45", "difficulty": "code"}
{"input": "Write a function to convert the given tuple to a key-value dictionary using adjacent elements.", "answer": "def tuple_to_dict(test_tup):\r\n  res = dict(test_tup[idx : idx + 2] for idx in range(0, len(test_tup), 2))\r\n  return (res)", "source": "mbpp", "task_id": "740", "test_cases": "assert 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}", "difficulty": "code"}
{"input": "Write a python function to check whether all the characters are same or not.", "answer": "def all_Characters_Same(s) :\r\n    n = len(s)\r\n    for i in range(1,n) :\r\n        if s[i] != s[0] :\r\n            return False\r\n    return True", "source": "mbpp", "task_id": "741", "test_cases": "assert all_Characters_Same(\"python\") == False\nassert all_Characters_Same(\"aaa\") == True\nassert all_Characters_Same(\"data\") == False", "difficulty": "code"}
{"input": "Write a function to caluclate the area of a tetrahedron.", "answer": "import math\r\ndef area_tetrahedron(side):\r\n  area = math.sqrt(3)*(side*side)\r\n  return area", "source": "mbpp", "task_id": "742", "test_cases": "assert area_tetrahedron(3)==15.588457268119894\nassert area_tetrahedron(20)==692.8203230275509\nassert area_tetrahedron(10)==173.20508075688772", "difficulty": "code"}
{"input": "Write a function to rotate a given list by specified number of items to the right direction.", "answer": "def rotate_right(list1,m,n):\r\n  result =  list1[-(m):]+list1[:-(n)]\r\n  return result", "source": "mbpp", "task_id": "743", "test_cases": "assert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],3,4)==[8, 9, 10, 1, 2, 3, 4, 5, 6]\nassert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2,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,2)==[6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8]", "difficulty": "code"}
{"input": "Write a function to check if the given tuple has any none value or not.", "answer": "def check_none(test_tup):\r\n  res = any(map(lambda ele: ele is None, test_tup))\r\n  return (res)", "source": "mbpp", "task_id": "744", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a function to find numbers within a given range where every number is divisible by every digit it contains.", "answer": "def divisible_by_digits(startnum, endnum):\r\n    return [n for n in range(startnum, endnum+1) \\\r\n                if not any(map(lambda x: int(x) == 0 or n%int(x) != 0, str(n)))]", "source": "mbpp", "task_id": "745", "test_cases": "assert 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]", "difficulty": "code"}
{"input": "Write a function to find area of a sector.", "answer": "def sector_area(r,a):\r\n    pi=22/7\r\n    if a >= 360:\r\n        return None\r\n    sectorarea = (pi*r**2) * (a/360)\r\n    return sectorarea", "source": "mbpp", "task_id": "746", "test_cases": "assert sector_area(4,45)==6.285714285714286\nassert sector_area(9,45)==31.82142857142857\nassert sector_area(9,360)==None", "difficulty": "code"}
{"input": "Write a function to find the longest common subsequence for the given three string sequence.", "answer": "def lcs_of_three(X, Y, Z, m, n, o): \r\n\tL = [[[0 for i in range(o+1)] for j in range(n+1)] \r\n\t\tfor k in range(m+1)] \r\n\tfor i in range(m+1): \r\n\t\tfor j in range(n+1): \r\n\t\t\tfor k in range(o+1): \r\n\t\t\t\tif (i == 0 or j == 0 or k == 0): \r\n\t\t\t\t\tL[i][j][k] = 0\r\n\t\t\t\telif (X[i-1] == Y[j-1] and\r\n\t\t\t\t\tX[i-1] == Z[k-1]): \r\n\t\t\t\t\tL[i][j][k] = L[i-1][j-1][k-1] + 1\r\n\t\t\t\telse: \r\n\t\t\t\t\tL[i][j][k] = max(max(L[i-1][j][k], \r\n\t\t\t\t\tL[i][j-1][k]), \r\n\t\t\t\t\t\t\t\t\tL[i][j][k-1]) \r\n\treturn L[m][n][o]", "source": "mbpp", "task_id": "747", "test_cases": "assert lcs_of_three('AGGT12', '12TXAYB', '12XBA', 6, 7, 5) == 2\nassert lcs_of_three('Reels', 'Reelsfor', 'ReelsforReels', 5, 8, 13) == 5 \nassert lcs_of_three('abcd1e2', 'bc12ea', 'bd1ea', 7, 6, 5) == 3", "difficulty": "code"}
{"input": "Write a function to put spaces between words starting with capital letters in a given string by using regex.", "answer": "import re\r\ndef capital_words_spaces(str1):\r\n  return re.sub(r\"(\\w)([A-Z])\", r\"\\1 \\2\", str1)", "source": "mbpp", "task_id": "748", "test_cases": "assert capital_words_spaces(\"Python\") == 'Python'\nassert capital_words_spaces(\"PythonProgrammingExamples\") == 'Python Programming Examples'\nassert capital_words_spaces(\"GetReadyToBeCodingFreak\") == 'Get Ready To Be Coding Freak'", "difficulty": "code"}
{"input": "Write a function to sort a given list of strings of numbers numerically.", "answer": "def sort_numeric_strings(nums_str):\r\n    result = [int(x) for x in nums_str]\r\n    result.sort()\r\n    return result", "source": "mbpp", "task_id": "749", "test_cases": "assert 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]", "difficulty": "code"}
{"input": "Write a function to add the given tuple to the given list.", "answer": "def add_tuple(test_list, test_tup):\r\n  test_list += test_tup\r\n  return (test_list)", "source": "mbpp", "task_id": "750", "test_cases": "assert 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]", "difficulty": "code"}
{"input": "Write a function to check if the given array represents min heap or not.", "answer": "def check_min_heap(arr, i):\r\n    if 2 * i + 2 > len(arr):\r\n        return True\r\n    left_child = (arr[i] <= arr[2 * i + 1]) and check_min_heap(arr, 2 * i + 1)\r\n    right_child = (2 * i + 2 == len(arr)) or (arr[i] <= arr[2 * i + 2] \r\n                                      and check_min_heap(arr, 2 * i + 2))\r\n    return left_child and right_child", "source": "mbpp", "task_id": "751", "test_cases": "assert check_min_heap([1, 2, 3, 4, 5, 6], 0) == True\nassert check_min_heap([2, 3, 4, 5, 10, 15], 0) == True\nassert check_min_heap([2, 10, 4, 5, 3, 15], 0) == False", "difficulty": "code"}
{"input": "Write a function to find the nth jacobsthal number.", "answer": "def jacobsthal_num(n): \r\n\tdp = [0] * (n + 1) \r\n\tdp[0] = 0\r\n\tdp[1] = 1\r\n\tfor i in range(2, n+1): \r\n\t\tdp[i] = dp[i - 1] + 2 * dp[i - 2] \r\n\treturn dp[n]", "source": "mbpp", "task_id": "752", "test_cases": "assert jacobsthal_num(5) == 11\nassert jacobsthal_num(2) == 1\nassert jacobsthal_num(4) == 5", "difficulty": "code"}
{"input": "Write a function to find minimum k records from tuple list.", "answer": "def min_k(test_list, K):\r\n  res = sorted(test_list, key = lambda x: x[1])[:K]\r\n  return (res)", "source": "mbpp", "task_id": "753", "test_cases": "assert 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)]", "difficulty": "code"}
{"input": "Write a function to find common index elements from three lists.", "answer": "def extract_index_list(l1, l2, l3):\r\n    result = []\r\n    for m, n, o in zip(l1, l2, l3):\r\n        if (m == n == o):\r\n            result.append(m)\r\n    return result", "source": "mbpp", "task_id": "754", "test_cases": "assert extract_index_list([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7])==[1, 7]\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]", "difficulty": "code"}
{"input": "Write a function to find the second smallest number in a list.", "answer": "def second_smallest(numbers):\r\n  if (len(numbers)<2):\r\n    return\r\n  if ((len(numbers)==2)  and (numbers[0] == numbers[1]) ):\r\n    return\r\n  dup_items = set()\r\n  uniq_items = []\r\n  for x in numbers:\r\n    if x not in dup_items:\r\n      uniq_items.append(x)\r\n      dup_items.add(x)\r\n  uniq_items.sort()    \r\n  return  uniq_items[1]", "source": "mbpp", "task_id": "755", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a function that matches a string that has an a followed by zero or one 'b'.", "answer": "import re\r\ndef text_match_zero_one(text):\r\n        patterns = 'ab?'\r\n        if re.search(patterns,  text):\r\n                return 'Found a match!'\r\n        else:\r\n                return('Not matched!')", "source": "mbpp", "task_id": "756", "test_cases": "assert text_match_zero_one(\"ac\")==('Found a match!')\nassert text_match_zero_one(\"dc\")==('Not matched!')\nassert text_match_zero_one(\"abbbba\")==('Found a match!')", "difficulty": "code"}
{"input": "Write a function to count the pairs of reverse strings in the given string list.", "answer": "def count_reverse_pairs(test_list):\r\n  res = sum([1 for idx in range(0, len(test_list)) for idxn in range(idx, len( \r\n\ttest_list)) if test_list[idxn] == str(''.join(list(reversed(test_list[idx]))))]) \r\n  return str(res)", "source": "mbpp", "task_id": "757", "test_cases": "assert 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' ", "difficulty": "code"}
{"input": "Write a function to count number of unique lists within a list.", "answer": "def unique_sublists(list1):\r\n    result ={}\r\n    for l in  list1: \r\n        result.setdefault(tuple(l), list()).append(1) \r\n    for a, b in result.items(): \r\n        result[a] = sum(b)\r\n    return result", "source": "mbpp", "task_id": "758", "test_cases": "assert 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}", "difficulty": "code"}
{"input": "Write a function to check a decimal with a precision of 2.", "answer": "def is_decimal(num):\r\n    import re\r\n    dnumre = re.compile(r\"\"\"^[0-9]+(\\.[0-9]{1,2})?$\"\"\")\r\n    result = dnumre.search(num)\r\n    return bool(result)", "source": "mbpp", "task_id": "759", "test_cases": "assert is_decimal('123.11')==True\nassert is_decimal('e666.86')==False\nassert is_decimal('3.124587')==False", "difficulty": "code"}
{"input": "Write a python function to check whether an array contains only one distinct element or not.", "answer": "def unique_Element(arr,n):\r\n    s = set(arr)\r\n    if (len(s) == 1):\r\n        return ('YES')\r\n    else:\r\n        return ('NO')", "source": "mbpp", "task_id": "760", "test_cases": "assert unique_Element([1,1,1],3) == 'YES'\nassert unique_Element([1,2,1,2],4) == 'NO'\nassert unique_Element([1,2,3,4,5],5) == 'NO'", "difficulty": "code"}
{"input": "Write a function to caluclate arc length of an angle.", "answer": "def arc_length(d,a):\r\n    pi=22/7\r\n    if a >= 360:\r\n        return None\r\n    arclength = (pi*d) * (a/360)\r\n    return arclength", "source": "mbpp", "task_id": "761", "test_cases": "assert arc_length(9,45)==3.5357142857142856\nassert arc_length(9,480)==None\nassert arc_length(5,270)==11.785714285714285", "difficulty": "code"}
{"input": "Write a function to check whether the given month number contains 30 days or not.", "answer": "def check_monthnumber_number(monthnum3):\r\n  if(monthnum3==4 or monthnum3==6 or monthnum3==9 or monthnum3==11):\r\n    return True\r\n  else:\r\n    return False", "source": "mbpp", "task_id": "762", "test_cases": "assert check_monthnumber_number(6)==True\nassert check_monthnumber_number(2)==False\nassert check_monthnumber_number(12)==False", "difficulty": "code"}
{"input": "Write a python function to find the minimum difference between any two elements in a given array.", "answer": "def find_Min_Diff(arr,n): \r\n    arr = sorted(arr) \r\n    diff = 10**20 \r\n    for i in range(n-1): \r\n        if arr[i+1] - arr[i] < diff: \r\n            diff = arr[i+1] - arr[i]  \r\n    return diff", "source": "mbpp", "task_id": "763", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a python function to count numeric values in a given string.", "answer": "def number_ctr(str):\r\n      number_ctr= 0\r\n      for i in range(len(str)):\r\n          if str[i] >= '0' and str[i] <= '9': number_ctr += 1     \r\n      return  number_ctr", "source": "mbpp", "task_id": "764", "test_cases": "assert number_ctr('program2bedone') == 1\nassert number_ctr('3wonders') ==1\nassert number_ctr('123') == 3", "difficulty": "code"}
{"input": "Write a function to find nth polite number.", "answer": "import math \r\ndef is_polite(n): \r\n\tn = n + 1\r\n\treturn (int)(n+(math.log((n + math.log(n, 2)), 2)))", "source": "mbpp", "task_id": "765", "test_cases": "assert is_polite(7) == 11\nassert is_polite(4) == 7\nassert is_polite(9) == 13", "difficulty": "code"}
{"input": "Write a function to iterate over all pairs of consecutive items in a given list.", "answer": "def pair_wise(l1):\r\n    temp = []\r\n    for i in range(len(l1) - 1):\r\n        current_element, next_element = l1[i], l1[i + 1]\r\n        x = (current_element, next_element)\r\n        temp.append(x)\r\n    return temp", "source": "mbpp", "task_id": "766", "test_cases": "assert 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([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)]", "difficulty": "code"}
{"input": "Write a python function to count the number of pairs whose sum is equal to ‘sum’.", "answer": "def get_Pairs_Count(arr,n,sum):\r\n    count = 0  \r\n    for i in range(0,n):\r\n        for j in range(i + 1,n):\r\n            if arr[i] + arr[j] == sum:\r\n                count += 1\r\n    return count", "source": "mbpp", "task_id": "767", "test_cases": "assert get_Pairs_Count([1,1,1,1],4,2) == 6\nassert get_Pairs_Count([1,5,7,-1,5],5,6) == 3\nassert get_Pairs_Count([1,-2,3],3,1) == 1", "difficulty": "code"}
{"input": "Write a python function to check for odd parity of a given number.", "answer": "def check_Odd_Parity(x): \r\n    parity = 0\r\n    while (x != 0): \r\n        x = x & (x - 1) \r\n        parity += 1\r\n    if (parity % 2 == 1): \r\n        return True\r\n    else: \r\n        return False", "source": "mbpp", "task_id": "768", "test_cases": "assert check_Odd_Parity(13) == True\nassert check_Odd_Parity(21) == True\nassert check_Odd_Parity(18) == False", "difficulty": "code"}
{"input": "Write a python function to get the difference between two lists.", "answer": "def Diff(li1,li2):\r\n    return (list(list(set(li1)-set(li2)) + list(set(li2)-set(li1))))", "source": "mbpp", "task_id": "769", "test_cases": "assert (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]", "difficulty": "code"}
{"input": "Write a python function to find the sum of fourth power of first n odd natural numbers.", "answer": "def odd_Num_Sum(n) : \r\n    j = 0\r\n    sm = 0\r\n    for i in range(1,n + 1) : \r\n        j = (2*i-1) \r\n        sm = sm + (j*j*j*j)   \r\n    return sm", "source": "mbpp", "task_id": "770", "test_cases": "assert odd_Num_Sum(2) == 82\nassert odd_Num_Sum(3) == 707\nassert odd_Num_Sum(4) == 3108", "difficulty": "code"}
{"input": "Write a function to check if the given expression is balanced or not.", "answer": "from collections import deque\r\ndef check_expression(exp):\r\n    if len(exp) & 1:\r\n        return False\r\n    stack = deque()\r\n    for ch in exp:\r\n        if ch == '(' or ch == '{' or ch == '[':\r\n            stack.append(ch)\r\n        if ch == ')' or ch == '}' or ch == ']':\r\n            if not stack:\r\n                return False\r\n            top = stack.pop()\r\n            if (top == '(' and ch != ')') or (top == '{' and ch != '}' or (top == '[' and ch != ']')):\r\n                return False\r\n    return not stack", "source": "mbpp", "task_id": "771", "test_cases": "assert check_expression(\"{()}[{}]\") == True\nassert check_expression(\"{()}[{]\") == False\nassert check_expression(\"{()}[{}][]({})\") == True", "difficulty": "code"}
{"input": "Write a function to remove all the words with k length in the given string.", "answer": "def remove_length(test_str, K):\r\n  temp = test_str.split()\r\n  res = [ele for ele in temp if len(ele) != K]\r\n  res = ' '.join(res)\r\n  return (res)", "source": "mbpp", "task_id": "772", "test_cases": "assert 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'", "difficulty": "code"}
{"input": "Write a function to find the occurrence and position of the substrings within a string.", "answer": "import re\r\ndef occurance_substring(text,pattern):\r\n for match in re.finditer(pattern, text):\r\n    s = match.start()\r\n    e = match.end()\r\n    return (text[s:e], s, e)", "source": "mbpp", "task_id": "773", "test_cases": "assert 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)", "difficulty": "code"}
{"input": "Write a function to check if the string is a valid email address or not using regex.", "answer": "import re \r\nregex = '^[a-z0-9]+[\\._]?[a-z0-9]+[@]\\w+[.]\\w{2,3}$'\r\ndef check_email(email): \r\n\tif(re.search(regex,email)): \r\n\t\treturn (\"Valid Email\") \r\n\telse: \r\n\t\treturn (\"Invalid Email\")", "source": "mbpp", "task_id": "774", "test_cases": "assert check_email(\"ankitrai326@gmail.com\") == 'Valid Email'\nassert check_email(\"my.ownsite@ourearth.org\") == 'Valid Email'\nassert check_email(\"ankitaoie326.com\") == 'Invalid Email'", "difficulty": "code"}
{"input": "Write a python function to check whether every odd index contains odd numbers of a given list.", "answer": "def odd_position(nums):\r\n\treturn all(nums[i]%2==i%2 for i in range(len(nums)))", "source": "mbpp", "task_id": "775", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a function to count those characters which have vowels as their neighbors in the given string.", "answer": "def count_vowels(test_str):\r\n  res = 0\r\n  vow_list = ['a', 'e', 'i', 'o', 'u']\r\n  for idx in range(1, len(test_str) - 1):\r\n    if test_str[idx] not in vow_list and (test_str[idx - 1] in vow_list or test_str[idx + 1] in vow_list):\r\n      res += 1\r\n  if test_str[0] not in vow_list and test_str[1] in vow_list:\r\n    res += 1\r\n  if test_str[-1] not in vow_list and test_str[-2] in vow_list:\r\n    res += 1\r\n  return (res)", "source": "mbpp", "task_id": "776", "test_cases": "assert count_vowels('bestinstareels') == 7\nassert count_vowels('partofthejourneyistheend') == 12\nassert count_vowels('amazonprime') == 5", "difficulty": "code"}
{"input": "Write a python function to find the sum of non-repeated elements in a given array.", "answer": "def find_Sum(arr,n): \r\n    arr.sort() \r\n    sum = arr[0] \r\n    for i in range(0,n-1): \r\n        if (arr[i] != arr[i+1]): \r\n            sum = sum + arr[i+1]   \r\n    return sum", "source": "mbpp", "task_id": "777", "test_cases": "assert find_Sum([1,2,3,1,1,4,5,6],8) == 21\nassert find_Sum([1,10,9,4,2,10,10,45,4],9) == 71\nassert find_Sum([12,10,9,45,2,10,10,45,10],9) == 78", "difficulty": "code"}
{"input": "Write a function to pack consecutive duplicates of a given list elements into sublists.", "answer": "from itertools import groupby\r\ndef pack_consecutive_duplicates(list1):\r\n    return [list(group) for key, group in groupby(list1)]", "source": "mbpp", "task_id": "778", "test_cases": "assert 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']]", "difficulty": "code"}
{"input": "Write a function to count the number of unique lists within a list.", "answer": "def unique_sublists(list1):\r\n    result ={}\r\n    for l in list1: \r\n        result.setdefault(tuple(l), list()).append(1) \r\n    for a, b in result.items(): \r\n        result[a] = sum(b)\r\n    return result", "source": "mbpp", "task_id": "779", "test_cases": "assert 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([[1, 2], [3, 4], [4, 5], [6, 7]])=={(1, 2): 1, (3, 4): 1, (4, 5): 1, (6, 7): 1}", "difficulty": "code"}
{"input": "Write a function to find the combinations of sums with tuples in the given tuple list.", "answer": "from itertools import combinations \r\ndef find_combinations(test_list):\r\n  res = [(b1 + a1, b2 + a2) for (a1, a2), (b1, b2) in combinations(test_list, 2)]\r\n  return (res)", "source": "mbpp", "task_id": "780", "test_cases": "assert 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)]", "difficulty": "code"}
{"input": "Write a python function to check whether the count of divisors is even or odd.", "answer": "import math \r\ndef count_Divisors(n) : \r\n    count = 0\r\n    for i in range(1, (int)(math.sqrt(n)) + 2) : \r\n        if (n % i == 0) : \r\n            if( n // i == i) : \r\n                count = count + 1\r\n            else : \r\n                count = count + 2\r\n    if (count % 2 == 0) : \r\n        return (\"Even\") \r\n    else : \r\n        return (\"Odd\")", "source": "mbpp", "task_id": "781", "test_cases": "assert count_Divisors(10) == \"Even\"\nassert count_Divisors(100) == \"Odd\"\nassert count_Divisors(125) == \"Even\"", "difficulty": "code"}
{"input": "Write a python function to find the sum of all odd length subarrays.", "answer": "def Odd_Length_Sum(arr):\r\n    Sum = 0\r\n    l = len(arr)\r\n    for i in range(l):\r\n        Sum += ((((i + 1) *(l - i) + 1) // 2) * arr[i])\r\n    return Sum", "source": "mbpp", "task_id": "782", "test_cases": "assert Odd_Length_Sum([1,2,4]) == 14\nassert Odd_Length_Sum([1,2,1,2]) == 15\nassert Odd_Length_Sum([1,7]) == 8", "difficulty": "code"}
{"input": "Write a function to convert rgb color to hsv color.", "answer": "def rgb_to_hsv(r, g, b):\r\n    r, g, b = r/255.0, g/255.0, b/255.0\r\n    mx = max(r, g, b)\r\n    mn = min(r, g, b)\r\n    df = mx-mn\r\n    if mx == mn:\r\n        h = 0\r\n    elif mx == r:\r\n        h = (60 * ((g-b)/df) + 360) % 360\r\n    elif mx == g:\r\n        h = (60 * ((b-r)/df) + 120) % 360\r\n    elif mx == b:\r\n        h = (60 * ((r-g)/df) + 240) % 360\r\n    if mx == 0:\r\n        s = 0\r\n    else:\r\n        s = (df/mx)*100\r\n    v = mx*100\r\n    return h, s, v", "source": "mbpp", "task_id": "783", "test_cases": "assert rgb_to_hsv(255, 255, 255)==(0, 0.0, 100.0)\nassert rgb_to_hsv(0, 215, 0)==(120.0, 100.0, 84.31372549019608)\nassert rgb_to_hsv(10, 215, 110)==(149.26829268292684, 95.34883720930233, 84.31372549019608)", "difficulty": "code"}
{"input": "Write a function to find the product of first even and odd number of a given list.", "answer": "def mul_even_odd(list1):\r\n    first_even = next((el for el in list1 if el%2==0),-1)\r\n    first_odd = next((el for el in list1 if el%2!=0),-1)\r\n    return (first_even*first_odd)", "source": "mbpp", "task_id": "784", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a function to convert tuple string to integer tuple.", "answer": "def tuple_str_int(test_str):\r\n  res = tuple(int(num) for num in test_str.replace('(', '').replace(')', '').replace('...', '').split(', '))\r\n  return (res)", "source": "mbpp", "task_id": "785", "test_cases": "assert 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)", "difficulty": "code"}
{"input": "Write a function to locate the right insertion point for a specified value in sorted order.", "answer": "import bisect\r\ndef right_insertion(a, x):\r\n    i = bisect.bisect_right(a, x)\r\n    return i", "source": "mbpp", "task_id": "786", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a function that matches a string that has an a followed by three 'b'.", "answer": "import re\r\ndef text_match_three(text):\r\n        patterns = 'ab{3}?'\r\n        if re.search(patterns,  text):\r\n                return 'Found a match!'\r\n        else:\r\n                return('Not matched!')", "source": "mbpp", "task_id": "787", "test_cases": "assert text_match_three(\"ac\")==('Not matched!')\nassert text_match_three(\"dc\")==('Not matched!')\nassert text_match_three(\"abbbba\")==('Found a match!')", "difficulty": "code"}
{"input": "Write a function to create a new tuple from the given string and list.", "answer": "def new_tuple(test_list, test_str):\r\n  res = tuple(test_list + [test_str])\r\n  return (res)", "source": "mbpp", "task_id": "788", "test_cases": "assert 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')", "difficulty": "code"}
{"input": "Write a function to calculate the perimeter of a regular polygon.", "answer": "from math import tan, pi\r\ndef perimeter_polygon(s,l):\r\n  perimeter = s*l\r\n  return perimeter", "source": "mbpp", "task_id": "789", "test_cases": "assert perimeter_polygon(4,20)==80\nassert perimeter_polygon(10,15)==150\nassert perimeter_polygon(9,7)==63", "difficulty": "code"}
{"input": "Write a python function to check whether every even index contains even numbers of a given list.", "answer": "def even_position(nums):\r\n\treturn all(nums[i]%2==i%2 for i in range(len(nums)))", "source": "mbpp", "task_id": "790", "test_cases": "assert even_position([3,2,1]) == False\nassert even_position([1,2,3]) == False\nassert even_position([2,1,4]) == True", "difficulty": "code"}
{"input": "Write a function to remove the nested record from the given tuple.", "answer": "def remove_nested(test_tup):\r\n  res = tuple()\r\n  for count, ele in enumerate(test_tup):\r\n    if not isinstance(ele, tuple):\r\n      res = res + (ele, )\r\n  return (res)", "source": "mbpp", "task_id": "791", "test_cases": "assert 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)", "difficulty": "code"}
{"input": "Write a python function to count the number of lists in a given number of lists.", "answer": "def count_list(input_list): \r\n    return len(input_list)", "source": "mbpp", "task_id": "792", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a python function to find the last position of an element in a sorted array.", "answer": "def last(arr,x,n):\r\n    low = 0\r\n    high = n - 1\r\n    res = -1  \r\n    while (low <= high):\r\n        mid = (low + high) // 2 \r\n        if arr[mid] > x:\r\n            high = mid - 1\r\n        elif arr[mid] < x:\r\n            low = mid + 1\r\n        else:\r\n            res = mid\r\n            low = mid + 1\r\n    return res", "source": "mbpp", "task_id": "793", "test_cases": "assert last([1,2,3],1,3) == 0\nassert last([1,1,1,2,3,4],1,6) == 2\nassert last([2,3,2,3,6,8,9],3,8) == 3", "difficulty": "code"}
{"input": "Write a function that matches a string that has an 'a' followed by anything, ending in 'b'.", "answer": "import re\r\ndef text_starta_endb(text):\r\n        patterns = 'a.*?b$'\r\n        if re.search(patterns,  text):\r\n                return 'Found a match!'\r\n        else:\r\n                return('Not matched!')", "source": "mbpp", "task_id": "794", "test_cases": "assert text_starta_endb(\"aabbbb\")==('Found a match!')\nassert text_starta_endb(\"aabAbbbc\")==('Not matched!')\nassert text_starta_endb(\"accddbbjjj\")==('Not matched!')", "difficulty": "code"}
{"input": "Write a function to find the n - cheap price items from a given dataset using heap queue algorithm.", "answer": "import heapq\r\ndef cheap_items(items,n):\r\n  cheap_items = heapq.nsmallest(n, items, key=lambda s: s['price'])\r\n  return cheap_items", "source": "mbpp", "task_id": "795", "test_cases": "assert cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],1)==[{'name': 'Item-1', 'price': 101.1}]\nassert cheap_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],2)==[{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}]\nassert cheap_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-4', 'price': 22.75}]", "difficulty": "code"}
{"input": "Write function to find the sum of all items in the given dictionary.", "answer": "def return_sum(dict):\r\n  sum = 0\r\n  for i in dict.values():\r\n    sum = sum + i\r\n  return sum", "source": "mbpp", "task_id": "796", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a python function to find the sum of all odd natural numbers within the range l and r.", "answer": "def sum_Odd(n): \r\n    terms = (n + 1)//2\r\n    sum1 = terms * terms \r\n    return sum1  \r\ndef sum_in_Range(l,r): \r\n    return sum_Odd(r) - sum_Odd(l - 1)", "source": "mbpp", "task_id": "797", "test_cases": "assert sum_in_Range(2,5) == 8\nassert sum_in_Range(5,7) == 12\nassert sum_in_Range(7,13) == 40", "difficulty": "code"}
{"input": "Write a python function to find the sum of an array.", "answer": "def _sum(arr):  \r\n    sum=0\r\n    for i in arr: \r\n        sum = sum + i      \r\n    return(sum)", "source": "mbpp", "task_id": "798", "test_cases": "assert _sum([1, 2, 3]) == 6\nassert _sum([15, 12, 13, 10]) == 50\nassert _sum([0, 1, 2]) == 3", "difficulty": "code"}
{"input": "Write a python function to left rotate the bits of a given number.", "answer": "INT_BITS = 32\r\ndef left_Rotate(n,d):   \r\n    return (n << d)|(n >> (INT_BITS - d))", "source": "mbpp", "task_id": "799", "test_cases": "assert left_Rotate(16,2) == 64\nassert left_Rotate(10,2) == 40\nassert left_Rotate(99,3) == 792", "difficulty": "code"}
{"input": "Write a function to remove all whitespaces from a string.", "answer": "import re\r\ndef remove_all_spaces(text):\r\n return (re.sub(r'\\s+', '',text))", "source": "mbpp", "task_id": "800", "test_cases": "assert remove_all_spaces('python  program')==('pythonprogram')\nassert remove_all_spaces('python   programming    language')==('pythonprogramminglanguage')\nassert remove_all_spaces('python                     program')==('pythonprogram')", "difficulty": "code"}
{"input": "Write a python function to count the number of equal numbers from three given integers.", "answer": "def test_three_equal(x,y,z):\r\n  result= set([x,y,z])\r\n  if len(result)==3:\r\n    return 0\r\n  else:\r\n    return (4-len(result))", "source": "mbpp", "task_id": "801", "test_cases": "assert test_three_equal(1,1,1) == 3\nassert test_three_equal(-1,-2,-3) == 0\nassert test_three_equal(1,2,2) == 2", "difficulty": "code"}
{"input": "Write a python function to count the number of rotations required to generate a sorted array.", "answer": "def count_Rotation(arr,n):   \r\n    for i in range (1,n): \r\n        if (arr[i] < arr[i - 1]): \r\n            return i  \r\n    return 0", "source": "mbpp", "task_id": "802", "test_cases": "assert count_Rotation([3,2,1],3) == 1\nassert count_Rotation([4,5,1,2,3],5) == 2\nassert count_Rotation([7,8,9,1,2,3],6) == 3", "difficulty": "code"}
{"input": "Write a python function to check whether the given number is a perfect square or not.", "answer": "def is_Perfect_Square(n) :\r\n    i = 1\r\n    while (i * i<= n):\r\n        if ((n % i == 0) and (n / i == i)):\r\n            return True     \r\n        i = i + 1\r\n    return False", "source": "mbpp", "task_id": "803", "test_cases": "assert is_Perfect_Square(10) == False\nassert is_Perfect_Square(36) == True\nassert is_Perfect_Square(14) == False", "difficulty": "code"}
{"input": "Write a python function to check whether the product of numbers is even or not.", "answer": "def is_Product_Even(arr,n): \r\n    for i in range(0,n): \r\n        if ((arr[i] & 1) == 0): \r\n            return True\r\n    return False", "source": "mbpp", "task_id": "804", "test_cases": "assert is_Product_Even([1,2,3],3) == True\nassert is_Product_Even([1,2,1,4],4) == True\nassert is_Product_Even([1,1],2) == False", "difficulty": "code"}
{"input": "Write a function to find the list in a list of lists whose sum of elements is the highest.", "answer": "def max_sum_list(lists):\r\n return max(lists, key=sum)", "source": "mbpp", "task_id": "805", "test_cases": "assert 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] ", "difficulty": "code"}
{"input": "Write a function to find maximum run of uppercase characters in the given string.", "answer": "def max_run_uppercase(test_str):\r\n  cnt = 0\r\n  res = 0\r\n  for idx in range(0, len(test_str)):\r\n    if test_str[idx].isupper():\r\n      cnt += 1\r\n    else:\r\n      res = cnt\r\n      cnt = 0\r\n  if test_str[len(test_str) - 1].isupper():\r\n    res = cnt\r\n  return (res)", "source": "mbpp", "task_id": "806", "test_cases": "assert max_run_uppercase('GeMKSForGERksISBESt') == 5\nassert max_run_uppercase('PrECIOusMOVemENTSYT') == 6\nassert max_run_uppercase('GooGLEFluTTER') == 4", "difficulty": "code"}
{"input": "Write a python function to find the first odd number in a given list of numbers.", "answer": "def first_odd(nums):\r\n  first_odd = next((el for el in nums if el%2!=0),-1)\r\n  return first_odd", "source": "mbpp", "task_id": "807", "test_cases": "assert first_odd([1,3,5]) == 1\nassert first_odd([2,4,1,3]) == 1\nassert first_odd ([8,9,1]) == 9", "difficulty": "code"}
{"input": "Write a function to check if the given tuples contain the k or not.", "answer": "def check_K(test_tup, K):\r\n  res = False\r\n  for ele in test_tup:\r\n    if ele == K:\r\n      res = True\r\n      break\r\n  return (res)", "source": "mbpp", "task_id": "808", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple.", "answer": "def check_smaller(test_tup1, test_tup2):\r\n  res = all(x > y for x, y in zip(test_tup1, test_tup2))\r\n  return (res)", "source": "mbpp", "task_id": "809", "test_cases": "assert 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", "difficulty": "code"}
{"input": "Write a function to iterate over elements repeating each as many times as its count.", "answer": "from collections import Counter\r\ndef count_variable(a,b,c,d):\r\n  c = Counter(p=a, q=b, r=c, s=d)\r\n  return list(c.elements())", "source": "mbpp", "task_id": "810", "test_cases": "assert count_variable(4,2,0,-2)==['p', 'p', 'p', 'p', 'q', 'q'] \nassert count_variable(0,1,2,3)==['q', 'r', 'r', 's', 's', 's'] \nassert count_variable(11,15,12,23)==['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's', 's']", "difficulty": "code"}
{"input": "Write a function to check if two lists of tuples are identical or not.", "answer": "def check_identical(test_list1, test_list2):\r\n  res = test_list1 == test_list2\r\n  return (res)", "source": "mbpp", "task_id": "811", "test_cases": "assert check_identical([(10, 4), (2, 5)], [(10, 4), (2, 5)]) == True\nassert check_identical([(1, 2), (3, 7)], [(12, 14), (12, 45)]) == False\nassert check_identical([(2, 14), (12, 25)], [(2, 14), (12, 25)]) == True", "difficulty": "code"}
{"input": "Write a function to abbreviate 'road' as 'rd.' in a given string.", "answer": "import re\r\ndef road_rd(street):\r\n  return (re.sub('Road$', 'Rd.', street))", "source": "mbpp", "task_id": "812", "test_cases": "assert road_rd(\"ravipadu Road\")==('ravipadu Rd.')\nassert road_rd(\"palnadu Road\")==('palnadu Rd.')\nassert road_rd(\"eshwar enclave Road\")==('eshwar enclave Rd.')", "difficulty": "code"}
{"input": "Write a function to find length of the string.", "answer": "def string_length(str1):\r\n    count = 0\r\n    for char in str1:\r\n        count += 1\r\n    return count", "source": "mbpp", "task_id": "813", "test_cases": "assert string_length('python')==6\nassert string_length('program')==7\nassert string_length('language')==8", "difficulty": "code"}
{"input": "Write a function to find the area of a rombus.", "answer": "def rombus_area(p,q):\r\n  area=(p*q)/2\r\n  return area", "source": "mbpp", "task_id": "814", "test_cases": "assert rombus_area(10,20)==100\nassert rombus_area(10,5)==25\nassert rombus_area(4,2)==4", "difficulty": "code"}
{"input": "Write a function to sort the given array without using any sorting algorithm. the given array consists of only 0, 1, and 2.", "answer": "def sort_by_dnf(arr, n):\r\n  low=0\r\n  mid=0\r\n  high=n-1\r\n  while mid <= high:\r\n    if arr[mid] == 0:\r\n      arr[low], arr[mid] = arr[mid], arr[low]\r\n      low = low + 1\r\n      mid = mid + 1\r\n    elif arr[mid] == 1:\r\n      mid = mid + 1\r\n    else:\r\n      arr[mid], arr[high] = arr[high], arr[mid]\r\n      high = high - 1\r\n  return arr", "source": "mbpp", "task_id": "815", "test_cases": "assert sort_by_dnf([1,2,0,1,0,1,2,1,1], 9) == [0, 0, 1, 1, 1, 1, 1, 2, 2]\nassert sort_by_dnf([1,0,0,1,2,1,2,2,1,0], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]\nassert sort_by_dnf([2,2,1,0,0,0,1,1,2,1], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2]", "difficulty": "code"}
{"input": "Write a function to clear the values of the given tuples.", "answer": "def clear_tuple(test_tup):\r\n  temp = list(test_tup)\r\n  temp.clear()\r\n  test_tup = tuple(temp)\r\n  return (test_tup)", "source": "mbpp", "task_id": "816", "test_cases": "assert clear_tuple((1, 5, 3, 6, 8)) == ()\nassert clear_tuple((2, 1, 4 ,5 ,6)) == ()\nassert clear_tuple((3, 2, 5, 6, 8)) == ()", "difficulty": "code"}
{"input": "Write a function to find numbers divisible by m or n from a list of numbers using lambda function.", "answer": "def div_of_nums(nums,m,n):\r\n result = list(filter(lambda x: (x % m == 0 or x % n == 0), nums)) \r\n return result", "source": "mbpp", "task_id": "817", "test_cases": "assert div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190],19,13)==[19, 65, 57, 39, 152, 190]\nassert div_of_nums([1, 2, 3, 5, 7, 8, 10],2,5)==[2, 5, 8, 10]\nassert div_of_nums([10,15,14,13,18,12,20],10,5)==[10, 15, 20]", "difficulty": "code"}
{"input": "Write a python function to count lower case letters in a given string.", "answer": "def lower_ctr(str):\r\n      lower_ctr= 0\r\n      for i in range(len(str)):\r\n          if str[i] >= 'a' and str[i] <= 'z': lower_ctr += 1     \r\n      return  lower_ctr", "source": "mbpp", "task_id": "818", "test_cases": "assert lower_ctr('abc') == 3\nassert lower_ctr('string') == 6\nassert lower_ctr('Python') == 5", "difficulty": "code"}
{"input": "Write a function to count the frequency of consecutive duplicate elements in a given list of numbers.", "answer": "def count_duplic(lists):\r\n    element = []\r\n    frequency = []\r\n    if not lists:\r\n        return element\r\n    running_count = 1\r\n    for i in range(len(lists)-1):\r\n        if lists[i] == lists[i+1]:\r\n            running_count += 1\r\n        else:\r\n            frequency.append(running_count)\r\n            element.append(lists[i])\r\n            running_count = 1\r\n    frequency.append(running_count)\r\n    element.append(lists[i+1])\r\n    return element,frequency", "source": "mbpp", "task_id": "819", "test_cases": "assert count_duplic([1,2,2,2,4,4,4,5,5,5,5])==([1, 2, 4, 5], [1, 3, 3, 4])\nassert count_duplic([2,2,3,1,2,6,7,9])==([2, 3, 1, 2, 6, 7, 9], [2, 1, 1, 1, 1, 1, 1])\nassert count_duplic([2,1,5,6,8,3,4,9,10,11,8,12])==([2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])", "difficulty": "code"}
{"input": "Write a function to check whether the given month number contains 28 days or not.", "answer": "def check_monthnum_number(monthnum1):\r\n  if monthnum1 == 2:\r\n    return True\r\n  else:\r\n    return False", "source": "mbpp", "task_id": "820", "test_cases": "assert check_monthnum_number(2)==True\nassert check_monthnum_number(1)==False\nassert check_monthnum_number(3)==False", "difficulty": "code"}
{"input": "Write a function to merge two dictionaries into a single expression.", "answer": "import collections as ct\r\ndef merge_dictionaries(dict1,dict2):\r\n    merged_dict = dict(ct.ChainMap({}, dict1, dict2))\r\n    return merged_dict", "source": "mbpp", "task_id": "821", "test_cases": "assert merge_dictionaries({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White'}\nassert merge_dictionaries({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" },{ \"O\": \"Orange\", \"W\": \"White\", \"B\": \"Black\" })=={'O': 'Orange', 'P': 'Pink', 'B': 'Black', 'W': 'White', 'R': 'Red'}\nassert merge_dictionaries({ \"G\": \"Green\", \"W\": \"White\" },{ \"O\": \"Orange\", \"W\": \"White\", \"B\": \"Black\" })=={'W': 'White', 'O': 'Orange', 'G': 'Green', 'B': 'Black'}", "difficulty": "code"}
{"input": "Write a function to return true if the password is valid.", "answer": "import re\r\ndef pass_validity(p):\r\n x = True\r\n while x:  \r\n    if (len(p)<6 or len(p)>12):\r\n        break\r\n    elif not re.search(\"[a-z]\",p):\r\n        break\r\n    elif not re.search(\"[0-9]\",p):\r\n        break\r\n    elif not re.search(\"[A-Z]\",p):\r\n        break\r\n    elif not re.search(\"[$#@]\",p):\r\n        break\r\n    elif re.search(\"\\s\",p):\r\n        break\r\n    else:\r\n        return True\r\n        x=False\r\n        break\r\n\r\n if x:\r\n    return False", "source": "mbpp", "task_id": "822", "test_cases": "assert pass_validity(\"password\")==False\nassert pass_validity(\"Password@10\")==True\nassert pass_validity(\"password@10\")==False", "difficulty": "code"}
{"input": "Write a function to check if the given string starts with a substring using regex.", "answer": "import re \r\ndef check_substring(string, sample) : \r\n  if (sample in string): \r\n      y = \"\\A\" + sample \r\n      x = re.search(y, string) \r\n      if x : \r\n          return (\"string starts with the given substring\") \r\n      else : \r\n          return (\"string doesnt start with the given substring\") \r\n  else : \r\n      return (\"entered string isnt a substring\")", "source": "mbpp", "task_id": "823", "test_cases": "assert check_substring(\"dreams for dreams makes life fun\", \"makes\") == 'string doesnt start with the given substring'\nassert check_substring(\"Hi there how are you Hi alex\", \"Hi\") == 'string starts with the given substring'\nassert check_substring(\"Its been a long day\", \"been\") == 'string doesnt start with the given substring'", "difficulty": "code"}
{"input": "Write a python function to remove even numbers from a given list.", "answer": "def remove_even(l):\r\n    for i in l:\r\n        if i % 2 == 0:\r\n            l.remove(i)\r\n    return l", "source": "mbpp", "task_id": "824", "test_cases": "assert remove_even([1,3,5,2]) == [1,3,5]\nassert remove_even([5,6,7]) == [5,7]\nassert remove_even([1,2,3,4]) == [1,3]", "difficulty": "code"}
{"input": "Write a python function to access multiple elements of specified index from a given list.", "answer": "def access_elements(nums, list_index):\r\n    result = [nums[i] for i in list_index]\r\n    return result", "source": "mbpp", "task_id": "825", "test_cases": "assert access_elements([2,3,8,4,7,9],[0,3,5]) == [2, 4, 9]\nassert access_elements([1, 2, 3, 4, 5],[1,2]) == [2,3]\nassert access_elements([1,0,2,3],[0,1]) == [1,0]", "difficulty": "code"}
{"input": "Write a python function to find the type of triangle from the given sides.", "answer": "def check_Type_Of_Triangle(a,b,c): \r\n    sqa = pow(a,2) \r\n    sqb = pow(b,2) \r\n    sqc = pow(c,2) \r\n    if (sqa == sqa + sqb or sqb == sqa + sqc or sqc == sqa + sqb): \r\n        return (\"Right-angled Triangle\") \r\n    elif (sqa > sqc + sqb or sqb > sqa + sqc or sqc > sqa + sqb): \r\n        return (\"Obtuse-angled Triangle\") \r\n    else: \r\n        return (\"Acute-angled Triangle\")", "source": "mbpp", "task_id": "826", "test_cases": "assert check_Type_Of_Triangle(1,2,3) == \"Obtuse-angled Triangle\"\nassert check_Type_Of_Triangle(2,2,2) == \"Acute-angled Triangle\"\nassert check_Type_Of_Triangle(1,0,1) == \"Right-angled Triangle\"", "difficulty": "code"}
{"input": "Write a function to sum a specific column of a list in a given list of lists.", "answer": "def sum_column(list1, C):\r\n    result = sum(row[C] for row in list1)\r\n    return result", "source": "mbpp", "task_id": "827", "test_cases": "assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],0)==12\nassert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],1)==15\nassert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],3)==9", "difficulty": "code"}
{"input": "Write a function to count alphabets,digits and special charactes in a given string.", "answer": "def count_alpha_dig_spl(string):\r\n  alphabets=digits = special = 0\r\n  for i in range(len(string)):\r\n    if(string[i].isalpha()):\r\n        alphabets = alphabets + 1\r\n    elif(string[i].isdigit()):\r\n        digits = digits + 1\r\n    else:\r\n        special = special + 1\r\n  return (alphabets,digits,special)", "source": "mbpp", "task_id": "828", "test_cases": "assert count_alpha_dig_spl(\"abc!@#123\")==(3,3,3)\nassert count_alpha_dig_spl(\"dgsuy@#$%&1255\")==(5,4,5)\nassert count_alpha_dig_spl(\"fjdsif627348#%$^&\")==(6,6,5)", "difficulty": "code"}
{"input": "Write a function to find out the second most repeated (or frequent) string in the given sequence.", "answer": "from collections import Counter \r\n\t\r\ndef second_frequent(input): \r\n\tdict = Counter(input) \r\n\tvalue = sorted(dict.values(), reverse=True)  \r\n\tsecond_large = value[1] \r\n\tfor (key, val) in dict.items(): \r\n\t\tif val == second_large: \r\n\t\t\treturn (key)", "source": "mbpp", "task_id": "829", "test_cases": "assert second_frequent(['aaa','bbb','ccc','bbb','aaa','aaa']) == 'bbb'\nassert second_frequent(['abc','bcd','abc','bcd','bcd','bcd']) == 'abc'\nassert second_frequent(['cdma','gsm','hspa','gsm','cdma','cdma']) == 'gsm'", "difficulty": "code"}
{"input": "Write a function to round up a number to specific digits.", "answer": "import math\r\ndef round_up(a, digits):\r\n    n = 10**-digits\r\n    return round(math.ceil(a / n) * n, digits)", "source": "mbpp", "task_id": "830", "test_cases": "assert round_up(123.01247,0)==124\nassert round_up(123.01247,1)==123.1\nassert round_up(123.01247,2)==123.02", "difficulty": "code"}
{"input": "Write a python function to count equal element pairs from the given array.", "answer": "def count_Pairs(arr,n): \r\n    cnt = 0; \r\n    for i in range(n): \r\n        for j in range(i + 1,n): \r\n            if (arr[i] == arr[j]): \r\n                cnt += 1; \r\n    return cnt;", "source": "mbpp", "task_id": "831", "test_cases": "assert count_Pairs([1,1,1,1],4) == 6\nassert count_Pairs([1,5,1],3) == 1\nassert count_Pairs([3,2,1,7,8,9],6) == 0", "difficulty": "code"}
{"input": "Write a function to extract the maximum numeric value from a string by using regex.", "answer": "import re \r\ndef extract_max(input): \r\n\tnumbers = re.findall('\\d+',input) \r\n\tnumbers = map(int,numbers) \r\n\treturn max(numbers)", "source": "mbpp", "task_id": "832", "test_cases": "assert extract_max('100klh564abc365bg') == 564\nassert extract_max('hello300how546mer231') == 546\nassert extract_max('its233beenalong343journey234') == 343", "difficulty": "code"}
{"input": "Write a function to get dictionary keys as a list.", "answer": "def get_key(dict): \r\n    list = [] \r\n    for key in dict.keys(): \r\n        list.append(key)           \r\n    return list", "source": "mbpp", "task_id": "833", "test_cases": "assert get_key({1:'python',2:'java'})==[1,2]\nassert get_key({10:'red',20:'blue',30:'black'})==[10,20,30]\nassert get_key({27:'language',39:'java',44:'little'})==[27,39,44]", "difficulty": "code"}
{"input": "Write a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order.", "answer": "def generate_matrix(n):\r\n        if n<=0:\r\n            return [] \r\n        matrix=[row[:] for row in [[0]*n]*n]        \r\n        row_st=0\r\n        row_ed=n-1        \r\n        col_st=0\r\n        col_ed=n-1\r\n        current=1        \r\n        while (True):\r\n            if current>n*n:\r\n                break\r\n            for c in range (col_st, col_ed+1):\r\n                matrix[row_st][c]=current\r\n                current+=1\r\n            row_st+=1\r\n            for r in range (row_st, row_ed+1):\r\n                matrix[r][col_ed]=current\r\n                current+=1\r\n            col_ed-=1\r\n            for c in range (col_ed, col_st-1, -1):\r\n                matrix[row_ed][c]=current\r\n                current+=1\r\n            row_ed-=1\r\n            for r in range (row_ed, row_st-1, -1):\r\n                matrix[r][col_st]=current\r\n                current+=1\r\n            col_st+=1\r\n        return matrix", "source": "mbpp", "task_id": "834", "test_cases": "assert generate_matrix(3)==[[1, 2, 3], [8, 9, 4], [7, 6, 5]] \nassert generate_matrix(2)==[[1,2],[4,3]]\nassert generate_matrix(7)==[[1, 2, 3, 4, 5, 6, 7], [24, 25, 26, 27, 28, 29, 8], [23, 40, 41, 42, 43, 30, 9], [22, 39, 48, 49, 44, 31, 10], [21, 38, 47, 46, 45, 32, 11], [20, 37, 36, 35, 34, 33, 12], [19, 18, 17, 16, 15, 14, 13]]", "difficulty": "code"}
{"input": "Write a python function to find the slope of a line.", "answer": "def slope(x1,y1,x2,y2): \r\n    return (float)(y2-y1)/(x2-x1)", "source": "mbpp", "task_id": "835", "test_cases": "assert slope(4,2,2,5) == -1.5\nassert slope(2,4,4,6) == 1\nassert slope(1,2,4,2) == 0", "difficulty": "code"}
{"input": "Write a function to find length of the subarray having maximum sum.", "answer": "from sys import maxsize \r\ndef max_sub_array_sum(a,size): \r\n\tmax_so_far = -maxsize - 1\r\n\tmax_ending_here = 0\r\n\tstart = 0\r\n\tend = 0\r\n\ts = 0\r\n\tfor i in range(0,size): \r\n\t\tmax_ending_here += a[i] \r\n\t\tif max_so_far < max_ending_here: \r\n\t\t\tmax_so_far = max_ending_here \r\n\t\t\tstart = s \r\n\t\t\tend = i \r\n\t\tif max_ending_here < 0: \r\n\t\t\tmax_ending_here = 0\r\n\t\t\ts = i+1\r\n\treturn (end - start + 1)", "source": "mbpp", "task_id": "836", "test_cases": "assert max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3],8) == 5\nassert max_sub_array_sum([1, -2, 1, 1, -2, 1],6) == 2\nassert max_sub_array_sum([-1, -2, 3, 4, 5],5) == 3", "difficulty": "code"}
{"input": "Write a python function to find the cube sum of first n odd natural numbers.", "answer": "def cube_Sum(n): \r\n    sum = 0   \r\n    for i in range(0,n) : \r\n        sum += (2*i+1)*(2*i+1)*(2*i+1) \r\n    return sum", "source": "mbpp", "task_id": "837", "test_cases": "assert cube_Sum(2) == 28\nassert cube_Sum(3) == 153\nassert cube_Sum(4) == 496", "difficulty": "code"}
{"input": "Write a python function to find minimum number swaps required to make two binary strings equal.", "answer": "def min_Swaps(s1,s2) :  \r\n    c0 = 0; c1 = 0;  \r\n    for i in range(len(s1)) :  \r\n        if (s1[i] == '0' and s2[i] == '1') : \r\n            c0 += 1;    \r\n        elif (s1[i] == '1' and s2[i] == '0') : \r\n            c1 += 1;  \r\n    result = c0 // 2 + c1 // 2;  \r\n    if (c0 % 2 == 0 and c1 % 2 == 0) : \r\n        return result;  \r\n    elif ((c0 + c1) % 2 == 0) : \r\n        return result + 2;  \r\n    else : \r\n        return -1;", "source": "mbpp", "task_id": "838", "test_cases": "assert min_Swaps(\"0011\",\"1111\") == 1\nassert min_Swaps(\"00011\",\"01001\") == 2\nassert min_Swaps(\"111\",\"111\") == 0", "difficulty": "code"}
{"input": "Write a function to sort the tuples alphabetically by the first item of each tuple.", "answer": "def sort_tuple(tup): \r\n\tn = len(tup) \r\n\tfor i in range(n): \r\n\t\tfor j in range(n-i-1): \r\n\t\t\tif tup[j][0] > tup[j + 1][0]: \r\n\t\t\t\ttup[j], tup[j + 1] = tup[j + 1], tup[j] \r\n\treturn tup", "source": "mbpp", "task_id": "839", "test_cases": "assert sort_tuple([(\"Amana\", 28), (\"Zenat\", 30), (\"Abhishek\", 29),(\"Nikhil\", 21), (\"B\", \"C\")]) == [('Abhishek', 29), ('Amana', 28), ('B', 'C'), ('Nikhil', 21), ('Zenat', 30)]\nassert sort_tuple([(\"aaaa\", 28), (\"aa\", 30), (\"bab\", 29), (\"bb\", 21), (\"csa\", \"C\")]) == [('aa', 30), ('aaaa', 28), ('bab', 29), ('bb', 21), ('csa', 'C')]\nassert sort_tuple([(\"Sarala\", 28), (\"Ayesha\", 30), (\"Suman\", 29),(\"Sai\", 21), (\"G\", \"H\")]) == [('Ayesha', 30), ('G', 'H'), ('Sai', 21), ('Sarala', 28), ('Suman', 29)]", "difficulty": "code"}
{"input": "Write a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not.", "answer": "def Check_Solution(a,b,c):  \r\n    if b == 0:  \r\n        return (\"Yes\")  \r\n    else: \r\n        return (\"No\")", "source": "mbpp", "task_id": "840", "test_cases": "assert Check_Solution(2,0,-1) == \"Yes\"\nassert Check_Solution(1,-5,6) == \"No\"\nassert Check_Solution(2,0,2) == \"Yes\"", "difficulty": "code"}
{"input": "Write a function to count the number of inversions in the given array.", "answer": "def get_inv_count(arr, n): \r\n\tinv_count = 0\r\n\tfor i in range(n): \r\n\t\tfor j in range(i + 1, n): \r\n\t\t\tif (arr[i] > arr[j]): \r\n\t\t\t\tinv_count += 1\r\n\treturn inv_count", "source": "mbpp", "task_id": "841", "test_cases": "assert get_inv_count([1, 20, 6, 4, 5], 5) == 5\nassert get_inv_count([8, 4, 2, 1], 4) == 6\nassert get_inv_count([3, 1, 2], 3) == 2", "difficulty": "code"}
{"input": "Write a function to find the number which occurs for odd number of times in the given array.", "answer": "def get_odd_occurence(arr, arr_size):\r\n  for i in range(0, arr_size):\r\n    count = 0\r\n    for j in range(0, arr_size):\r\n      if arr[i] == arr[j]:\r\n        count += 1\r\n    if (count % 2 != 0):\r\n      return arr[i]\r\n  return -1", "source": "mbpp", "task_id": "842", "test_cases": "assert get_odd_occurence([2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2], 13) == 5\nassert get_odd_occurence([1, 2, 3, 2, 3, 1, 3], 7) == 3\nassert get_odd_occurence([5, 7, 2, 7, 5, 2, 5], 7) == 5", "difficulty": "code"}
{"input": "Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm.", "answer": "import heapq\r\ndef nth_super_ugly_number(n, primes):\r\n    uglies = [1]\r\n    def gen(prime):\r\n        for ugly in uglies:\r\n            yield ugly * prime\r\n    merged = heapq.merge(*map(gen, primes))\r\n    while len(uglies) < n:\r\n        ugly = next(merged)\r\n        if ugly != uglies[-1]:\r\n            uglies.append(ugly)\r\n    return uglies[-1]", "source": "mbpp", "task_id": "843", "test_cases": "assert nth_super_ugly_number(12,[2,7,13,19])==32\nassert nth_super_ugly_number(10,[2,7,13,19])==26\nassert nth_super_ugly_number(100,[2,7,13,19])==5408", "difficulty": "code"}
{"input": "Write a python function to find the kth element in an array containing odd elements first and then even elements.", "answer": "def get_Number(n, k): \r\n    arr = [0] * n; \r\n    i = 0; \r\n    odd = 1; \r\n    while (odd <= n):   \r\n        arr[i] = odd; \r\n        i += 1; \r\n        odd += 2;\r\n    even = 2; \r\n    while (even <= n): \r\n        arr[i] = even; \r\n        i += 1;\r\n        even += 2; \r\n    return arr[k - 1];", "source": "mbpp", "task_id": "844", "test_cases": "assert get_Number(8,5) == 2\nassert get_Number(7,2) == 3\nassert get_Number(5,2) == 3", "difficulty": "code"}
{"input": "Write a python function to count the number of digits in factorial of a given number.", "answer": "import math \r\ndef find_Digits(n): \r\n    if (n < 0): \r\n        return 0;\r\n    if (n <= 1): \r\n        return 1; \r\n    x = ((n * math.log10(n / math.e) + math.log10(2 * math.pi * n) /2.0)); \r\n    return math.floor(x) + 1;", "source": "mbpp", "task_id": "845", "test_cases": "assert find_Digits(7) == 4\nassert find_Digits(5) == 3\nassert find_Digits(4) == 2", "difficulty": "code"}
{"input": "Write a function to find the minimum number of platforms required for a railway/bus station.", "answer": "def find_platform(arr, dep, n): \r\n    arr.sort() \r\n    dep.sort() \r\n    plat_needed = 1\r\n    result = 1\r\n    i = 1\r\n    j = 0\r\n    while (i < n and j < n): \r\n        if (arr[i] <= dep[j]):           \r\n            plat_needed+= 1\r\n            i+= 1\r\n        elif (arr[i] > dep[j]):           \r\n            plat_needed-= 1\r\n            j+= 1\r\n        if (plat_needed > result):  \r\n            result = plat_needed           \r\n    return result", "source": "mbpp", "task_id": "846", "test_cases": "assert find_platform([900, 940, 950, 1100, 1500, 1800],[910, 1200, 1120, 1130, 1900, 2000],6)==3\nassert find_platform([100,200,300,400],[700,800,900,1000],4)==4\nassert find_platform([5,6,7,8],[4,3,2,1],4)==1", "difficulty": "code"}
{"input": "Write a python function to copy a list from a singleton tuple.", "answer": "def lcopy(xs):\n  return xs[:]", "source": "mbpp", "task_id": "847", "test_cases": "assert lcopy([1, 2, 3]) == [1, 2, 3]\nassert lcopy([4, 8, 2, 10, 15, 18]) == [4, 8, 2, 10, 15, 18]\nassert lcopy([4, 5, 6]) == [4, 5, 6]\n", "difficulty": "code"}
{"input": "Write a function to find the area of a trapezium.", "answer": "def area_trapezium(base1,base2,height):\r\n area = 0.5 * (base1 + base2) * height\r\n return area", "source": "mbpp", "task_id": "848", "test_cases": "assert area_trapezium(6,9,4)==30\nassert area_trapezium(10,20,30)==450\nassert area_trapezium(15,25,35)==700", "difficulty": "code"}
{"input": "Write a python function to find sum of all prime divisors of a given number.", "answer": "def Sum(N): \r\n    SumOfPrimeDivisors = [0]*(N + 1)   \r\n    for i in range(2,N + 1) : \r\n        if (SumOfPrimeDivisors[i] == 0) : \r\n            for j in range(i,N + 1,i) : \r\n                SumOfPrimeDivisors[j] += i           \r\n    return SumOfPrimeDivisors[N]", "source": "mbpp", "task_id": "849", "test_cases": "assert Sum(60) == 10\nassert Sum(39) == 16\nassert Sum(40) == 7", "difficulty": "code"}
{"input": "Write a function to check if a triangle of positive area is possible with the given angles.", "answer": "def is_triangleexists(a,b,c): \r\n    if(a != 0 and b != 0 and c != 0 and (a + b + c)== 180): \r\n        if((a + b)>= c or (b + c)>= a or (a + c)>= b): \r\n            return True \r\n        else:\r\n            return False\r\n    else:\r\n        return False", "source": "mbpp", "task_id": "850", "test_cases": "assert is_triangleexists(50,60,70)==True\nassert is_triangleexists(90,45,45)==True\nassert is_triangleexists(150,30,70)==False", "difficulty": "code"}
{"input": "Write a python function to find sum of inverse of divisors.", "answer": "def Sum_of_Inverse_Divisors(N,Sum): \r\n    ans = float(Sum)*1.0 /float(N);  \r\n    return round(ans,2);", "source": "mbpp", "task_id": "851", "test_cases": "assert Sum_of_Inverse_Divisors(6,12) == 2\nassert Sum_of_Inverse_Divisors(9,13) == 1.44\nassert Sum_of_Inverse_Divisors(1,4) == 4", "difficulty": "code"}
{"input": "Write a python function to remove negative numbers from a list.", "answer": "def remove_negs(num_list): \r\n    for item in num_list: \r\n        if item < 0: \r\n           num_list.remove(item) \r\n    return num_list", "source": "mbpp", "task_id": "852", "test_cases": "assert remove_negs([1,-2,3,-4]) == [1,3]\nassert remove_negs([1,2,3,-4]) == [1,2,3]\nassert remove_negs([4,5,-6,7,-8]) == [4,5,7]", "difficulty": "code"}
{"input": "Write a python function to find sum of odd factors of a number.", "answer": "import math\r\ndef sum_of_odd_Factors(n): \r\n    res = 1\r\n    while n % 2 == 0: \r\n        n = n // 2 \r\n    for i in range(3,int(math.sqrt(n) + 1)): \r\n        count = 0\r\n        curr_sum = 1\r\n        curr_term = 1\r\n        while n % i == 0: \r\n            count+=1 \r\n            n = n // i \r\n            curr_term *= i \r\n            curr_sum += curr_term    \r\n        res *= curr_sum  \r\n    if n >= 2: \r\n        res *= (1 + n) \r\n    return res", "source": "mbpp", "task_id": "853", "test_cases": "assert sum_of_odd_Factors(30) == 24\nassert sum_of_odd_Factors(18) == 13\nassert sum_of_odd_Factors(2) == 1", "difficulty": "code"}
{"input": "Write a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm.", "answer": "import heapq as hq\r\ndef raw_heap(rawheap):\r\n  hq.heapify(rawheap)\r\n  return rawheap", "source": "mbpp", "task_id": "854", "test_cases": "assert raw_heap([25, 44, 68, 21, 39, 23, 89])==[21, 25, 23, 44, 39, 68, 89]\nassert raw_heap([25, 35, 22, 85, 14, 65, 75, 25, 58])== [14, 25, 22, 25, 35, 65, 75, 85, 58]\nassert raw_heap([4, 5, 6, 2])==[2, 4, 6, 5]", "difficulty": "code"}
{"input": "Write a python function to check for even parity of a given number.", "answer": "def check_Even_Parity(x): \r\n    parity = 0\r\n    while (x != 0): \r\n        x = x & (x - 1) \r\n        parity += 1\r\n    if (parity % 2 == 0): \r\n        return True\r\n    else: \r\n        return False", "source": "mbpp", "task_id": "855", "test_cases": "assert check_Even_Parity(10) == True\nassert check_Even_Parity(11) == False\nassert check_Even_Parity(18) == True", "difficulty": "code"}
{"input": "Write a python function to find minimum adjacent swaps required to sort binary array.", "answer": "def find_Min_Swaps(arr,n) : \r\n    noOfZeroes = [0] * n \r\n    count = 0 \r\n    noOfZeroes[n - 1] = 1 - arr[n - 1] \r\n    for i in range(n-2,-1,-1) : \r\n        noOfZeroes[i] = noOfZeroes[i + 1] \r\n        if (arr[i] == 0) : \r\n            noOfZeroes[i] = noOfZeroes[i] + 1\r\n    for i in range(0,n) : \r\n        if (arr[i] == 1) : \r\n            count = count + noOfZeroes[i] \r\n    return count", "source": "mbpp", "task_id": "856", "test_cases": "assert find_Min_Swaps([1,0,1,0],4) == 3\nassert find_Min_Swaps([0,1,0],3) == 1\nassert find_Min_Swaps([0,0,1,1,0],5) == 2", "difficulty": "code"}
{"input": "Write a function to list out the list of given strings individually using map function.", "answer": "def listify_list(list1):\r\n  result = list(map(list,list1)) \r\n  return result", "source": "mbpp", "task_id": "857", "test_cases": "assert listify_list(['Red', 'Blue', 'Black', 'White', 'Pink'])==[['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e'], ['P', 'i', 'n', 'k']]\nassert listify_list(['python'])==[['p', 'y', 't', 'h', 'o', 'n']]\nassert listify_list([' red ', 'green',' black', 'blue ',' orange', 'brown'])==[[' ', 'r', 'e', 'd', ' '], ['g', 'r', 'e', 'e', 'n'], [' ', 'b', 'l', 'a', 'c', 'k'], ['b', 'l', 'u', 'e', ' '], [' ', 'o', 'r', 'a', 'n', 'g', 'e'], ['b', 'r', 'o', 'w', 'n']]", "difficulty": "code"}
{"input": "Write a function to count number of lists in a given list of lists and square the count.", "answer": "def count_list(input_list): \r\n    return (len(input_list))**2", "source": "mbpp", "task_id": "858", "test_cases": "assert count_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==25\nassert count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]] )==16\nassert count_list([[2, 4], [[6,8], [4,5,8]], [10, 12, 14]])==9", "difficulty": "code"}
{"input": "Write a function to generate all sublists of a given list.", "answer": "from itertools import combinations\r\ndef sub_lists(my_list):\r\n\tsubs = []\r\n\tfor i in range(0, len(my_list)+1):\r\n\t  temp = [list(x) for x in combinations(my_list, i)]\r\n\t  if len(temp)>0:\r\n\t    subs.extend(temp)\r\n\treturn subs", "source": "mbpp", "task_id": "859", "test_cases": "assert sub_lists([10, 20, 30, 40])==[[], [10], [20], [30], [40], [10, 20], [10, 30], [10, 40], [20, 30], [20, 40], [30, 40], [10, 20, 30], [10, 20, 40], [10, 30, 40], [20, 30, 40], [10, 20, 30, 40]]\nassert sub_lists(['X', 'Y', 'Z'])==[[], ['X'], ['Y'], ['Z'], ['X', 'Y'], ['X', 'Z'], ['Y', 'Z'], ['X', 'Y', 'Z']]\nassert sub_lists([1,2,3])==[[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]", "difficulty": "code"}
{"input": "Write a function to check whether the given string is ending with only alphanumeric characters or not using regex.", "answer": "import re \r\nregex = '[a-zA-z0-9]$'\r\ndef check_alphanumeric(string): \r\n\tif(re.search(regex, string)): \r\n\t\treturn (\"Accept\") \r\n\telse: \r\n\t\treturn (\"Discard\")", "source": "mbpp", "task_id": "860", "test_cases": "assert check_alphanumeric(\"dawood@\") == 'Discard'\nassert check_alphanumeric(\"skdmsam326\") == 'Accept'\nassert check_alphanumeric(\"cooltricks@\") == 'Discard'", "difficulty": "code"}
{"input": "Write a function to find all anagrams of a string in a given list of strings using lambda function.", "answer": "from collections import Counter \r\ndef anagram_lambda(texts,str):\r\n  result = list(filter(lambda x: (Counter(str) == Counter(x)), texts)) \r\n  return result", "source": "mbpp", "task_id": "861", "test_cases": "assert anagram_lambda([\"bcda\", \"abce\", \"cbda\", \"cbea\", \"adcb\"],\"abcd\")==['bcda', 'cbda', 'adcb']\nassert anagram_lambda([\"recitals\",\" python\"], \"articles\" )==[\"recitals\"]\nassert anagram_lambda([\" keep\",\" abcdef\",\" xyz\"],\" peek\")==[\" keep\"]", "difficulty": "code"}
{"input": "Write a function to find the occurrences of n most common words in a given text.", "answer": "from collections import Counter\r\nimport re\r\ndef n_common_words(text,n):\r\n  words = re.findall('\\w+',text)\r\n  n_common_words= Counter(words).most_common(n)\r\n  return list(n_common_words)", "source": "mbpp", "task_id": "862", "test_cases": "assert n_common_words(\"python is a programming language\",1)==[('python', 1)]\nassert n_common_words(\"python is a programming language\",1)==[('python', 1)]\nassert n_common_words(\"python is a programming language\",5)==[('python', 1),('is', 1), ('a', 1), ('programming', 1), ('language', 1)]", "difficulty": "code"}
{"input": "Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.", "answer": "def find_longest_conseq_subseq(arr, n): \r\n\tans = 0\r\n\tcount = 0\r\n\tarr.sort() \r\n\tv = [] \r\n\tv.append(arr[0]) \r\n\tfor i in range(1, n): \r\n\t\tif (arr[i] != arr[i - 1]): \r\n\t\t\tv.append(arr[i]) \r\n\tfor i in range(len(v)): \r\n\t\tif (i > 0 and v[i] == v[i - 1] + 1): \r\n\t\t\tcount += 1\r\n\t\telse: \r\n\t\t\tcount = 1\r\n\t\tans = max(ans, count) \r\n\treturn ans", "source": "mbpp", "task_id": "863", "test_cases": "assert find_longest_conseq_subseq([1, 2, 2, 3], 4) == 3\nassert find_longest_conseq_subseq([1, 9, 3, 10, 4, 20, 2], 7) == 4\nassert find_longest_conseq_subseq([36, 41, 56, 35, 44, 33, 34, 92, 43, 32, 42], 11) == 5", "difficulty": "code"}
{"input": "Write a function to find palindromes in a given list of strings using lambda function.", "answer": "def palindrome_lambda(texts):\r\n  result = list(filter(lambda x: (x == \"\".join(reversed(x))), texts))\r\n  return result", "source": "mbpp", "task_id": "864", "test_cases": "assert palindrome_lambda([\"php\", \"res\", \"Python\", \"abcd\", \"Java\", \"aaa\"])==['php', 'aaa']\nassert palindrome_lambda([\"abcd\", \"Python\", \"abba\", \"aba\"])==['abba', 'aba']\nassert palindrome_lambda([\"abcd\", \"abbccbba\", \"abba\", \"aba\"])==['abbccbba', 'abba', 'aba']", "difficulty": "code"}
{"input": "Write a function to print n-times a list using map function.", "answer": "def ntimes_list(nums,n):\r\n    result = map(lambda x:n*x, nums) \r\n    return list(result)", "source": "mbpp", "task_id": "865", "test_cases": "assert ntimes_list([1, 2, 3, 4, 5, 6, 7],3)==[3, 6, 9, 12, 15, 18, 21]\nassert ntimes_list([1, 2, 3, 4, 5, 6, 7],4)==[4, 8, 12, 16, 20, 24, 28]\nassert ntimes_list([1, 2, 3, 4, 5, 6, 7],10)==[10, 20, 30, 40, 50, 60, 70]", "difficulty": "code"}
{"input": "Write a function to check whether the given month name contains 31 days or not.", "answer": "def check_monthnumb(monthname2):\r\n  if(monthname2==\"January\" or monthname2==\"March\"or monthname2==\"May\" or monthname2==\"July\" or monthname2==\"Augest\" or monthname2==\"October\" or monthname2==\"December\"):\r\n    return True\r\n  else:\r\n    return False", "source": "mbpp", "task_id": "866", "test_cases": "assert check_monthnumb(\"February\")==False\nassert check_monthnumb(\"January\")==True\nassert check_monthnumb(\"March\")==True", "difficulty": "code"}
{"input": "Write a python function to add a minimum number such that the sum of array becomes even.", "answer": "def min_Num(arr,n):  \r\n    odd = 0\r\n    for i in range(n): \r\n        if (arr[i] % 2): \r\n            odd += 1 \r\n    if (odd % 2): \r\n        return 1\r\n    return 2", "source": "mbpp", "task_id": "867", "test_cases": "assert min_Num([1,2,3,4,5,6,7,8,9],9) == 1\nassert min_Num([1,2,3,4,5,6,7,8],8) == 2\nassert min_Num([1,2,3],3) == 2", "difficulty": "code"}
{"input": "Write a python function to find the length of the last word in a given string.", "answer": "def length_Of_Last_Word(a): \r\n    l = 0\r\n    x = a.strip() \r\n    for i in range(len(x)): \r\n        if x[i] == \" \": \r\n            l = 0\r\n        else: \r\n            l += 1\r\n    return l", "source": "mbpp", "task_id": "868", "test_cases": "assert length_Of_Last_Word(\"python language\") == 8\nassert length_Of_Last_Word(\"PHP\") == 3\nassert length_Of_Last_Word(\"\") == 0", "difficulty": "code"}
{"input": "Write a function to remove sublists from a given list of lists, which are outside a given range.", "answer": "def remove_list_range(list1, leftrange, rigthrange):\r\n   result = [i for i in list1 if (min(i)>=leftrange and max(i)<=rigthrange)]\r\n   return result", "source": "mbpp", "task_id": "869", "test_cases": "assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],13,17)==[[13, 14, 15, 17]]\nassert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],1,3)==[[2], [1, 2, 3]]\nassert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],0,7)==[[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7]]", "difficulty": "code"}
{"input": "Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.", "answer": "def sum_positivenum(nums):\r\n  sum_positivenum = list(filter(lambda nums:nums>0,nums))\r\n  return sum(sum_positivenum)", "source": "mbpp", "task_id": "870", "test_cases": "assert sum_positivenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==48\nassert sum_positivenum([10,15,-14,13,-18,12,-20])==50\nassert sum_positivenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==522", "difficulty": "code"}
{"input": "Write a python function to check whether the given strings are rotations of each other or not.", "answer": "def are_Rotations(string1,string2): \r\n    size1 = len(string1) \r\n    size2 = len(string2) \r\n    temp = '' \r\n    if size1 != size2: \r\n        return False\r\n    temp = string1 + string1 \r\n    if (temp.count(string2)> 0): \r\n        return True\r\n    else: \r\n        return False", "source": "mbpp", "task_id": "871", "test_cases": "assert are_Rotations(\"abc\",\"cba\") == False\nassert are_Rotations(\"abcd\",\"cdba\") == False\nassert are_Rotations(\"abacd\",\"cdaba\") == True", "difficulty": "code"}
{"input": "Write a function to check if a nested list is a subset of another nested list.", "answer": "def check_subset(list1,list2): \r\n    return all(map(list1.__contains__,list2))", "source": "mbpp", "task_id": "872", "test_cases": "assert check_subset([[1, 3], [5, 7], [9, 11], [13, 15, 17]] ,[[1, 3],[13,15,17]])==True\nassert check_subset([[1, 2], [2, 3], [3, 4], [5, 6]],[[3, 4], [5, 6]])==True\nassert check_subset([[[1, 2], [2, 3]], [[3, 4], [5, 7]]],[[[3, 4], [5, 6]]])==False", "difficulty": "code"}
{"input": "Write a function to solve the fibonacci sequence using recursion.", "answer": "def fibonacci(n):\r\n  if n == 1 or n == 2:\r\n    return 1\r\n  else:\r\n    return (fibonacci(n - 1) + (fibonacci(n - 2)))", "source": "mbpp", "task_id": "873", "test_cases": "assert fibonacci(7) == 13\nassert fibonacci(8) == 21\nassert fibonacci(9) == 34", "difficulty": "code"}
{"input": "Write a python function to check if the string is a concatenation of another string.", "answer": "def check_Concat(str1,str2):\r\n    N = len(str1)\r\n    M = len(str2)\r\n    if (N % M != 0):\r\n        return False\r\n    for i in range(N):\r\n        if (str1[i] != str2[i % M]):\r\n            return False         \r\n    return True", "source": "mbpp", "task_id": "874", "test_cases": "assert check_Concat(\"abcabcabc\",\"abc\") == True\nassert check_Concat(\"abcab\",\"abc\") == False\nassert check_Concat(\"aba\",\"ab\") == False", "difficulty": "code"}
{"input": "Write a function to find the minimum difference in the tuple pairs of given tuples.", "answer": "def min_difference(test_list):\r\n  temp = [abs(b - a) for a, b in test_list]\r\n  res = min(temp)\r\n  return (res)", "source": "mbpp", "task_id": "875", "test_cases": "assert min_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 1\nassert min_difference([(4, 6), (12, 8), (11, 4), (2, 13)]) == 2\nassert min_difference([(5, 17), (3, 9), (12, 5), (3, 24)]) == 6", "difficulty": "code"}
{"input": "Write a python function to find lcm of two positive integers.", "answer": "def lcm(x, y):\r\n   if x > y:\r\n       z = x\r\n   else:\r\n       z = y\r\n   while(True):\r\n       if((z % x == 0) and (z % y == 0)):\r\n           lcm = z\r\n           break\r\n       z += 1\r\n   return lcm", "source": "mbpp", "task_id": "876", "test_cases": "assert lcm(4,6) == 12\nassert lcm(15,17) == 255\nassert lcm(2,6) == 6", "difficulty": "code"}
{"input": "Write a python function to sort the given string.", "answer": "def sort_String(str) : \r\n    str = ''.join(sorted(str)) \r\n    return (str)", "source": "mbpp", "task_id": "877", "test_cases": "assert sort_String(\"cba\") == \"abc\"\nassert sort_String(\"data\") == \"aadt\"\nassert sort_String(\"zxy\") == \"xyz\"", "difficulty": "code"}
{"input": "Write a function to check if the given tuple contains only k elements.", "answer": "def check_tuples(test_tuple, K):\r\n  res = all(ele in K for ele in test_tuple)\r\n  return (res)", "source": "mbpp", "task_id": "878", "test_cases": "assert check_tuples((3, 5, 6, 5, 3, 6),[3, 6, 5]) == True\nassert check_tuples((4, 5, 6, 4, 6, 5),[4, 5, 6]) == True\nassert check_tuples((9, 8, 7, 6, 8, 9),[9, 8, 1]) == False", "difficulty": "code"}
{"input": "Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex.", "answer": "import re\r\ndef text_match(text):\r\n  patterns = 'a.*?b$'\r\n  if re.search(patterns,  text):\r\n    return ('Found a match!')\r\n  else:\r\n    return ('Not matched!')", "source": "mbpp", "task_id": "879", "test_cases": "assert text_match(\"aabbbbd\") == 'Not matched!'\nassert text_match(\"aabAbbbc\") == 'Not matched!'\nassert text_match(\"accddbbjjjb\") == 'Found a match!'", "difficulty": "code"}
{"input": "Write a python function to find number of solutions in quadratic equation.", "answer": "def Check_Solution(a,b,c) : \r\n    if ((b*b) - (4*a*c)) > 0 : \r\n        return (\"2 solutions\") \r\n    elif ((b*b) - (4*a*c)) == 0 : \r\n        return (\"1 solution\") \r\n    else : \r\n        return (\"No solutions\")", "source": "mbpp", "task_id": "880", "test_cases": "assert Check_Solution(2,5,2) == \"2 solutions\"\nassert Check_Solution(1,1,1) == \"No solutions\"\nassert Check_Solution(1,2,1) == \"1 solution\"", "difficulty": "code"}
{"input": "Write a function to find the sum of first even and odd number of a given list.", "answer": "def sum_even_odd(list1):\r\n    first_even = next((el for el in list1 if el%2==0),-1)\r\n    first_odd = next((el for el in list1 if el%2!=0),-1)\r\n    return (first_even+first_odd)", "source": "mbpp", "task_id": "881", "test_cases": "assert sum_even_odd([1,3,5,7,4,1,6,8])==5\nassert sum_even_odd([1,2,3,4,5,6,7,8,9,10])==3\nassert sum_even_odd([1,5,7,9,10])==11", "difficulty": "code"}
{"input": "Write a function to caluclate perimeter of a parallelogram.", "answer": "def parallelogram_perimeter(b,h):\r\n  perimeter=2*(b*h)\r\n  return perimeter", "source": "mbpp", "task_id": "882", "test_cases": "assert parallelogram_perimeter(10,20)==400\nassert parallelogram_perimeter(15,20)==600\nassert parallelogram_perimeter(8,9)==144", "difficulty": "code"}
{"input": "Write a function to find numbers divisible by m and n from a list of numbers using lambda function.", "answer": "def div_of_nums(nums,m,n):\r\n result = list(filter(lambda x: (x % m == 0 and x % n == 0), nums)) \r\n return result", "source": "mbpp", "task_id": "883", "test_cases": "assert div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190],2,4)==[ 152,44]\nassert div_of_nums([1, 2, 3, 5, 7, 8, 10],2,5)==[10]\nassert div_of_nums([10,15,14,13,18,12,20],10,5)==[10,20]", "difficulty": "code"}
{"input": "Write a python function to check whether all the bits are within a given range or not.", "answer": "def all_Bits_Set_In_The_Given_Range(n,l,r): \r\n    num = ((1 << r) - 1) ^ ((1 << (l - 1)) - 1) \r\n    new_num = n & num \r\n    if (num == new_num): \r\n        return True\r\n    return False", "source": "mbpp", "task_id": "884", "test_cases": "assert all_Bits_Set_In_The_Given_Range(10,2,1) == True \nassert all_Bits_Set_In_The_Given_Range(5,2,4) == False\nassert all_Bits_Set_In_The_Given_Range(22,2,3) == True ", "difficulty": "code"}
{"input": "Write a python function to check whether the two given strings are isomorphic to each other or not.", "answer": "def is_Isomorphic(str1,str2):          \r\n    dict_str1 = {}\r\n    dict_str2 = {}\r\n    for i, value in enumerate(str1):\r\n        dict_str1[value] = dict_str1.get(value,[]) + [i]        \r\n    for j, value in enumerate(str2):\r\n        dict_str2[value] = dict_str2.get(value,[]) + [j]\r\n    if sorted(dict_str1.values()) == sorted(dict_str2.values()):\r\n        return True\r\n    else:\r\n        return False", "source": "mbpp", "task_id": "885", "test_cases": "assert is_Isomorphic(\"paper\",\"title\") == True\nassert is_Isomorphic(\"ab\",\"ba\") == True\nassert is_Isomorphic(\"ab\",\"aa\") == False", "difficulty": "code"}
{"input": "Write a function to add all the numbers in a list and divide it with the length of the list.", "answer": "def sum_num(numbers):\r\n    total = 0\r\n    for x in numbers:\r\n        total += x\r\n    return total/len(numbers)", "source": "mbpp", "task_id": "886", "test_cases": "assert sum_num((8, 2, 3, 0, 7))==4.0\nassert sum_num((-10,-20,-30))==-20.0\nassert sum_num((19,15,18))==17.333333333333332", "difficulty": "code"}
{"input": "Write a python function to check whether the given number is odd or not using bitwise operator.", "answer": "def is_odd(n) : \r\n    if (n^1 == n-1) :\r\n        return True; \r\n    else :\r\n        return False;", "source": "mbpp", "task_id": "887", "test_cases": "assert is_odd(5) == True\nassert is_odd(6) == False\nassert is_odd(7) == True", "difficulty": "code"}
{"input": "Write a function to substract the elements of the given nested tuples.", "answer": "def substract_elements(test_tup1, test_tup2):\r\n  res = tuple(tuple(a - b for a, b in zip(tup1, tup2))\r\n   for tup1, tup2 in zip(test_tup1, test_tup2))\r\n  return (res)", "source": "mbpp", "task_id": "888", "test_cases": "assert substract_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((-5, -4), (1, -4), (1, 8), (-6, 7))\nassert substract_elements(((13, 4), (14, 6), (13, 10), (12, 11)), ((19, 8), (14, 10), (12, 2), (18, 4))) == ((-6, -4), (0, -4), (1, 8), (-6, 7))\nassert substract_elements(((19, 5), (18, 7), (19, 11), (17, 12)), ((12, 9), (17, 11), (13, 3), (19, 5))) == ((7, -4), (1, -4), (6, 8), (-2, 7))", "difficulty": "code"}
{"input": "Write a function to reverse each list in a given list of lists.", "answer": "def reverse_list_lists(lists):\r\n    for l in lists:\r\n        l.sort(reverse = True)\r\n    return lists", "source": "mbpp", "task_id": "889", "test_cases": "assert reverse_list_lists([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])==[[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9], [16, 15, 14, 13]]\nassert reverse_list_lists([[1,2],[2,3],[3,4]])==[[2,1],[3,2],[4,3]]\nassert reverse_list_lists([[10,20],[30,40]])==[[20,10],[40,30]]", "difficulty": "code"}
{"input": "Write a python function to find the index of an extra element present in one sorted array.", "answer": "def find_Extra(arr1,arr2,n) : \r\n    for i in range(0, n) : \r\n        if (arr1[i] != arr2[i]) : \r\n            return i \r\n    return n", "source": "mbpp", "task_id": "890", "test_cases": "assert find_Extra([1,2,3,4],[1,2,3],3) == 3\nassert find_Extra([2,4,6,8,10],[2,4,6,8],4) == 4\nassert find_Extra([1,3,5,7,9,11],[1,3,5,7,9],5) == 5", "difficulty": "code"}
{"input": "Write a python function to check whether the given two numbers have same number of digits or not.", "answer": "def same_Length(A,B): \r\n    while (A > 0 and B > 0): \r\n        A = A / 10; \r\n        B = B / 10; \r\n    if (A == 0 and B == 0): \r\n        return True; \r\n    return False;", "source": "mbpp", "task_id": "891", "test_cases": "assert same_Length(12,1) == False\nassert same_Length(2,2) == True\nassert same_Length(10,20) == True", "difficulty": "code"}
{"input": "Write a function to remove multiple spaces in a string.", "answer": "import re\r\ndef remove_spaces(text):\r\n return (re.sub(' +',' ',text))", "source": "mbpp", "task_id": "892", "test_cases": "assert remove_spaces('python  program')==('python program')\nassert remove_spaces('python   programming    language')==('python programming language')\nassert remove_spaces('python                     program')==('python program')", "difficulty": "code"}
{"input": "Write a python function to get the last element of each sublist.", "answer": "def Extract(lst): \r\n    return [item[-1] for item in lst]", "source": "mbpp", "task_id": "893", "test_cases": "assert Extract([[1, 2, 3], [4, 5], [6, 7, 8, 9]]) == [3, 5, 9]\nassert Extract([['x', 'y', 'z'], ['m'], ['a', 'b'], ['u', 'v']]) == ['z', 'm', 'b', 'v']\nassert Extract([[1, 2, 3], [4, 5]]) == [3, 5]", "difficulty": "code"}
{"input": "Write a function to convert the given string of float type into tuple.", "answer": "def float_to_tuple(test_str):\r\n  res = tuple(map(float, test_str.split(', ')))\r\n  return (res)", "source": "mbpp", "task_id": "894", "test_cases": "assert float_to_tuple(\"1.2, 1.3, 2.3, 2.4, 6.5\") == (1.2, 1.3, 2.3, 2.4, 6.5)\nassert float_to_tuple(\"2.3, 2.4, 5.6, 5.4, 8.9\") == (2.3, 2.4, 5.6, 5.4, 8.9)\nassert float_to_tuple(\"0.3, 0.5, 7.8, 9.4\") == (0.3, 0.5, 7.8, 9.4)", "difficulty": "code"}
{"input": "Write a function to find the maximum sum of subsequences of given array with no adjacent elements.", "answer": "def max_sum_subseq(A):\r\n    n = len(A)\r\n    if n == 1:\r\n        return A[0]\r\n    look_up = [None] * n\r\n    look_up[0] = A[0]\r\n    look_up[1] = max(A[0], A[1])\r\n    for i in range(2, n):\r\n        look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i])\r\n        look_up[i] = max(look_up[i], A[i])\r\n    return look_up[n - 1]", "source": "mbpp", "task_id": "895", "test_cases": "assert max_sum_subseq([1, 2, 9, 4, 5, 0, 4, 11, 6]) == 26\nassert max_sum_subseq([1, 2, 9, 5, 6, 0, 5, 12, 7]) == 28\nassert max_sum_subseq([1, 3, 10, 5, 6, 0, 6, 14, 21]) == 44", "difficulty": "code"}
{"input": "Write a function to sort a list in increasing order by the last element in each tuple from a given list of non-empty tuples.", "answer": "def last(n):\r\n   return n[-1]\r\ndef sort_list_last(tuples):\r\n  return sorted(tuples, key=last)", "source": "mbpp", "task_id": "896", "test_cases": "assert sort_list_last([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)])==[(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)] \nassert sort_list_last([(9,8), (4, 7), (3,5), (7,9), (1,2)])==[(1,2), (3,5), (4,7), (9,8), (7,9)] \nassert sort_list_last([(20,50), (10,20), (40,40)])==[(10,20),(40,40),(20,50)] ", "difficulty": "code"}
{"input": "Write a python function to check whether the word is present in a given sentence or not.", "answer": "def is_Word_Present(sentence,word): \r\n    s = sentence.split(\" \") \r\n    for i in s:  \r\n        if (i == word): \r\n            return True\r\n    return False", "source": "mbpp", "task_id": "897", "test_cases": "assert is_Word_Present(\"machine learning\",\"machine\") == True\nassert is_Word_Present(\"easy\",\"fun\") == False\nassert is_Word_Present(\"python language\",\"code\") == False", "difficulty": "code"}
{"input": "Write a function to extract specified number of elements from a given list, which follow each other continuously.", "answer": "from itertools import groupby \r\ndef extract_elements(numbers, n):\r\n    result = [i for i, j in groupby(numbers) if len(list(j)) == n] \r\n    return result", "source": "mbpp", "task_id": "898", "test_cases": "assert extract_elements([1, 1, 3, 4, 4, 5, 6, 7],2)==[1, 4]\nassert extract_elements([0, 1, 2, 3, 4, 4, 4, 4, 5, 7],4)==[4]\nassert extract_elements([0,0,0,0,0],5)==[0]", "difficulty": "code"}
{"input": "Write a python function to check whether an array can be sorted or not by picking only the corner elements.", "answer": "def check(arr,n): \r\n    g = 0 \r\n    for i in range(1,n): \r\n        if (arr[i] - arr[i - 1] > 0 and g == 1): \r\n            return False\r\n        if (arr[i] - arr[i] < 0): \r\n            g = 1\r\n    return True", "source": "mbpp", "task_id": "899", "test_cases": "assert check([3,2,1,2,3,4],6) == True\nassert check([2,1,4,5,1],5) == True\nassert check([1,2,2,1,2,3],6) == True", "difficulty": "code"}
{"input": "Write a function where a string will start with a specific number.", "answer": "import re\r\ndef match_num(string):\r\n    text = re.compile(r\"^5\")\r\n    if text.match(string):\r\n        return True\r\n    else:\r\n        return False", "source": "mbpp", "task_id": "900", "test_cases": "assert match_num('5-2345861')==True\nassert match_num('6-2345861')==False\nassert match_num('78910')==False", "difficulty": "code"}
{"input": "Write a function to find the smallest multiple of the first n numbers.", "answer": "def smallest_multiple(n):\r\n    if (n<=2):\r\n      return n\r\n    i = n * 2\r\n    factors = [number  for number in range(n, 1, -1) if number * 2 > n]\r\n    while True:\r\n        for a in factors:\r\n            if i % a != 0:\r\n                i += n\r\n                break\r\n            if (a == factors[-1] and i % a == 0):\r\n                return i", "source": "mbpp", "task_id": "901", "test_cases": "assert smallest_multiple(13)==360360\nassert smallest_multiple(2)==2\nassert smallest_multiple(1)==1", "difficulty": "code"}
{"input": "Write a function to combine two dictionaries by adding values for common keys.", "answer": "from collections import Counter\r\ndef add_dict(d1,d2):\r\n   add_dict = Counter(d1) + Counter(d2)\r\n   return add_dict", "source": "mbpp", "task_id": "902", "test_cases": "assert add_dict({'a': 100, 'b': 200, 'c':300},{'a': 300, 'b': 200, 'd':400})==({'b': 400, 'd': 400, 'a': 400, 'c': 300}) \nassert add_dict({'a': 500, 'b': 700, 'c':900},{'a': 500, 'b': 600, 'd':900})==({'b': 1300, 'd': 900, 'a': 1000, 'c': 900}) \nassert add_dict({'a':900,'b':900,'d':900},{'a':900,'b':900,'d':900})==({'b': 1800, 'd': 1800, 'a': 1800})", "difficulty": "code"}
{"input": "Write a python function to count the total unset bits from 1 to n.", "answer": "def count_Unset_Bits(n) :  \r\n    cnt = 0;  \r\n    for i in range(1,n + 1) : \r\n        temp = i;  \r\n        while (temp) :  \r\n            if (temp % 2 == 0) : \r\n                cnt += 1;  \r\n            temp = temp // 2;  \r\n    return cnt;", "source": "mbpp", "task_id": "903", "test_cases": "assert count_Unset_Bits(2) == 1\nassert count_Unset_Bits(5) == 4\nassert count_Unset_Bits(14) == 17", "difficulty": "code"}
{"input": "Write a function to return true if the given number is even else return false.", "answer": "def even_num(x):\r\n  if x%2==0:\r\n     return True\r\n  else:\r\n    return False", "source": "mbpp", "task_id": "904", "test_cases": "assert even_num(13.5)==False\nassert even_num(0)==True\nassert even_num(-9)==False", "difficulty": "code"}
{"input": "Write a python function to find the sum of squares of binomial co-efficients.", "answer": "def factorial(start,end): \r\n    res = 1 \r\n    for i in range(start,end + 1): \r\n        res *= i      \r\n    return res \r\ndef sum_of_square(n): \r\n   return int(factorial(n + 1, 2 * n)  /factorial(1, n))", "source": "mbpp", "task_id": "905", "test_cases": "assert sum_of_square(4) == 70\nassert sum_of_square(5) == 252\nassert sum_of_square(2) == 6", "difficulty": "code"}
{"input": "Write a function to extract year, month and date from a url by using regex.", "answer": "import re\r\ndef extract_date(url):\r\n        return re.findall(r'/(\\d{4})/(\\d{1,2})/(\\d{1,2})/', url)", "source": "mbpp", "task_id": "906", "test_cases": "assert extract_date(\"https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-norman-tells-author/\") == [('2016', '09', '02')]\nassert extract_date(\"https://www.indiatoday.in/movies/celebrities/story/wp/2020/11/03/odeof-sushant-singh-rajput-s-death-his-brother-in-law-shares-advice-for-fans-1749646/\") == [('2020', '11', '03')]\nassert extract_date(\"https://economictimes.indiatimes.com/news/economy/2020/12/29/finance/pension-assets-under-pfrda-touch-rs-5-32-lakh-crore/articleshow/79736619.cms\") == [('2020', '12', '29')]", "difficulty": "code"}
{"input": "Write a function to print the first n lucky numbers.", "answer": "def lucky_num(n):\r\n List=range(-1,n*n+9,2)\r\n i=2\r\n while List[i:]:List=sorted(set(List)-set(List[List[i]::List[i]]));i+=1\r\n return List[1:n+1]", "source": "mbpp", "task_id": "907", "test_cases": "assert lucky_num(10)==[1, 3, 7, 9, 13, 15, 21, 25, 31, 33] \nassert lucky_num(5)==[1, 3, 7, 9, 13]\nassert lucky_num(8)==[1, 3, 7, 9, 13, 15, 21, 25]", "difficulty": "code"}
{"input": "Write a function to find the fixed point in the given array.", "answer": "def find_fixed_point(arr, n): \r\n\tfor i in range(n): \r\n\t\tif arr[i] is i: \r\n\t\t\treturn i \r\n\treturn -1", "source": "mbpp", "task_id": "908", "test_cases": "assert find_fixed_point([-10, -1, 0, 3, 10, 11, 30, 50, 100],9) == 3\nassert find_fixed_point([1, 2, 3, 4, 5, 6, 7, 8],8) == -1\nassert find_fixed_point([0, 2, 5, 8, 17],5) == 0", "difficulty": "code"}
{"input": "Write a function to find the previous palindrome of a specified number.", "answer": "def previous_palindrome(num):\r\n    for x in range(num-1,0,-1):\r\n        if str(x) == str(x)[::-1]:\r\n            return x", "source": "mbpp", "task_id": "909", "test_cases": "assert previous_palindrome(99)==88\nassert previous_palindrome(1221)==1111\nassert previous_palindrome(120)==111", "difficulty": "code"}
{"input": "Write a function to validate a gregorian date.", "answer": "import datetime\r\ndef check_date(m, d, y):\r\n    try:\r\n        m, d, y = map(int, (m, d, y))\r\n        datetime.date(y, m, d)\r\n        return True\r\n    except ValueError:\r\n        return False", "source": "mbpp", "task_id": "910", "test_cases": "assert check_date(11,11,2002)==True\nassert check_date(13,11,2002)==False\nassert check_date('11','11','2002')==True", "difficulty": "code"}
{"input": "Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm.", "answer": "def maximum_product(nums):\r\n    import heapq\r\n    a, b = heapq.nlargest(3, nums), heapq.nsmallest(2, nums)\r\n    return max(a[0] * a[1] * a[2], a[0] * b[0] * b[1])", "source": "mbpp", "task_id": "911", "test_cases": "assert maximum_product( [12, 74, 9, 50, 61, 41])==225700\nassert maximum_product([25, 35, 22, 85, 14, 65, 75, 25, 58])==414375\nassert maximum_product([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1])==2520", "difficulty": "code"}
{"input": "Write a function to find ln, m lobb number.", "answer": "def binomial_coeff(n, k): \r\n\tC = [[0 for j in range(k + 1)] \r\n\t\t\tfor i in range(n + 1)] \r\n\tfor i in range(0, n + 1): \r\n\t\tfor j in range(0, min(i, k) + 1): \r\n\t\t\tif (j == 0 or j == i): \r\n\t\t\t\tC[i][j] = 1\r\n\t\t\telse: \r\n\t\t\t\tC[i][j] = (C[i - 1][j - 1] \r\n\t\t\t\t\t\t\t+ C[i - 1][j]) \r\n\treturn C[n][k] \r\ndef lobb_num(n, m): \r\n\treturn (((2 * m + 1) *\r\n\t\tbinomial_coeff(2 * n, m + n)) \r\n\t\t\t\t\t/ (m + n + 1))", "source": "mbpp", "task_id": "912", "test_cases": "assert int(lobb_num(5, 3)) == 35\nassert int(lobb_num(3, 2)) == 5\nassert int(lobb_num(4, 2)) == 20", "difficulty": "code"}
{"input": "Write a function to check for a number at the end of a string.", "answer": "import re\r\ndef end_num(string):\r\n    text = re.compile(r\".*[0-9]$\")\r\n    if text.match(string):\r\n        return True\r\n    else:\r\n        return False", "source": "mbpp", "task_id": "913", "test_cases": "assert end_num('abcdef')==False\nassert end_num('abcdef7')==True\nassert end_num('abc')==False", "difficulty": "code"}
{"input": "Write a python function to check whether the given string is made up of two alternating characters or not.", "answer": "def is_Two_Alter(s):  \r\n    for i in range (len( s) - 2) : \r\n        if (s[i] != s[i + 2]) : \r\n            return False\r\n    if (s[0] == s[1]): \r\n        return False\r\n    return True", "source": "mbpp", "task_id": "914", "test_cases": "assert is_Two_Alter(\"abab\") == True\nassert is_Two_Alter(\"aaaa\") == False\nassert is_Two_Alter(\"xyz\") == False", "difficulty": "code"}
{"input": "Write a function to rearrange positive and negative numbers in a given array using lambda function.", "answer": "def rearrange_numbs(array_nums):\r\n  result = sorted(array_nums, key = lambda i: 0 if i == 0 else -1 / i)\r\n  return result", "source": "mbpp", "task_id": "915", "test_cases": "assert rearrange_numbs([-1, 2, -3, 5, 7, 8, 9, -10])==[2, 5, 7, 8, 9, -10, -3, -1]\nassert rearrange_numbs([10,15,14,13,-18,12,-20])==[10, 12, 13, 14, 15, -20, -18]\nassert rearrange_numbs([-20,20,-10,10,-30,30])==[10, 20, 30, -30, -20, -10]", "difficulty": "code"}
{"input": "Write a function to find if there is a triplet in the array whose sum is equal to a given value.", "answer": "def find_triplet_array(A, arr_size, sum): \r\n\tfor i in range( 0, arr_size-2): \r\n\t\tfor j in range(i + 1, arr_size-1): \r\n\t\t\tfor k in range(j + 1, arr_size): \r\n\t\t\t\tif A[i] + A[j] + A[k] == sum: \r\n\t\t\t\t\treturn  A[i],A[j],A[k] \r\n\t\t\t\t\treturn True\r\n\treturn False", "source": "mbpp", "task_id": "916", "test_cases": "assert find_triplet_array([1, 4, 45, 6, 10, 8], 6, 22) == (4, 10, 8)\nassert find_triplet_array([12, 3, 5, 2, 6, 9], 6, 24) == (12, 3, 9)\nassert find_triplet_array([1, 2, 3, 4, 5], 5, 9) == (1, 3, 5)", "difficulty": "code"}
{"input": "Write a function to find the sequences of one upper case letter followed by lower case letters.", "answer": "import re\r\ndef text_uppercase_lowercase(text):\r\n        patterns = '[A-Z]+[a-z]+$'\r\n        if re.search(patterns, text):\r\n                return 'Found a match!'\r\n        else:\r\n                return ('Not matched!')", "source": "mbpp", "task_id": "917", "test_cases": "assert text_uppercase_lowercase(\"AaBbGg\")==('Found a match!')\nassert text_uppercase_lowercase(\"aA\")==('Not matched!')\nassert text_uppercase_lowercase(\"PYTHON\")==('Not matched!')", "difficulty": "code"}
{"input": "Write a function to count coin change.", "answer": "def coin_change(S, m, n): \r\n    table = [[0 for x in range(m)] for x in range(n+1)] \r\n    for i in range(m): \r\n        table[0][i] = 1\r\n    for i in range(1, n+1): \r\n        for j in range(m): \r\n            x = table[i - S[j]][j] if i-S[j] >= 0 else 0\r\n            y = table[i][j-1] if j >= 1 else 0 \r\n            table[i][j] = x + y   \r\n    return table[n][m-1]", "source": "mbpp", "task_id": "918", "test_cases": "assert coin_change([1, 2, 3],3,4)==4\nassert coin_change([4,5,6,7,8,9],6,9)==2\nassert coin_change([4,5,6,7,8,9],6,4)==1", "difficulty": "code"}
{"input": "Write a python function to multiply all items in the list.", "answer": "def multiply_list(items):\r\n    tot = 1\r\n    for x in items:\r\n        tot *= x\r\n    return tot", "source": "mbpp", "task_id": "919", "test_cases": "assert multiply_list([1,-2,3]) == -6\nassert multiply_list([1,2,3,4]) == 24\nassert multiply_list([3,1,2,3]) == 18", "difficulty": "code"}
{"input": "Write a function to remove all tuples with all none values in the given tuple list.", "answer": "def remove_tuple(test_list):\r\n  res = [sub for sub in test_list if not all(ele == None for ele in sub)]\r\n  return (str(res))", "source": "mbpp", "task_id": "920", "test_cases": "assert remove_tuple([(None, 2), (None, None), (3, 4), (12, 3), (None, )] ) == '[(None, 2), (3, 4), (12, 3)]'\nassert remove_tuple([(None, None), (None, None), (3, 6), (17, 3), (None,1 )] ) == '[(3, 6), (17, 3), (None, 1)]'\nassert remove_tuple([(1, 2), (2, None), (3, None), (24, 3), (None, None )] ) == '[(1, 2), (2, None), (3, None), (24, 3)]'", "difficulty": "code"}
{"input": "Write a function to perform chunking of tuples each of size n.", "answer": "def chunk_tuples(test_tup, N):\r\n  res = [test_tup[i : i + N] for i in range(0, len(test_tup), N)]\r\n  return (res)", "source": "mbpp", "task_id": "921", "test_cases": "assert chunk_tuples((10, 4, 5, 6, 7, 6, 8, 3, 4), 3) == [(10, 4, 5), (6, 7, 6), (8, 3, 4)]\nassert chunk_tuples((1, 2, 3, 4, 5, 6, 7, 8, 9), 2) == [(1, 2), (3, 4), (5, 6), (7, 8), (9,)]\nassert chunk_tuples((11, 14, 16, 17, 19, 21, 22, 25), 4) == [(11, 14, 16, 17), (19, 21, 22, 25)]", "difficulty": "code"}
{"input": "Write a function to find a pair with the highest product from a given array of integers.", "answer": "def max_product(arr): \r\n    arr_len = len(arr) \r\n    if (arr_len < 2): \r\n        return None     \r\n    x = arr[0]; y = arr[1]    \r\n    for i in range(0, arr_len): \r\n        for j in range(i + 1, arr_len): \r\n            if (arr[i] * arr[j] > x * y): \r\n                x = arr[i]; y = arr[j] \r\n    return x,y", "source": "mbpp", "task_id": "922", "test_cases": "assert 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, 3, 5, 6, 8, 9])==(8,9)", "difficulty": "code"}
{"input": "Write a function to find the length of the shortest string that has both str1 and str2 as subsequences.", "answer": "def super_seq(X, Y, m, n):\r\n\tif (not m):\r\n\t\treturn n\r\n\tif (not n):\r\n\t\treturn m\r\n\tif (X[m - 1] == Y[n - 1]):\r\n\t\treturn 1 + super_seq(X, Y, m - 1, n - 1)\r\n\treturn 1 + min(super_seq(X, Y, m - 1, n),\tsuper_seq(X, Y, m, n - 1))", "source": "mbpp", "task_id": "923", "test_cases": "assert super_seq(\"AGGTAB\", \"GXTXAYB\", 6, 7) == 9\nassert super_seq(\"feek\", \"eke\", 4, 3) == 5\nassert super_seq(\"PARRT\", \"RTA\", 5, 3) == 6", "difficulty": "code"}
{"input": "Write a function to find maximum of two numbers.", "answer": "def max_of_two( x, y ):\r\n    if x > y:\r\n        return x\r\n    return y", "source": "mbpp", "task_id": "924", "test_cases": "assert max_of_two(10,20)==20\nassert max_of_two(19,15)==19\nassert max_of_two(-10,-20)==-10", "difficulty": "code"}
{"input": "Write a python function to calculate the product of all the numbers of a given tuple.", "answer": "def mutiple_tuple(nums):\r\n    temp = list(nums)\r\n    product = 1 \r\n    for x in temp:\r\n        product *= x\r\n    return product", "source": "mbpp", "task_id": "925", "test_cases": "assert mutiple_tuple((4, 3, 2, 2, -1, 18)) == -864\nassert mutiple_tuple((1,2,3)) == 6\nassert mutiple_tuple((-2,-4,-6)) == -48", "difficulty": "code"}
{"input": "Write a function to find n-th rencontres number.", "answer": "def binomial_coeffi(n, k): \r\n\tif (k == 0 or k == n): \r\n\t\treturn 1\r\n\treturn (binomial_coeffi(n - 1, k - 1) \r\n\t\t+ binomial_coeffi(n - 1, k)) \r\ndef rencontres_number(n, m): \r\n\tif (n == 0 and m == 0): \r\n\t\treturn 1\r\n\tif (n == 1 and m == 0): \r\n\t\treturn 0\r\n\tif (m == 0): \r\n\t\treturn ((n - 1) * (rencontres_number(n - 1, 0)+ rencontres_number(n - 2, 0))) \r\n\treturn (binomial_coeffi(n, m) * rencontres_number(n - m, 0))", "source": "mbpp", "task_id": "926", "test_cases": "assert rencontres_number(7, 2) == 924\nassert rencontres_number(3, 0) == 2\nassert rencontres_number(3, 1) == 3", "difficulty": "code"}
{"input": "Write a function to calculate the height of the given binary tree.", "answer": "class Node: \r\n\tdef __init__(self, data): \r\n\t\tself.data = data \r\n\t\tself.left = None\r\n\t\tself.right = None\r\ndef max_height(node): \r\n\tif node is None: \r\n\t\treturn 0 ; \r\n\telse : \r\n\t\tleft_height = max_height(node.left) \r\n\t\tright_height = max_height(node.right) \r\n\t\tif (left_height > right_height): \r\n\t\t\treturn left_height+1\r\n\t\telse: \r\n\t\t\treturn right_height+1", "source": "mbpp", "task_id": "927", "test_cases": "assert (max_height(root)) == 3\nassert (max_height(root1)) == 5 \nassert (max_height(root2)) == 4", "difficulty": "code"}
{"input": "Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.", "answer": "import re\r\ndef change_date_format(dt):\r\n        return re.sub(r'(\\d{4})-(\\d{1,2})-(\\d{1,2})', '\\\\3-\\\\2-\\\\1', dt)\r\n        return change_date_format(dt)", "source": "mbpp", "task_id": "928", "test_cases": "assert change_date_format('2026-01-02')=='02-01-2026'\nassert change_date_format('2021-01-04')=='04-01-2021'\nassert change_date_format('2030-06-06')=='06-06-2030'", "difficulty": "code"}
{"input": "Write a function to count repeated items of a tuple.", "answer": "def count_tuplex(tuplex,value):  \r\n  count = tuplex.count(value)\r\n  return count", "source": "mbpp", "task_id": "929", "test_cases": "assert count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7),4)==3\nassert count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7),2)==2\nassert count_tuplex((2, 4, 7, 7, 7, 3, 4, 4, 7),7)==4", "difficulty": "code"}
{"input": "Write a function that matches a string that has an a followed by zero or more b's by using regex.", "answer": "import re\r\ndef text_match(text):\r\n        patterns = 'ab*?'\r\n        if re.search(patterns,  text):\r\n                return ('Found a match!')\r\n        else:\r\n                return ('Not matched!')", "source": "mbpp", "task_id": "930", "test_cases": "assert text_match(\"msb\") == 'Not matched!'\nassert text_match(\"a0c\") == 'Found a match!'\nassert text_match(\"abbc\") == 'Found a match!'", "difficulty": "code"}
{"input": "Write a function to calculate the sum of series 1³+2³+3³+….+n³.", "answer": "import math \r\ndef sum_series(number):\r\n total = 0\r\n total = math.pow((number * (number + 1)) /2, 2)\r\n return total", "source": "mbpp", "task_id": "931", "test_cases": "assert sum_series(7)==784\nassert sum_series(5)==225\nassert sum_series(15)==14400", "difficulty": "code"}
{"input": "Write a function to remove duplicate words from a given list of strings.", "answer": "def remove_duplic_list(l):\r\n    temp = []\r\n    for x in l:\r\n        if x not in temp:\r\n            temp.append(x)\r\n    return temp", "source": "mbpp", "task_id": "932", "test_cases": "assert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\"])==['Python', 'Exercises', 'Practice', 'Solution']\nassert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\",\"Java\"])==['Python', 'Exercises', 'Practice', 'Solution', 'Java']\nassert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\",\"C++\",\"C\",\"C++\"])==['Python', 'Exercises', 'Practice', 'Solution','C++','C']", "difficulty": "code"}
{"input": "Write a function to convert camel case string to snake case string by using regex.", "answer": "import re\r\ndef camel_to_snake(text):\r\n  str1 = re.sub('(.)([A-Z][a-z]+)', r'\\1_\\2', text)\r\n  return re.sub('([a-z0-9])([A-Z])', r'\\1_\\2', str1).lower()", "source": "mbpp", "task_id": "933", "test_cases": "assert camel_to_snake('GoogleAssistant') == 'google_assistant'\nassert camel_to_snake('ChromeCast') == 'chrome_cast'\nassert camel_to_snake('QuadCore') == 'quad_core'", "difficulty": "code"}
{"input": "Write a function to find the nth delannoy number.", "answer": "def dealnnoy_num(n, m): \r\n\tif (m == 0 or n == 0) : \r\n\t\treturn 1\r\n\treturn dealnnoy_num(m - 1, n) + dealnnoy_num(m - 1, n - 1) + dealnnoy_num(m, n - 1)", "source": "mbpp", "task_id": "934", "test_cases": "assert dealnnoy_num(3, 4) == 129\nassert dealnnoy_num(3, 3) == 63\nassert dealnnoy_num(4, 5) == 681", "difficulty": "code"}
{"input": "Write a function to calculate the sum of series 1²+2²+3²+….+n².", "answer": "def series_sum(number):\r\n total = 0\r\n total = (number * (number + 1) * (2 * number + 1)) / 6\r\n return total", "source": "mbpp", "task_id": "935", "test_cases": "assert series_sum(6)==91\nassert series_sum(7)==140\nassert series_sum(12)==650", "difficulty": "code"}
{"input": "Write a function to re-arrange the given tuples based on the given ordered list.", "answer": "def re_arrange_tuples(test_list, ord_list):\r\n  temp = dict(test_list)\r\n  res = [(key, temp[key]) for key in ord_list]\r\n  return (res)", "source": "mbpp", "task_id": "936", "test_cases": "assert re_arrange_tuples([(4, 3), (1, 9), (2, 10), (3, 2)],  [1, 4, 2, 3]) == [(1, 9), (4, 3), (2, 10), (3, 2)]\nassert re_arrange_tuples([(5, 4), (2, 10), (3, 11), (4, 3)],  [3, 4, 2, 3]) == [(3, 11), (4, 3), (2, 10), (3, 11)]\nassert re_arrange_tuples([(6, 3), (3, 8), (5, 7), (2, 4)],  [2, 5, 3, 6]) == [(2, 4), (5, 7), (3, 8), (6, 3)]", "difficulty": "code"}
{"input": "Write a function to count the most common character in a given string.", "answer": "from collections import Counter \r\ndef max_char(str1):\r\n    temp = Counter(str1) \r\n    max_char = max(temp, key = temp.get)\r\n    return max_char", "source": "mbpp", "task_id": "937", "test_cases": "assert max_char(\"hello world\")==('l')\nassert max_char(\"hello \")==('l')\nassert max_char(\"python pr\")==('p')", "difficulty": "code"}
{"input": "Write a function to find three closest elements from three sorted arrays.", "answer": "import sys \r\n\r\ndef find_closet(A, B, C, p, q, r): \r\n\tdiff = sys.maxsize \r\n\tres_i = 0\r\n\tres_j = 0\r\n\tres_k = 0\r\n\ti = 0\r\n\tj = 0\r\n\tk = 0\r\n\twhile(i < p and j < q and k < r): \r\n\t\tminimum = min(A[i], min(B[j], C[k])) \r\n\t\tmaximum = max(A[i], max(B[j], C[k])); \r\n\t\tif maximum-minimum < diff: \r\n\t\t\tres_i = i \r\n\t\t\tres_j = j \r\n\t\t\tres_k = k \r\n\t\t\tdiff = maximum - minimum; \r\n\t\tif diff == 0: \r\n\t\t\tbreak\r\n\t\tif A[i] == minimum: \r\n\t\t\ti = i+1\r\n\t\telif B[j] == minimum: \r\n\t\t\tj = j+1\r\n\t\telse: \r\n\t\t\tk = k+1\r\n\treturn A[res_i],B[res_j],C[res_k]", "source": "mbpp", "task_id": "938", "test_cases": "assert find_closet([1, 4, 10],[2, 15, 20],[10, 12],3,3,2) == (10, 15, 10)\nassert find_closet([20, 24, 100],[2, 19, 22, 79, 800],[10, 12, 23, 24, 119],3,5,5) == (24, 22, 23)\nassert find_closet([2, 5, 11],[3, 16, 21],[11, 13],3,3,2) == (11, 16, 11)", "difficulty": "code"}
{"input": "Write a function to sort a list of dictionaries using lambda function.", "answer": "def sorted_models(models):\r\n sorted_models = sorted(models, key = lambda x: x['color'])\r\n return sorted_models", "source": "mbpp", "task_id": "939", "test_cases": "assert sorted_models([{'make':'Nokia', 'model':216, 'color':'Black'}, {'make':'Mi Max', 'model':2, 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color':'Blue'}])==[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'Mi Max', 'model': 2, 'color': 'Gold'}]\nassert sorted_models([{'make':'Vivo', 'model':20,'color':'Blue'},{'make': 'oppo','model':17,'color':'Gold'},{'make':'Apple','model':11,'color':'red'}])==([{'make':'Vivo', 'model':20,'color':'Blue'},{'make': 'oppo','model':17,'color':'Gold'},{'make':'Apple','model':11,'color':'red'}])\nassert sorted_models([{'make':'micromax','model':40,'color':'grey'},{'make':'poco','model':60,'color':'blue'}])==([{'make':'poco','model':60,'color':'blue'},{'make':'micromax','model':40,'color':'grey'}])", "difficulty": "code"}
{"input": "Write a function to sort the given array by using heap sort.", "answer": "def heap_sort(arr):\r\n    heapify(arr)  \r\n    end = len(arr) - 1\r\n    while end > 0:\r\n        arr[end], arr[0] = arr[0], arr[end]\r\n        shift_down(arr, 0, end - 1)\r\n        end -= 1\r\n    return arr\r\n\r\ndef heapify(arr):\r\n    start = len(arr) // 2\r\n    while start >= 0:\r\n        shift_down(arr, start, len(arr) - 1)\r\n        start -= 1\r\ndef shift_down(arr, start, end):\r\n    root = start\r\n    while root * 2 + 1 <= end:\r\n        child = root * 2 + 1\r\n        if child + 1 <= end and arr[child] < arr[child + 1]:\r\n            child += 1\r\n        if child <= end and arr[root] < arr[child]:\r\n            arr[root], arr[child] = arr[child], arr[root]\r\n            root = child\r\n        else:\r\n            return", "source": "mbpp", "task_id": "940", "test_cases": "assert heap_sort([12, 2, 4, 5, 2, 3]) == [2, 2, 3, 4, 5, 12]\nassert heap_sort([32, 14, 5, 6, 7, 19]) == [5, 6, 7, 14, 19, 32]\nassert heap_sort([21, 15, 29, 78, 65]) == [15, 21, 29, 65, 78]", "difficulty": "code"}
{"input": "Write a function to count the elements in a list until an element is a tuple.", "answer": "def count_elim(num):\r\n  count_elim = 0\r\n  for n in num:\r\n    if isinstance(n, tuple):\r\n        break\r\n    count_elim += 1\r\n  return count_elim", "source": "mbpp", "task_id": "941", "test_cases": "assert count_elim([10,20,30,(10,20),40])==3\nassert count_elim([10,(20,30),(10,20),40])==1\nassert count_elim([(10,(20,30,(10,20),40))])==0", "difficulty": "code"}
{"input": "Write a function to check if any list element is present in the given list.", "answer": "def check_element(test_tup, check_list):\r\n  res = False\r\n  for ele in check_list:\r\n    if ele in test_tup:\r\n      res = True\r\n      break\r\n  return (res)", "source": "mbpp", "task_id": "942", "test_cases": "assert check_element((4, 5, 7, 9, 3),  [6, 7, 10, 11]) == True\nassert check_element((1, 2, 3, 4),  [4, 6, 7, 8, 9]) == True\nassert check_element((3, 2, 1, 4, 5),  [9, 8, 7, 6]) == False", "difficulty": "code"}
{"input": "Write a function to combine two given sorted lists using heapq module.", "answer": "from heapq import merge\r\ndef combine_lists(num1,num2):\r\n  combine_lists=list(merge(num1, num2))\r\n  return combine_lists", "source": "mbpp", "task_id": "943", "test_cases": "assert combine_lists([1, 3, 5, 7, 9, 11],[0, 2, 4, 6, 8, 10])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\nassert combine_lists([1, 3, 5, 6, 8, 9], [2, 5, 7, 11])==[1,2,3,5,5,6,7,8,9,11]\nassert combine_lists([1,3,7],[2,4,6])==[1,2,3,4,6,7]", "difficulty": "code"}
{"input": "Write a function to separate and print the numbers and their position of a given string.", "answer": "import re\r\ndef num_position(text):\r\n for m in re.finditer(\"\\d+\", text):\r\n    return m.start()", "source": "mbpp", "task_id": "944", "test_cases": "assert num_position(\"there are 70 flats in this apartment\")==10\nassert num_position(\"every adult have 32 teeth\")==17\nassert num_position(\"isha has 79 chocolates in her bag\")==9", "difficulty": "code"}
{"input": "Write a function to convert the given tuples into set.", "answer": "def tuple_to_set(t):\r\n  s = set(t)\r\n  return (s)", "source": "mbpp", "task_id": "945", "test_cases": "assert tuple_to_set(('x', 'y', 'z') ) == {'y', 'x', 'z'}\nassert tuple_to_set(('a', 'b', 'c') ) == {'c', 'a', 'b'}\nassert tuple_to_set(('z', 'd', 'e') ) == {'d', 'e', 'z'}", "difficulty": "code"}
{"input": "Write a function to find the most common elements and their counts of a specified text.", "answer": "from collections import Counter \r\ndef most_common_elem(s,a):\r\n  most_common_elem=Counter(s).most_common(a)\r\n  return most_common_elem", "source": "mbpp", "task_id": "946", "test_cases": "assert most_common_elem('lkseropewdssafsdfafkpwe',3)==[('s', 4), ('e', 3), ('f', 3)] \nassert most_common_elem('lkseropewdssafsdfafkpwe',2)==[('s', 4), ('e', 3)]\nassert most_common_elem('lkseropewdssafsdfafkpwe',7)==[('s', 4), ('e', 3), ('f', 3), ('k', 2), ('p', 2), ('w', 2), ('d', 2)]", "difficulty": "code"}
{"input": "Write a python function to find the length of the shortest word.", "answer": "def len_log(list1):\r\n    min=len(list1[0])\r\n    for i in list1:\r\n        if len(i)<min:\r\n            min=len(i)\r\n    return min", "source": "mbpp", "task_id": "947", "test_cases": "assert len_log([\"win\",\"lose\",\"great\"]) == 3\nassert len_log([\"a\",\"ab\",\"abc\"]) == 1\nassert len_log([\"12\",\"12\",\"1234\"]) == 2", "difficulty": "code"}
{"input": "Write a function to get an item of a tuple.", "answer": "def get_item(tup1,index):\r\n  item = tup1[index]\r\n  return item", "source": "mbpp", "task_id": "948", "test_cases": "assert get_item((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),3)==('e')\nassert get_item((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),-4)==('u')\nassert get_item((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),-3)==('r')", "difficulty": "code"}
{"input": "Write a function to sort the given tuple list basis the total digits in tuple.", "answer": "def count_digs(tup):\r\n  return sum([len(str(ele)) for ele in tup ]) \r\ndef sort_list(test_list):\r\n  test_list.sort(key = count_digs)\r\n  return (str(test_list))", "source": "mbpp", "task_id": "949", "test_cases": "assert sort_list([(3, 4, 6, 723), (1, 2), (12345,), (134, 234, 34)] ) == '[(1, 2), (12345,), (3, 4, 6, 723), (134, 234, 34)]'\nassert sort_list([(3, 4, 8), (1, 2), (1234335,), (1345, 234, 334)] ) == '[(1, 2), (3, 4, 8), (1234335,), (1345, 234, 334)]'\nassert sort_list([(34, 4, 61, 723), (1, 2), (145,), (134, 23)] ) == '[(1, 2), (145,), (134, 23), (34, 4, 61, 723)]'", "difficulty": "code"}
{"input": "Write a function to display sign of the chinese zodiac for given year.", "answer": "def chinese_zodiac(year):\r\n if (year - 2000) % 12 == 0:\r\n     sign = 'Dragon'\r\n elif (year - 2000) % 12 == 1:\r\n     sign = 'Snake'\r\n elif (year - 2000) % 12 == 2:\r\n     sign = 'Horse'\r\n elif (year - 2000) % 12 == 3:\r\n     sign = 'sheep'\r\n elif (year - 2000) % 12 == 4:\r\n     sign = 'Monkey'\r\n elif (year - 2000) % 12 == 5:\r\n     sign = 'Rooster'\r\n elif (year - 2000) % 12 == 6:\r\n     sign = 'Dog'\r\n elif (year - 2000) % 12 == 7:\r\n     sign = 'Pig'\r\n elif (year - 2000) % 12 == 8:\r\n     sign = 'Rat'\r\n elif (year - 2000) % 12 == 9:\r\n     sign = 'Ox'\r\n elif (year - 2000) % 12 == 10:\r\n     sign = 'Tiger'\r\n else:\r\n     sign = 'Hare'\r\n return sign", "source": "mbpp", "task_id": "950", "test_cases": "assert chinese_zodiac(1997)==('Ox')\nassert chinese_zodiac(1998)==('Tiger')\nassert chinese_zodiac(1994)==('Dog')", "difficulty": "code"}
{"input": "Write a function to find the maximum of similar indices in two lists of tuples.", "answer": "def max_similar_indices(test_list1, test_list2):\r\n  res = [(max(x[0], y[0]), max(x[1], y[1]))\r\n   for x, y in zip(test_list1, test_list2)]\r\n  return (res)", "source": "mbpp", "task_id": "951", "test_cases": "assert max_similar_indices([(2, 4), (6, 7), (5, 1)],[(5, 4), (8, 10), (8, 14)]) == [(5, 4), (8, 10), (8, 14)]\nassert max_similar_indices([(3, 5), (7, 8), (6, 2)],[(6, 5), (9, 11), (9, 15)]) == [(6, 5), (9, 11), (9, 15)]\nassert max_similar_indices([(4, 6), (8, 9), (7, 3)],[(7, 6), (10, 12), (10, 16)]) == [(7, 6), (10, 12), (10, 16)]", "difficulty": "code"}
{"input": "Write a function to compute the value of ncr mod p.", "answer": "def nCr_mod_p(n, r, p): \r\n\tif (r > n- r): \r\n\t\tr = n - r \r\n\tC = [0 for i in range(r + 1)] \r\n\tC[0] = 1 \r\n\tfor i in range(1, n + 1): \r\n\t\tfor j in range(min(i, r), 0, -1): \r\n\t\t\tC[j] = (C[j] + C[j-1]) % p \r\n\treturn C[r]", "source": "mbpp", "task_id": "952", "test_cases": "assert nCr_mod_p(10, 2, 13) == 6\nassert nCr_mod_p(11, 3, 14) == 11\nassert nCr_mod_p(18, 14, 19) == 1", "difficulty": "code"}
{"input": "Write a python function to find the minimun number of subsets with distinct elements.", "answer": "def subset(ar, n): \r\n    res = 0\r\n    ar.sort() \r\n    for i in range(0, n) : \r\n        count = 1\r\n        for i in range(n - 1): \r\n            if ar[i] == ar[i + 1]: \r\n                count+=1\r\n            else: \r\n                break \r\n        res = max(res, count)  \r\n    return res", "source": "mbpp", "task_id": "953", "test_cases": "assert subset([1, 2, 3, 4],4) == 1\nassert subset([5, 6, 9, 3, 4, 3, 4],7) == 2\nassert subset([1, 2, 3 ],3) == 1", "difficulty": "code"}
{"input": "Write a function that gives profit amount if the given amount has profit else return none.", "answer": "def profit_amount(actual_cost,sale_amount): \r\n if(actual_cost > sale_amount):\r\n    amount = actual_cost - sale_amount\r\n    return amount\r\n else:\r\n    return None", "source": "mbpp", "task_id": "954", "test_cases": "assert profit_amount(1500,1200)==300\nassert profit_amount(100,200)==None\nassert profit_amount(2000,5000)==None", "difficulty": "code"}
{"input": "Write a function to find out, if the given number is abundant.", "answer": "def is_abundant(n):\r\n    fctrsum = sum([fctr for fctr in range(1, n) if n % fctr == 0])\r\n    return fctrsum > n", "source": "mbpp", "task_id": "955", "test_cases": "assert is_abundant(12)==True\nassert is_abundant(13)==False\nassert is_abundant(9)==False", "difficulty": "code"}
{"input": "Write a function to split the given string at uppercase letters by using regex.", "answer": "import re\r\ndef split_list(text):\r\n  return (re.findall('[A-Z][^A-Z]*', text))", "source": "mbpp", "task_id": "956", "test_cases": "assert split_list(\"LearnToBuildAnythingWithGoogle\") == ['Learn', 'To', 'Build', 'Anything', 'With', 'Google']\nassert split_list(\"ApmlifyingTheBlack+DeveloperCommunity\") == ['Apmlifying', 'The', 'Black+', 'Developer', 'Community']\nassert split_list(\"UpdateInTheGoEcoSystem\") == ['Update', 'In', 'The', 'Go', 'Eco', 'System']", "difficulty": "code"}
{"input": "Write a python function to get the position of rightmost set bit.", "answer": "import math\r\ndef get_First_Set_Bit_Pos(n):\r\n     return math.log2(n&-n)+1", "source": "mbpp", "task_id": "957", "test_cases": "assert get_First_Set_Bit_Pos(12) == 3\nassert get_First_Set_Bit_Pos(18) == 2\nassert get_First_Set_Bit_Pos(16) == 5", "difficulty": "code"}
{"input": "Write a function to convert an integer into a roman numeral.", "answer": "def int_to_roman( num):\r\n        val = [1000, 900, 500, 400,100, 90, 50, 40,10, 9, 5, 4,1]\r\n        syb = [\"M\", \"CM\", \"D\", \"CD\",\"C\", \"XC\", \"L\", \"XL\",\"X\", \"IX\", \"V\", \"IV\",\"I\"]\r\n        roman_num = ''\r\n        i = 0\r\n        while  num > 0:\r\n            for _ in range(num // val[i]):\r\n                roman_num += syb[i]\r\n                num -= val[i]\r\n            i += 1\r\n        return roman_num", "source": "mbpp", "task_id": "958", "test_cases": "assert int_to_roman(1)==(\"I\")\nassert int_to_roman(50)==(\"L\")\nassert int_to_roman(4)==(\"IV\")", "difficulty": "code"}
{"input": "Write a python function to find the average of a list.", "answer": "def Average(lst): \r\n    return sum(lst) / len(lst)", "source": "mbpp", "task_id": "959", "test_cases": "assert Average([15, 9, 55, 41, 35, 20, 62, 49]) == 35.75\nassert Average([4, 5, 1, 2, 9, 7, 10, 8]) == 5.75\nassert Average([1,2,3]) == 2", "difficulty": "code"}
{"input": "Write a function to solve tiling problem.", "answer": "def get_noOfways(n):\r\n    if (n == 0):\r\n        return 0;\r\n    if (n == 1):\r\n        return 1; \r\n    return get_noOfways(n - 1) + get_noOfways(n - 2);", "source": "mbpp", "task_id": "960", "test_cases": "assert get_noOfways(4)==3\nassert get_noOfways(3)==2\nassert get_noOfways(5)==5", "difficulty": "code"}
{"input": "Write a function to convert a roman numeral to an integer.", "answer": "def roman_to_int(s):\r\n        rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}\r\n        int_val = 0\r\n        for i in range(len(s)):\r\n            if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]:\r\n                int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]]\r\n            else:\r\n                int_val += rom_val[s[i]]\r\n        return int_val", "source": "mbpp", "task_id": "961", "test_cases": "assert roman_to_int('MMMCMLXXXVI')==3986\nassert roman_to_int('MMMM')==4000\nassert roman_to_int('C')==100", "difficulty": "code"}
{"input": "Write a python function to find the sum of all even natural numbers within the range l and r.", "answer": "def sum_Natural(n): \r\n    sum = (n * (n + 1)) \r\n    return int(sum) \r\ndef sum_Even(l,r): \r\n    return (sum_Natural(int(r / 2)) - sum_Natural(int((l - 1) / 2)))", "source": "mbpp", "task_id": "962", "test_cases": "assert sum_Even(2,5) == 6\nassert sum_Even(3,8) == 18\nassert sum_Even(4,6) == 10", "difficulty": "code"}
{"input": "Write a function to calculate the discriminant value.", "answer": "def discriminant_value(x,y,z):\r\n    discriminant = (y**2) - (4*x*z)\r\n    if discriminant > 0:\r\n        return (\"Two solutions\",discriminant)\r\n    elif discriminant == 0:\r\n        return (\"one solution\",discriminant)\r\n    elif discriminant < 0:\r\n        return (\"no real solution\",discriminant)", "source": "mbpp", "task_id": "963", "test_cases": "assert discriminant_value(4,8,2)==(\"Two solutions\",32)\nassert discriminant_value(5,7,9)==(\"no real solution\",-131)\nassert discriminant_value(0,0,9)==(\"one solution\",0)", "difficulty": "code"}
{"input": "Write a python function to check whether the length of the word is even or not.", "answer": "def word_len(s): \r\n    s = s.split(' ')   \r\n    for word in s:    \r\n        if len(word)%2==0: \r\n            return True  \r\n        else:\r\n          return False", "source": "mbpp", "task_id": "964", "test_cases": "assert word_len(\"program\") == False\nassert word_len(\"solution\") == True\nassert word_len(\"data\") == True", "difficulty": "code"}
{"input": "Write a function to convert camel case string to snake case string.", "answer": "def camel_to_snake(text):\r\n        import re\r\n        str1 = re.sub('(.)([A-Z][a-z]+)', r'\\1_\\2', text)\r\n        return re.sub('([a-z0-9])([A-Z])', r'\\1_\\2', str1).lower()", "source": "mbpp", "task_id": "965", "test_cases": "assert camel_to_snake('PythonProgram')==('python_program')\nassert camel_to_snake('pythonLanguage')==('python_language')\nassert camel_to_snake('ProgrammingLanguage')==('programming_language')", "difficulty": "code"}
{"input": "Write a function to remove an empty tuple from a list of tuples.", "answer": "def remove_empty(tuple1): #L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]\r\n   tuple1 = [t for t in tuple1 if t]\r\n   return tuple1", "source": "mbpp", "task_id": "966", "test_cases": "assert remove_empty([(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')])==[('',), ('a', 'b'), ('a', 'b', 'c'), 'd']  \nassert remove_empty([(), (), ('',), (\"python\"), (\"program\")])==[('',), (\"python\"), (\"program\")]  \nassert remove_empty([(), (), ('',), (\"java\")])==[('',),(\"java\") ]  ", "difficulty": "code"}
{"input": "Write a python function to accept the strings which contains all vowels.", "answer": "def check(string): \r\n  if len(set(string).intersection(\"AEIOUaeiou\"))>=5: \r\n    return ('accepted') \r\n  else: \r\n    return (\"not accepted\")", "source": "mbpp", "task_id": "967", "test_cases": "assert check(\"SEEquoiaL\") == 'accepted'\nassert check('program') == \"not accepted\"\nassert check('fine') == \"not accepted\"", "difficulty": "code"}
{"input": "Write a python function to find maximum possible value for the given periodic function.", "answer": "def floor_Max(A,B,N):\r\n    x = min(B - 1,N)\r\n    return (A*x) // B", "source": "mbpp", "task_id": "968", "test_cases": "assert floor_Max(11,10,9) == 9\nassert floor_Max(5,7,4) == 2\nassert floor_Max(2,2,1) == 1", "difficulty": "code"}
{"input": "Write a function to join the tuples if they have similar initial elements.", "answer": "def join_tuples(test_list):\r\n  res = []\r\n  for sub in test_list:\r\n    if res and res[-1][0] == sub[0]:\r\n      res[-1].extend(sub[1:])\r\n    else:\r\n      res.append([ele for ele in sub])\r\n  res = list(map(tuple, res))\r\n  return (res)", "source": "mbpp", "task_id": "969", "test_cases": "assert join_tuples([(5, 6), (5, 7), (6, 8), (6, 10), (7, 13)] ) == [(5, 6, 7), (6, 8, 10), (7, 13)]\nassert join_tuples([(6, 7), (6, 8), (7, 9), (7, 11), (8, 14)] ) == [(6, 7, 8), (7, 9, 11), (8, 14)]\nassert join_tuples([(7, 8), (7, 9), (8, 10), (8, 12), (9, 15)] ) == [(7, 8, 9), (8, 10, 12), (9, 15)]", "difficulty": "code"}
{"input": "Write a function to find minimum of two numbers.", "answer": "def min_of_two( x, y ):\r\n    if x < y:\r\n        return x\r\n    return y", "source": "mbpp", "task_id": "970", "test_cases": "assert min_of_two(10,20)==10\nassert min_of_two(19,15)==15\nassert min_of_two(-10,-20)==-20", "difficulty": "code"}
{"input": "Write a function to find the maximum number of segments of lengths a, b and c that can be formed from n.", "answer": "def maximum_segments(n, a, b, c) : \r\n\tdp = [-1] * (n + 10) \r\n\tdp[0] = 0\r\n\tfor i in range(0, n) : \r\n\t\tif (dp[i] != -1) : \r\n\t\t\tif(i + a <= n ): \r\n\t\t\t\tdp[i + a] = max(dp[i] + 1, \r\n\t\t\t\t\t\t\tdp[i + a]) \r\n\t\t\tif(i + b <= n ): \r\n\t\t\t\tdp[i + b] = max(dp[i] + 1, \r\n\t\t\t\t\t\t\tdp[i + b]) \r\n\t\t\tif(i + c <= n ): \r\n\t\t\t\tdp[i + c] = max(dp[i] + 1, \r\n\t\t\t\t\t\t\tdp[i + c]) \r\n\treturn dp[n]", "source": "mbpp", "task_id": "971", "test_cases": "assert maximum_segments(7, 5, 2, 5) == 2\nassert maximum_segments(17, 2, 1, 3) == 17\nassert maximum_segments(18, 16, 3, 6) == 6", "difficulty": "code"}
{"input": "Write a function to concatenate the given two tuples to a nested tuple.", "answer": "def concatenate_nested(test_tup1, test_tup2):\r\n  res = test_tup1 + test_tup2\r\n  return (res)", "source": "mbpp", "task_id": "972", "test_cases": "assert concatenate_nested((3, 4), (5, 6)) == (3, 4, 5, 6)\nassert concatenate_nested((1, 2), (3, 4)) == (1, 2, 3, 4)\nassert concatenate_nested((4, 5), (6, 8)) == (4, 5, 6, 8)", "difficulty": "code"}
{"input": "Write a python function to left rotate the string.", "answer": "def left_rotate(s,d):\r\n    tmp = s[d : ] + s[0 : d]\r\n    return tmp", "source": "mbpp", "task_id": "973", "test_cases": "assert left_rotate(\"python\",2) == \"thonpy\"   \nassert left_rotate(\"bigdata\",3 ) == \"databig\" \nassert left_rotate(\"hadoop\",1 ) == \"adooph\" ", "difficulty": "code"}
{"input": "Write a function to find the minimum total path sum in the given triangle.", "answer": "def min_sum_path(A): \r\n\tmemo = [None] * len(A) \r\n\tn = len(A) - 1\r\n\tfor i in range(len(A[n])): \r\n\t\tmemo[i] = A[n][i] \r\n\tfor i in range(len(A) - 2, -1,-1): \r\n\t\tfor j in range( len(A[i])): \r\n\t\t\tmemo[j] = A[i][j] + min(memo[j], \r\n\t\t\t\t\t\t\t\t\tmemo[j + 1]) \r\n\treturn memo[0]", "source": "mbpp", "task_id": "974", "test_cases": "assert min_sum_path([[ 2 ], [3, 9 ], [1, 6, 7 ]]) == 6\nassert min_sum_path([[ 2 ], [3, 7 ], [8, 5, 6 ]]) == 10 \nassert min_sum_path([[ 3 ], [6, 4 ], [5, 2, 7 ]]) == 9", "difficulty": "code"}