task_id
int32
11
510
text
stringlengths
37
191
code
stringlengths
37
1.33k
test_list
sequence
test_setup_code
stringclasses
2 values
challenge_test_list
sequence
311
Write a python function to set the left most unset bit.
def set_left_most_unset_bit(n): if not (n & (n + 1)): return n pos, temp, count = 0, n, 0 while temp: if not (temp & 1): pos = count count += 1; temp>>=1 return (n | (1 << (pos)))
[ "assert set_left_most_unset_bit(10) == 14", "assert set_left_most_unset_bit(12) == 14", "assert set_left_most_unset_bit(15) == 15" ]
[]
312
Write a function to find the volume of a cone.
import math def volume_cone(r,h): volume = (1.0/3) * math.pi * r * r * h return volume
[ "assert volume_cone(5,12)==314.15926535897927", "assert volume_cone(10,15)==1570.7963267948965", "assert volume_cone(19,17)==6426.651371693521" ]
[]
313
Write a python function to print positive numbers in a list.
def pos_nos(list1): for num in list1: if num >= 0: return num
[ "assert pos_nos([-1,-2,1,2]) == 1,2", "assert pos_nos([3,4,-5]) == 3,4", "assert pos_nos([-2,-3,1]) == 1" ]
[]
314
Write a function to find out the maximum sum such that no two chosen numbers are adjacent for the given rectangular grid of dimension 2 x n.
def max_sum_rectangular_grid(grid, n) : incl = max(grid[0][0], grid[1][0]) excl = 0 for i in range(1, n) : excl_new = max(excl, incl) incl = excl + max(grid[0][i], grid[1][i]) excl = excl_new return max(excl, incl)
[ "assert max_sum_rectangular_grid([ [1, 4, 5], [2, 0, 0 ] ], 3) == 7", "assert max_sum_rectangular_grid([ [ 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10] ], 5) == 24", "assert max_sum_rectangular_grid([ [7, 9, 11, 15, 19], [21, 25, 28, 31, 32] ], 5) == 81" ]
[]
315
Write a python function to find the first maximum length of even word.
def find_Max_Len_Even(str): n = len(str) i = 0 currlen = 0 maxlen = 0 st = -1 while (i < n): if (str[i] == ' '): if (currlen % 2 == 0): if (maxlen < currlen): maxlen = currlen st = i - currlen currlen = 0 else : currlen += 1 i += 1 if (currlen % 2 == 0): if (maxlen < currlen): maxlen = currlen st = i - currlen if (st == -1): return "-1" return str[st: st + maxlen]
[ "assert find_Max_Len_Even(\"python language\") == \"language\"", "assert find_Max_Len_Even(\"maximum even length\") == \"length\"", "assert find_Max_Len_Even(\"eve\") == \"-1\"" ]
[]
316
Write a function to find the index of the last occurrence of a given number in a sorted array.
def find_last_occurrence(A, x): (left, right) = (0, len(A) - 1) result = -1 while left <= right: mid = (left + right) // 2 if x == A[mid]: result = mid left = mid + 1 elif x < A[mid]: right = mid - 1 else: left = mid + 1 return result
[ "assert find_last_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 3", "assert find_last_occurrence([2, 3, 5, 8, 6, 6, 8, 9, 9, 9], 9) == 9", "assert find_last_occurrence([2, 2, 1, 5, 6, 6, 6, 9, 9, 9], 6) == 6" ]
[]
317
Write a function to reflect the modified run-length encoding from a list.
from itertools import groupby def modified_encode(alist): def ctr_ele(el): if len(el)>1: return [len(el), el[0]] else: return el[0] return [ctr_ele(list(group)) for key, group in groupby(alist)]
[ "assert modified_encode([1,1,2,3,4,4,5,1])==[[2, 1], 2, 3, [2, 4], 5, 1]", "assert modified_encode('automatically')==['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', [2, 'l'], 'y']", "assert modified_encode('python')==['p', 'y', 't', 'h', 'o', 'n']" ]
[]
318
Write a python function to find the maximum volume of a cuboid with given sum of sides.
def max_volume (s): maxvalue = 0 i = 1 for i in range(s - 1): j = 1 for j in range(s): k = s - i - j maxvalue = max(maxvalue, i * j * k) return maxvalue
[ "assert max_volume(8) == 18", "assert max_volume(4) == 2", "assert max_volume(1) == 0" ]
[]
319
Write a function to find all five characters long word in the given string by using regex.
import re def find_long_word(text): return (re.findall(r"\b\w{5}\b", text))
[ "assert find_long_word('Please move back to strem') == ['strem']", "assert find_long_word('4K Ultra HD streaming player') == ['Ultra']", "assert find_long_word('Streaming Media Player') == ['Media']" ]
[]
320
Write a function to calculate the difference between the squared sum of first n natural numbers and the sum of squared first n natural numbers.
def sum_difference(n): sumofsquares = 0 squareofsum = 0 for num in range(1, n+1): sumofsquares += num * num squareofsum += num squareofsum = squareofsum ** 2 return squareofsum - sumofsquares
[ "assert sum_difference(12)==5434", "assert sum_difference(20)==41230", "assert sum_difference(54)==2151270" ]
[]
321
Write a function to find the demlo number for the given number.
def find_demlo(s): l = len(s) res = "" for i in range(1,l+1): res = res + str(i) for i in range(l-1,0,-1): res = res + str(i) return res
[ "assert find_demlo(\"111111\") == '12345654321'", "assert find_demlo(\"1111\") == '1234321'", "assert find_demlo(\"13333122222\") == '123456789101110987654321'" ]
[]
322
Write a function to find all index positions of the minimum values in a given list.
def position_min(list1): min_val = min(list1) min_result = [i for i, j in enumerate(list1) if j == min_val] return min_result
[ "assert position_min([12,33,23,10,67,89,45,667,23,12,11,10,54])==[3,11]", "assert position_min([1,2,2,2,4,4,4,5,5,5,5])==[0]", "assert position_min([2,1,5,6,8,3,4,9,10,11,8,12])==[1]" ]
[]
323
Write a function to re-arrange the given array in alternating positive and negative items.
def right_rotate(arr, n, out_of_place, cur): temp = arr[cur] for i in range(cur, out_of_place, -1): arr[i] = arr[i - 1] arr[out_of_place] = temp return arr def re_arrange(arr, n): out_of_place = -1 for index in range(n): if (out_of_place >= 0): if ((arr[index] >= 0 and arr[out_of_place] < 0) or (arr[index] < 0 and arr[out_of_place] >= 0)): arr = right_rotate(arr, n, out_of_place, index) if (index-out_of_place > 2): out_of_place += 2 else: out_of_place = - 1 if (out_of_place == -1): if ((arr[index] >= 0 and index % 2 == 0) or (arr[index] < 0 and index % 2 == 1)): out_of_place = index return arr
[ "assert re_arrange([-5, -2, 5, 2, 4,\t7, 1, 8, 0, -8], 10) == [-5, 5, -2, 2, -8, 4, 7, 1, 8, 0]", "assert re_arrange([1, 2, 3, -4, -1, 4], 6) == [-4, 1, -1, 2, 3, 4]", "assert re_arrange([4, 7, 9, 77, -4, 5, -3, -9], 8) == [-4, 4, -3, 7, -9, 9, 77, 5]" ]
[]
324
Write a function to extract the sum of alternate chains of tuples.
def sum_of_alternates(test_tuple): sum1 = 0 sum2 = 0 for idx, ele in enumerate(test_tuple): if idx % 2: sum1 += ele else: sum2 += ele return ((sum1),(sum2))
[ "assert sum_of_alternates((5, 6, 3, 6, 10, 34)) == (46, 18)", "assert sum_of_alternates((1, 2, 3, 4, 5)) == (6, 9)", "assert sum_of_alternates((6, 7, 8, 9, 4, 5)) == (21, 18)" ]
[]
325
Write a python function to find the minimum number of squares whose sum is equal to a given number.
def get_Min_Squares(n): if n <= 3: return n; res = n for x in range(1,n + 1): temp = x * x; if temp > n: break else: res = min(res,1 + get_Min_Squares(n - temp)) return res;
[ "assert get_Min_Squares(6) == 3", "assert get_Min_Squares(2) == 2", "assert get_Min_Squares(4) == 1" ]
[]
326
Write a function to get the word with most number of occurrences in the given strings list.
from collections import defaultdict def most_occurrences(test_list): temp = defaultdict(int) for sub in test_list: for wrd in sub.split(): temp[wrd] += 1 res = max(temp, key=temp.get) return (str(res))
[ "assert most_occurrences([\"UTS is best for RTF\", \"RTF love UTS\", \"UTS is best\"] ) == 'UTS'", "assert most_occurrences([\"Its been a great year\", \"this year is so worse\", \"this year is okay\"] ) == 'year'", "assert most_occurrences([\"Families can be reunited\", \"people can be reunited\", \"Tasks can be achieved \"] ) == 'can'" ]
[]
327
Write a function to print check if the triangle is isosceles or not.
def check_isosceles(x,y,z): if x==y or y==z or z==x: return True else: return False
[ "assert check_isosceles(6,8,12)==False ", "assert check_isosceles(6,6,12)==True", "assert check_isosceles(6,16,20)==False" ]
[]
328
Write a function to rotate a given list by specified number of items to the left direction.
def rotate_left(list1,m,n): result = list1[m:]+list1[:n] return result
[ "assert rotate_left([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],3,4)==[4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4]", "assert rotate_left([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2,2)==[3, 4, 5, 6, 7, 8, 9, 10, 1, 2]", "assert rotate_left([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],5,2)==[6, 7, 8, 9, 10, 1, 2]" ]
[]
329
Write a python function to count negative numbers in a list.
def neg_count(list): neg_count= 0 for num in list: if num <= 0: neg_count += 1 return neg_count
[ "assert neg_count([-1,-2,3,-4,-5]) == 4", "assert neg_count([1,2,3]) == 0", "assert neg_count([1,2,-3,-10,20]) == 2" ]
[]
330
Write a function to find all three, four, five characters long words in the given string by using regex.
import re def find_char(text): return (re.findall(r"\b\w{3,5}\b", text))
[ "assert find_char('For the four consumer complaints contact manager AKR reddy') == ['For', 'the', 'four', 'AKR', 'reddy']", "assert find_char('Certain service are subject to change MSR') == ['are', 'MSR']", "assert find_char('Third party legal desclaimers') == ['Third', 'party', 'legal']" ]
[]
331
Write a python function to count unset bits of a given number.
def count_unset_bits(n): count = 0 x = 1 while(x < n + 1): if ((x & n) == 0): count += 1 x = x << 1 return count
[ "assert count_unset_bits(2) == 1", "assert count_unset_bits(4) == 2", "assert count_unset_bits(6) == 1" ]
[]
332
Write a function to count character frequency of a given string.
def char_frequency(str1): dict = {} for n in str1: keys = dict.keys() if n in keys: dict[n] += 1 else: dict[n] = 1 return dict
[ "assert char_frequency('python')=={'p': 1, 'y': 1, 't': 1, 'h': 1, 'o': 1, 'n': 1}", "assert char_frequency('program')=={'p': 1, 'r': 2, 'o': 1, 'g': 1, 'a': 1, 'm': 1}", "assert char_frequency('language')=={'l': 1, 'a': 2, 'n': 1, 'g': 2, 'u': 1, 'e': 1}" ]
[]
333
Write a python function to sort a list according to the second element in sublist.
def Sort(sub_li): sub_li.sort(key = lambda x: x[1]) return sub_li
[ "assert Sort([['a', 10], ['b', 5], ['c', 20], ['d', 15]]) == [['b', 5], ['a', 10], ['d', 15], ['c', 20]]", "assert Sort([['452', 10], ['256', 5], ['100', 20], ['135', 15]]) == [['256', 5], ['452', 10], ['135', 15], ['100', 20]]", "assert Sort([['rishi', 10], ['akhil', 5], ['ramya', 20], ['gaur', 15]]) == [['akhil', 5], ['rishi', 10], ['gaur', 15], ['ramya', 20]]" ]
[]
334
Write a python function to check whether the triangle is valid or not if sides are given.
def check_Validity(a,b,c): if (a + b <= c) or (a + c <= b) or (b + c <= a) : return False else: return True
[ "assert check_Validity(1,2,3) == False", "assert check_Validity(2,3,5) == False", "assert check_Validity(7,10,5) == True" ]
[]
335
Write a function to find the sum of arithmetic progression.
def ap_sum(a,n,d): total = (n * (2 * a + (n - 1) * d)) / 2 return total
[ "assert ap_sum(1,5,2)==25", "assert ap_sum(2,6,4)==72", "assert ap_sum(1,4,5)==34" ]
[]
336
Write a function to check whether the given month name contains 28 days or not.
def check_monthnum(monthname1): if monthname1 == "February": return True else: return False
[ "assert check_monthnum(\"February\")==True", "assert check_monthnum(\"January\")==False", "assert check_monthnum(\"March\")==False" ]
[]
337
Write a function that matches a word at the end of a string, with optional punctuation.
import re def text_match_word(text): patterns = '\w+\S*$' if re.search(patterns, text): return 'Found a match!' else: return 'Not matched!'
[ "assert text_match_word(\"python.\")==('Found a match!')", "assert text_match_word(\"python.\")==('Found a match!')", "assert text_match_word(\" lang .\")==('Not matched!')" ]
[]
338
Write a python function to count the number of substrings with same first and last characters.
def check_Equality(s): return (ord(s[0]) == ord(s[len(s) - 1])); def count_Substring_With_Equal_Ends(s): result = 0; n = len(s); for i in range(n): for j in range(1,n-i+1): if (check_Equality(s[i:i+j])): result+=1; return result;
[ "assert count_Substring_With_Equal_Ends('aba') == 4", "assert count_Substring_With_Equal_Ends('abcab') == 7", "assert count_Substring_With_Equal_Ends('abc') == 3" ]
[]
339
Write a python function to find the maximum occuring divisor in an interval.
def find_Divisor(x,y): if (x==y): return y return 2
[ "assert find_Divisor(2,2) == 2", "assert find_Divisor(2,5) == 2", "assert find_Divisor(5,10) == 2" ]
[]
340
Write a python function to find the sum of the three lowest positive numbers from a given list of numbers.
def sum_three_smallest_nums(lst): return sum(sorted([x for x in lst if x > 0])[:3])
[ "assert sum_three_smallest_nums([10,20,30,40,50,60,7]) == 37", "assert sum_three_smallest_nums([1,2,3,4,5]) == 6", "assert sum_three_smallest_nums([0,1,2,3,4,5]) == 6" ]
[]
341
Write a function to convert the given set into ordered tuples.
def set_to_tuple(s): t = tuple(sorted(s)) return (t)
[ "assert set_to_tuple({1, 2, 3, 4, 5}) == (1, 2, 3, 4, 5)", "assert set_to_tuple({6, 7, 8, 9, 10, 11}) == (6, 7, 8, 9, 10, 11)", "assert set_to_tuple({12, 13, 14, 15, 16}) == (12, 13, 14, 15, 16)" ]
[]
342
Write a function to find the smallest range that includes at-least one element from each of the given arrays.
from heapq import heappop, heappush class Node: def __init__(self, value, list_num, index): self.value = value self.list_num = list_num self.index = index def __lt__(self, other): return self.value < other.value def find_minimum_range(list): high = float('-inf') p = (0, float('inf')) pq = [] for i in range(len(list)): heappush(pq, Node(list[i][0], i, 0)) high = max(high, list[i][0]) while True: top = heappop(pq) low = top.value i = top.list_num j = top.index if high - low < p[1] - p[0]: p = (low, high) if j == len(list[i]) - 1: return p heappush(pq, Node(list[i][j + 1], i, j + 1)) high = max(high, list[i][j + 1])
[ "assert find_minimum_range([[3, 6, 8, 10, 15], [1, 5, 12], [4, 8, 15, 16], [2, 6]]) == (4, 6)", "assert find_minimum_range([[ 2, 3, 4, 8, 10, 15 ], [1, 5, 12], [7, 8, 15, 16], [3, 6]]) == (4, 7)", "assert find_minimum_range([[4, 7, 9, 11, 16], [2, 6, 13], [5, 9, 16, 17], [3, 7]]) == (5, 7)" ]
[]
343
Write a function to calculate the number of digits and letters in a string.
def dig_let(s): d=l=0 for c in s: if c.isdigit(): d=d+1 elif c.isalpha(): l=l+1 else: pass return (l,d)
[ "assert dig_let(\"python\")==(6,0)", "assert dig_let(\"program\")==(7,0)", "assert dig_let(\"python3.0\")==(6,2)" ]
[]
344
Write a python function to find number of elements with odd factors in a given range.
def count_Odd_Squares(n,m): return int(m**0.5) - int((n-1)**0.5)
[ "assert count_Odd_Squares(5,100) == 8", "assert count_Odd_Squares(8,65) == 6", "assert count_Odd_Squares(2,5) == 1" ]
[]
345
Write a function to find the difference between two consecutive numbers in a given list.
def diff_consecutivenums(nums): result = [b-a for a, b in zip(nums[:-1], nums[1:])] return result
[ "assert diff_consecutivenums([1, 1, 3, 4, 4, 5, 6, 7])==[0, 2, 1, 0, 1, 1, 1]", "assert diff_consecutivenums([4, 5, 8, 9, 6, 10])==[1, 3, 1, -3, 4]", "assert diff_consecutivenums([0, 1, 2, 3, 4, 4, 4, 4, 5, 7])==[1, 1, 1, 1, 0, 0, 0, 1, 2]" ]
[]
346
Write a function to find entringer number e(n, k).
def zigzag(n, k): if (n == 0 and k == 0): return 1 if (k == 0): return 0 return zigzag(n, k - 1) + zigzag(n - 1, n - k)
[ "assert zigzag(4, 3) == 5", "assert zigzag(4, 2) == 4", "assert zigzag(3, 1) == 1" ]
[]
347
Write a python function to count the number of squares in a rectangle.
def count_Squares(m,n): if (n < m): temp = m m = n n = temp return n * (n + 1) * (3 * m - n + 1) // 6
[ "assert count_Squares(4,3) == 20", "assert count_Squares(1,2) == 2", "assert count_Squares(2,2) == 5" ]
[]
348
Write a function to count sequences of given length having non-negative prefix sums that can be generated by given values.
def bin_coff(n, r): val = 1 if (r > (n - r)): r = (n - r) for i in range(0, r): val *= (n - i) val //= (i + 1) return val def find_ways(M): n = M // 2 a = bin_coff(2 * n, n) b = a // (n + 1) return (b)
[ "assert find_ways(4) == 2", "assert find_ways(6) == 5", "assert find_ways(8) == 14" ]
[]
349
Write a python function to check whether the given string is a binary string or not.
def check(string) : p = set(string) s = {'0', '1'} if s == p or p == {'0'} or p == {'1'}: return ("Yes") else : return ("No")
[ "assert check(\"01010101010\") == \"Yes\"", "assert check(\"name0\") == \"No\"", "assert check(\"101\") == \"Yes\"" ]
[]
350
Write a python function to minimize the length of the string by removing occurrence of only one character.
def minimum_Length(s) : maxOcc = 0 n = len(s) arr = [0]*26 for i in range(n) : arr[ord(s[i]) -ord('a')] += 1 for i in range(26) : if arr[i] > maxOcc : maxOcc = arr[i] return n - maxOcc
[ "assert minimum_Length(\"mnm\") == 1", "assert minimum_Length(\"abcda\") == 3", "assert minimum_Length(\"abcb\") == 2" ]
[]
351
Write a python function to find the first element occurring k times in a given array.
def first_Element(arr,n,k): count_map = {}; for i in range(0, n): if(arr[i] in count_map.keys()): count_map[arr[i]] += 1 else: count_map[arr[i]] = 1 i += 1 for i in range(0, n): if (count_map[arr[i]] == k): return arr[i] i += 1 return -1
[ "assert first_Element([0,1,2,3,4,5],6,1) == 0", "assert first_Element([1,2,1,3,4],5,2) == 1", "assert first_Element([2,3,4,3,5,7,1,2,3,5],10,2) == 2" ]
[]
352
Write a python function to check whether all the characters in a given string are unique.
def unique_Characters(str): for i in range(len(str)): for j in range(i + 1,len(str)): if (str[i] == str[j]): return False; return True;
[ "assert unique_Characters('aba') == False", "assert unique_Characters('abc') == True", "assert unique_Characters('abab') == False" ]
[]
353
Write a function to remove a specified column from a given nested list.
def remove_column(list1, n): for i in list1: del i[n] return list1
[ "assert remove_column([[1, 2, 3], [2, 4, 5], [1, 1, 1]],0)==[[2, 3], [4, 5], [1, 1]]", "assert remove_column([[1, 2, 3], [-2, 4, -5], [1, -1, 1]],2)==[[1, 2], [-2, 4], [1, -1]]", "assert remove_column([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]],0)==[[3], [7], [3], [15, 17], [7], [11]]" ]
[]
354
Write a function to find t-nth term of arithemetic progression.
def tn_ap(a,n,d): tn = a + (n - 1) * d return tn
[ "assert tn_ap(1,5,2)==9", "assert tn_ap(2,6,4)==22", "assert tn_ap(1,4,5)==16" ]
[]
355
Write a python function to count the number of rectangles in a circle of radius r.
def count_Rectangles(radius): rectangles = 0 diameter = 2 * radius diameterSquare = diameter * diameter for a in range(1, 2 * radius): for b in range(1, 2 * radius): diagnalLengthSquare = (a * a + b * b) if (diagnalLengthSquare <= diameterSquare) : rectangles += 1 return rectangles
[ "assert count_Rectangles(2) == 8", "assert count_Rectangles(1) == 1", "assert count_Rectangles(0) == 0" ]
[]
356
Write a function to find the third angle of a triangle using two angles.
def find_angle(a,b): c = 180 - (a + b) return c
[ "assert find_angle(47,89)==44", "assert find_angle(45,95)==40", "assert find_angle(50,40)==90" ]
[]
357
Write a function to find the maximum element of all the given tuple records.
def find_max(test_list): res = max(int(j) for i in test_list for j in i) return (res)
[ "assert find_max([(2, 4), (6, 7), (5, 1), (6, 10), (8, 7)]) == 10", "assert find_max([(3, 5), (7, 8), (6, 2), (7, 11), (9, 8)]) == 11", "assert find_max([(4, 6), (8, 9), (7, 3), (8, 12), (10, 9)]) == 12" ]
[]
358
Write a function to find modulo division of two lists using map and lambda function.
def moddiv_list(nums1,nums2): result = map(lambda x, y: x % y, nums1, nums2) return list(result)
[ "assert moddiv_list([4,5,6],[1, 2, 3])==[0, 1, 0]", "assert moddiv_list([3,2],[1,4])==[0, 2]", "assert moddiv_list([90,120],[50,70])==[40, 50]" ]
[]
359
Write a python function to check whether one root of the quadratic equation is twice of the other or not.
def Check_Solution(a,b,c): if (2*b*b == 9*a*c): return ("Yes"); else: return ("No");
[ "assert Check_Solution(1,3,2) == \"Yes\"", "assert Check_Solution(1,2,3) == \"No\"", "assert Check_Solution(1,-5,6) == \"No\"" ]
[]
360
Write a function to find the n’th carol number.
def get_carol(n): result = (2**n) - 1 return result * result - 2
[ "assert get_carol(2) == 7", "assert get_carol(4) == 223", "assert get_carol(5) == 959" ]
[]
361
Write a function to remove empty lists from a given list of lists.
def remove_empty(list1): remove_empty = [x for x in list1 if x] return remove_empty
[ "assert remove_empty([[], [], [], 'Red', 'Green', [1,2], 'Blue', [], []])==['Red', 'Green', [1, 2], 'Blue']", "assert remove_empty([[], [], [],[],[], 'Green', [1,2], 'Blue', [], []])==[ 'Green', [1, 2], 'Blue']", "assert remove_empty([[], [], [], 'Python',[],[], 'programming', 'language',[],[],[], [], []])==['Python', 'programming', 'language']" ]
[]
362
Write a python function to find the item with maximum occurrences in a given list.
def max_occurrences(nums): max_val = 0 result = nums[0] for i in nums: occu = nums.count(i) if occu > max_val: max_val = occu result = i return result
[ "assert max_occurrences([1,2,3,1,2,3,12,4,2]) == 2", "assert max_occurrences([1,2,6,7,0,1,0,1,0]) == 1,0", "assert max_occurrences([1,2,3,1,2,4,1]) == 1" ]
[]
363
Write a function to add the k elements to each element in the tuple.
def add_K_element(test_list, K): res = [tuple(j + K for j in sub ) for sub in test_list] return (res)
[ "assert add_K_element([(1, 3, 4), (2, 4, 6), (3, 8, 1)], 4) == [(5, 7, 8), (6, 8, 10), (7, 12, 5)]", "assert add_K_element([(1, 2, 3), (4, 5, 6), (7, 8, 9)], 8) == [(9, 10, 11), (12, 13, 14), (15, 16, 17)]", "assert add_K_element([(11, 12, 13), (14, 15, 16), (17, 18, 19)], 9) == [(20, 21, 22), (23, 24, 25), (26, 27, 28)]" ]
[]
364
Write a function to find the number of flips required to make the given binary string a sequence of alternate characters.
def make_flip(ch): return '1' if (ch == '0') else '0' def get_flip_with_starting_charcter(str, expected): flip_count = 0 for i in range(len( str)): if (str[i] != expected): flip_count += 1 expected = make_flip(expected) return flip_count def min_flip_to_make_string_alternate(str): return min(get_flip_with_starting_charcter(str, '0'),get_flip_with_starting_charcter(str, '1'))
[ "assert min_flip_to_make_string_alternate(\"0001010111\") == 2", "assert min_flip_to_make_string_alternate(\"001\") == 1", "assert min_flip_to_make_string_alternate(\"010111011\") == 2 " ]
[]
365
Write a python function to count the number of digits of a given number.
def count_Digit(n): count = 0 while n != 0: n //= 10 count += 1 return count
[ "assert count_Digit(12345) == 5", "assert count_Digit(11223305) == 8", "assert count_Digit(4123459) == 7" ]
[]
366
Write a python function to find the largest product of the pair of adjacent elements from a given list of integers.
def adjacent_num_product(list_nums): return max(a*b for a, b in zip(list_nums, list_nums[1:]))
[ "assert adjacent_num_product([1,2,3,4,5,6]) == 30", "assert adjacent_num_product([1,2,3,4,5]) == 20", "assert adjacent_num_product([2,3]) == 6" ]
[]
367
Write a function to check if a binary tree is balanced or not.
class Node: def __init__(self, data): self.data = data self.left = None self.right = None def get_height(root): if root is None: return 0 return max(get_height(root.left), get_height(root.right)) + 1 def is_tree_balanced(root): if root is None: return True lh = get_height(root.left) rh = get_height(root.right) if (abs(lh - rh) <= 1) and is_tree_balanced( root.left) is True and is_tree_balanced( root.right) is True: return True return False
[ "assert is_tree_balanced(root) == False", "assert is_tree_balanced(root1) == True", "assert is_tree_balanced(root2) == False " ]
root = Node(1) root.left = Node(2) root.right = Node(3) root.left.left = Node(4) root.left.right = Node(5) root.left.left.left = Node(8) root1 = Node(1) root1.left = Node(2) root1.right = Node(3) root1.left.left = Node(4) root1.left.right = Node(5) root1.right.left = Node(6) root1.left.left.left = Node(7) root2 = Node(1) root2.left = Node(2) root2.right = Node(3) root2.left.left = Node(4) root2.left.right = Node(5) root2.left.left.left = Node(7)
[]
368
Write a function to repeat the given tuple n times.
def repeat_tuples(test_tup, N): res = ((test_tup, ) * N) return (res)
[ "assert repeat_tuples((1, 3), 4) == ((1, 3), (1, 3), (1, 3), (1, 3))", "assert repeat_tuples((1, 2), 3) == ((1, 2), (1, 2), (1, 2))", "assert repeat_tuples((3, 4), 5) == ((3, 4), (3, 4), (3, 4), (3, 4), (3, 4))" ]
[]
369
Write a function to find the lateral surface area of cuboid
def lateralsurface_cuboid(l,w,h): LSA = 2*h*(l+w) return LSA
[ "assert lateralsurface_cuboid(8,5,6)==156", "assert lateralsurface_cuboid(7,9,10)==320", "assert lateralsurface_cuboid(10,20,30)==1800" ]
[]
370
Write a function to sort a tuple by its float element.
def float_sort(price): float_sort=sorted(price, key=lambda x: float(x[1]), reverse=True) return float_sort
[ "assert float_sort([('item1', '12.20'), ('item2', '15.10'), ('item3', '24.5')])==[('item3', '24.5'), ('item2', '15.10'), ('item1', '12.20')] ", "assert float_sort([('item1', '15'), ('item2', '10'), ('item3', '20')])==[('item3', '20'), ('item1', '15'), ('item2', '10')] ", "assert float_sort([('item1', '5'), ('item2', '10'), ('item3', '14')])==[('item3', '14'), ('item2', '10'), ('item1', '5')] " ]
[]
371
Write a function to find the smallest missing element in a sorted array.
def smallest_missing(A, left_element, right_element): if left_element > right_element: return left_element mid = left_element + (right_element - left_element) // 2 if A[mid] == mid: return smallest_missing(A, mid + 1, right_element) else: return smallest_missing(A, left_element, mid - 1)
[ "assert smallest_missing([0, 1, 2, 3, 4, 5, 6], 0, 6) == 7", "assert smallest_missing([0, 1, 2, 6, 9, 11, 15], 0, 6) == 3", "assert smallest_missing([1, 2, 3, 4, 6, 9, 11, 15], 0, 7) == 0" ]
[]
372
Write a function to sort a given list of elements in ascending order using heap queue algorithm.
import heapq as hq def heap_assending(nums): hq.heapify(nums) s_result = [hq.heappop(nums) for i in range(len(nums))] return s_result
[ "assert heap_assending([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1])==[1, 2, 3, 4, 7, 8, 9, 9, 10, 14, 18]", "assert heap_assending([25, 35, 22, 85, 14, 65, 75, 25, 58])==[14, 22, 25, 25, 35, 58, 65, 75, 85]", "assert heap_assending([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]" ]
[]
373
Write a function to find the volume of a cuboid.
def volume_cuboid(l,w,h): volume=l*w*h return volume
[ "assert volume_cuboid(1,2,3)==6", "assert volume_cuboid(5,7,9)==315", "assert volume_cuboid(10,15,21)==3150" ]
[]
374
Write a function to print all permutations of a given string including duplicates.
def permute_string(str): if len(str) == 0: return [''] prev_list = permute_string(str[1:len(str)]) next_list = [] for i in range(0,len(prev_list)): for j in range(0,len(str)): new_str = prev_list[i][0:j]+str[0]+prev_list[i][j:len(str)-1] if new_str not in next_list: next_list.append(new_str) return next_list
[ "assert permute_string('ab')==['ab', 'ba']", "assert permute_string('abc')==['abc', 'bac', 'bca', 'acb', 'cab', 'cba']", "assert permute_string('abcd')==['abcd', 'bacd', 'bcad', 'bcda', 'acbd', 'cabd', 'cbad', 'cbda', 'acdb', 'cadb', 'cdab', 'cdba', 'abdc', 'badc', 'bdac', 'bdca', 'adbc', 'dabc', 'dbac', 'dbca', 'adcb', 'dacb', 'dcab', 'dcba']" ]
[]
375
Write a function to round the given number to the nearest multiple of a specific number.
def round_num(n,m): a = (n //m) * m b = a + m return (b if n - a > b - n else a)
[ "assert round_num(4722,10)==4720", "assert round_num(1111,5)==1110", "assert round_num(219,2)==218" ]
[]
376
Write a function to remove tuple elements that occur more than once and replace the duplicates with some custom value.
def remove_replica(test_tup): temp = set() res = tuple(ele if ele not in temp and not temp.add(ele) else 'MSP' for ele in test_tup) return (res)
[ "assert remove_replica((1, 1, 4, 4, 4, 5, 5, 6, 7, 7)) == (1, 'MSP', 4, 'MSP', 'MSP', 5, 'MSP', 6, 7, 'MSP')", "assert remove_replica((2, 3, 4, 4, 5, 6, 6, 7, 8, 9, 9)) == (2, 3, 4, 'MSP', 5, 6, 'MSP', 7, 8, 9, 'MSP')", "assert remove_replica((2, 2, 5, 4, 5, 7, 5, 6, 7, 7)) == (2, 'MSP', 5, 4, 'MSP', 7, 'MSP', 6, 'MSP', 'MSP')" ]
[]
377
Write a python function to remove all occurrences of a character in a given string.
def remove_Char(s,c) : counts = s.count(c) s = list(s) while counts : s.remove(c) counts -= 1 s = '' . join(s) return (s)
[ "assert remove_Char(\"aba\",'a') == \"b\"", "assert remove_Char(\"toggle\",'g') == \"tole\"", "assert remove_Char(\"aabbc\",'b') == \"aac\"" ]
[]
378
Write a python function to shift last element to first position in the given list.
def move_first(test_list): test_list = test_list[-1:] + test_list[:-1] return test_list
[ "assert move_first([1,2,3,4]) == [4,1,2,3]", "assert move_first([0,1,2,3]) == [3,0,1,2]", "assert move_first([9,8,7,1]) == [1,9,8,7]" ]
[]
379
Write a function to find the surface area of a cuboid.
def surfacearea_cuboid(l,w,h): SA = 2*(l*w + l * h + w * h) return SA
[ "assert surfacearea_cuboid(1,2,3)==22", "assert surfacearea_cuboid(5,7,9)==286", "assert surfacearea_cuboid(10,15,21)==1350" ]
[]
380
Write a function to generate a two-dimensional array.
def multi_list(rownum,colnum): multi_list = [[0 for col in range(colnum)] for row in range(rownum)] for row in range(rownum): for col in range(colnum): multi_list[row][col]= row*col return multi_list
[ "assert multi_list(3,4)==[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6]] ", "assert multi_list(5,7)==[[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6], [0, 2, 4, 6, 8, 10, 12], [0, 3, 6, 9, 12, 15, 18], [0, 4, 8, 12, 16, 20, 24]]", "assert multi_list(10,15)==[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28], [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42], [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56], [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70], [0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84], [0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98], [0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112], [0, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126]]" ]
[]
381
Write a function to sort a list of lists by a given index of the inner list.
from operator import itemgetter def index_on_inner_list(list_data, index_no): result = sorted(list_data, key=itemgetter(index_no)) return result
[ "assert index_on_inner_list([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,0)==[('Beau Turnbull', 94, 98), ('Brady Kent', 97, 96), ('Greyson Fulton', 98, 99), ('Wyatt Knott', 91, 94)]", "assert index_on_inner_list([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,1)==[('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98), ('Brady Kent', 97, 96), ('Greyson Fulton', 98, 99)]", "assert index_on_inner_list([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,2)==[('Wyatt Knott', 91, 94), ('Brady Kent', 97, 96), ('Beau Turnbull', 94, 98), ('Greyson Fulton', 98, 99)]" ]
[]
382
Write a function to find the number of rotations in a circularly sorted array.
def find_rotation_count(A): (left, right) = (0, len(A) - 1) while left <= right: if A[left] <= A[right]: return left mid = (left + right) // 2 next = (mid + 1) % len(A) prev = (mid - 1 + len(A)) % len(A) if A[mid] <= A[next] and A[mid] <= A[prev]: return mid elif A[mid] <= A[right]: right = mid - 1 elif A[mid] >= A[left]: left = mid + 1 return -1
[ "assert find_rotation_count([8, 9, 10, 1, 2, 3, 4, 5, 6, 7]) == 3", "assert find_rotation_count([8, 9, 10,2, 5, 6]) == 3", "assert find_rotation_count([2, 5, 6, 8, 9, 10]) == 0" ]
[]
383
Write a python function to toggle all odd bits of a given number.
def even_bit_toggle_number(n) : res = 0; count = 0; temp = n while(temp > 0 ) : if (count % 2 == 0) : res = res | (1 << count) count = count + 1 temp >>= 1 return n ^ res
[ "assert even_bit_toggle_number(10) == 15", "assert even_bit_toggle_number(20) == 1", "assert even_bit_toggle_number(30) == 11" ]
[]
384
Write a python function to find the frequency of the smallest value in a given array.
def frequency_Of_Smallest(n,arr): mn = arr[0] freq = 1 for i in range(1,n): if (arr[i] < mn): mn = arr[i] freq = 1 elif (arr[i] == mn): freq += 1 return freq
[ "assert frequency_Of_Smallest(5,[1,2,3,4,3]) == 1", "assert frequency_Of_Smallest(7,[3,1,2,5,6,2,3]) == 1", "assert frequency_Of_Smallest(7,[3,3,6,3,7,4,9]) == 3" ]
[]
385
Write a function to find the n'th perrin number using recursion.
def get_perrin(n): if (n == 0): return 3 if (n == 1): return 0 if (n == 2): return 2 return get_perrin(n - 2) + get_perrin(n - 3)
[ "assert get_perrin(9) == 12", "assert get_perrin(4) == 2", "assert get_perrin(6) == 5" ]
[]
386
Write a function to find out the minimum no of swaps required for bracket balancing in the given string.
def swap_count(s): chars = s count_left = 0 count_right = 0 swap = 0 imbalance = 0; for i in range(len(chars)): if chars[i] == '[': count_left += 1 if imbalance > 0: swap += imbalance imbalance -= 1 elif chars[i] == ']': count_right += 1 imbalance = (count_right - count_left) return swap
[ "assert swap_count(\"[]][][\") == 2", "assert swap_count(\"[[][]]\") == 0", "assert swap_count(\"[[][]]][\") == 1" ]
[]
387
Write a python function to check whether the hexadecimal number is even or odd.
def even_or_odd(N): l = len(N) if (N[l-1] =='0'or N[l-1] =='2'or N[l-1] =='4'or N[l-1] =='6'or N[l-1] =='8'or N[l-1] =='A'or N[l-1] =='C'or N[l-1] =='E'): return ("Even") else: return ("Odd")
[ "assert even_or_odd(\"AB3454D\") ==\"Odd\"", "assert even_or_odd(\"ABC\") == \"Even\"", "assert even_or_odd(\"AAD\") == \"Odd\"" ]
[]
388
Write a python function to find the highest power of 2 that is less than or equal to n.
def highest_Power_of_2(n): res = 0; for i in range(n, 0, -1): if ((i & (i - 1)) == 0): res = i; break; return res;
[ "assert highest_Power_of_2(10) == 8", "assert highest_Power_of_2(19) == 16", "assert highest_Power_of_2(32) == 32" ]
[]
389
Write a function to find the n'th lucas number.
def find_lucas(n): if (n == 0): return 2 if (n == 1): return 1 return find_lucas(n - 1) + find_lucas(n - 2)
[ "assert find_lucas(9) == 76", "assert find_lucas(4) == 7", "assert find_lucas(3) == 4" ]
[]
390
Write a function to insert a given string at the beginning of all items in a list.
def add_string(list,string): add_string=[string.format(i) for i in list] return add_string
[ "assert add_string([1,2,3,4],'temp{0}')==['temp1', 'temp2', 'temp3', 'temp4']", "assert add_string(['a','b','c','d'], 'python{0}')==[ 'pythona', 'pythonb', 'pythonc', 'pythond']", "assert add_string([5,6,7,8],'string{0}')==['string5', 'string6', 'string7', 'string8']" ]
[]
391
Write a function to convert more than one list to nested dictionary.
def convert_list_dictionary(l1, l2, l3): result = [{x: {y: z}} for (x, y, z) in zip(l1, l2, l3)] return result
[ "assert convert_list_dictionary([\"S001\", \"S002\", \"S003\", \"S004\"],[\"Adina Park\", \"Leyton Marsh\", \"Duncan Boyle\", \"Saim Richards\"] ,[85, 98, 89, 92])==[{'S001': {'Adina Park': 85}}, {'S002': {'Leyton Marsh': 98}}, {'S003': {'Duncan Boyle': 89}}, {'S004': {'Saim Richards': 92}}]", "assert convert_list_dictionary([\"abc\",\"def\",\"ghi\",\"jkl\"],[\"python\",\"program\",\"language\",\"programs\"],[100,200,300,400])==[{'abc':{'python':100}},{'def':{'program':200}},{'ghi':{'language':300}},{'jkl':{'programs':400}}]", "assert convert_list_dictionary([\"A1\",\"A2\",\"A3\",\"A4\"],[\"java\",\"C\",\"C++\",\"DBMS\"],[10,20,30,40])==[{'A1':{'java':10}},{'A2':{'C':20}},{'A3':{'C++':30}},{'A4':{'DBMS':40}}]" ]
[]
392
Write a function to find the maximum sum possible by using the given equation f(n) = max( (f(n/2) + f(n/3) + f(n/4) + f(n/5)), n).
def get_max_sum (n): res = list() res.append(0) res.append(1) i = 2 while i<n + 1: res.append(max(i, (res[int(i / 2)] + res[int(i / 3)] + res[int(i / 4)] + res[int(i / 5)]))) i = i + 1 return res[n]
[ "assert get_max_sum(60) == 106", "assert get_max_sum(10) == 12", "assert get_max_sum(2) == 2" ]
[]
393
Write a function to find the list with maximum length using lambda function.
def max_length_list(input_list): max_length = max(len(x) for x in input_list ) max_list = max(input_list, key = lambda i: len(i)) return(max_length, max_list)
[ "assert max_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])", "assert max_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(5,[1,2,3,4,5])", "assert max_length_list([[3,4,5],[6,7,8,9],[10,11,12]])==(4,[6,7,8,9])" ]
[]
394
Write a function to check if given tuple is distinct or not.
def check_distinct(test_tup): res = True temp = set() for ele in test_tup: if ele in temp: res = False break temp.add(ele) return (res)
[ "assert check_distinct((1, 4, 5, 6, 1, 4)) == False", "assert check_distinct((1, 4, 5, 6)) == True", "assert check_distinct((2, 3, 4, 5, 6)) == True" ]
[]
395
Write a python function to find the first non-repeated character in a given string.
def first_non_repeating_character(str1): char_order = [] ctr = {} for c in str1: if c in ctr: ctr[c] += 1 else: ctr[c] = 1 char_order.append(c) for c in char_order: if ctr[c] == 1: return c return None
[ "assert first_non_repeating_character(\"abcabc\") == None", "assert first_non_repeating_character(\"abc\") == \"a\"", "assert first_non_repeating_character(\"ababc\") == \"c\"" ]
[]
396
Write a function to check whether the given string starts and ends with the same character or not using regex.
import re regex = r'^[a-z]$|^([a-z]).*\1$' def check_char(string): if(re.search(regex, string)): return "Valid" else: return "Invalid"
[ "assert check_char(\"abba\") == \"Valid\"", "assert check_char(\"a\") == \"Valid\"", "assert check_char(\"abcd\") == \"Invalid\"" ]
[]
397
Write a function to find the median of three specific numbers.
def median_numbers(a,b,c): if a > b: if a < c: median = a elif b > c: median = b else: median = c else: if a > c: median = a elif b < c: median = b else: median = c return median
[ "assert median_numbers(25,55,65)==55.0", "assert median_numbers(20,10,30)==20.0", "assert median_numbers(15,45,75)==45.0" ]
[]
398
Write a function to compute the sum of digits of each number of a given list.
def sum_of_digits(nums): return sum(int(el) for n in nums for el in str(n) if el.isdigit())
[ "assert sum_of_digits([10,2,56])==14", "assert sum_of_digits([[10,20,4,5,'b',70,'a']])==19", "assert sum_of_digits([10,20,-4,5,-70])==19" ]
[]
399
Write a function to perform the mathematical bitwise xor operation across the given tuples.
def bitwise_xor(test_tup1, test_tup2): res = tuple(ele1 ^ ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res)
[ "assert bitwise_xor((10, 4, 6, 9), (5, 2, 3, 3)) == (15, 6, 5, 10)", "assert bitwise_xor((11, 5, 7, 10), (6, 3, 4, 4)) == (13, 6, 3, 14)", "assert bitwise_xor((12, 6, 8, 11), (7, 4, 5, 6)) == (11, 2, 13, 13)" ]
[]
400
Write a function to extract the frequency of unique tuples in the given list order irrespective.
def extract_freq(test_list): res = len(list(set(tuple(sorted(sub)) for sub in test_list))) return (res)
[ "assert extract_freq([(3, 4), (1, 2), (4, 3), (5, 6)] ) == 3", "assert extract_freq([(4, 15), (2, 3), (5, 4), (6, 7)] ) == 4", "assert extract_freq([(5, 16), (2, 3), (6, 5), (6, 9)] ) == 4" ]
[]
401
Write a function to perform index wise addition of tuple elements in the given two nested tuples.
def add_nested_tuples(test_tup1, test_tup2): res = tuple(tuple(a + b for a, b in zip(tup1, tup2)) for tup1, tup2 in zip(test_tup1, test_tup2)) return (res)
[ "assert add_nested_tuples(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((7, 10), (7, 14), (3, 10), (8, 13))", "assert add_nested_tuples(((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))) == ((9, 12), (9, 16), (5, 12), (10, 15))", "assert add_nested_tuples(((3, 5), (6, 7), (4, 11), (3, 12)), ((8, 9), (5, 11), (3, 3), (9, 5))) == ((11, 14), (11, 18), (7, 14), (12, 17))" ]
[]
402
Write a function to compute the value of ncr%p.
def ncr_modp(n, r, p): C = [0 for i in range(r+1)] C[0] = 1 for i in range(1, n+1): for j in range(min(i, r), 0, -1): C[j] = (C[j] + C[j-1]) % p return C[r]
[ "assert ncr_modp(10,2,13)==6", "assert ncr_modp(15,12,43)==25", "assert ncr_modp(17,9,18)==10" ]
[]
403
Write a function to check if a url is valid or not using regex.
import re def is_valid_URL(str): regex = ("((http|https)://)(www.)?" + "[a-zA-Z0-9@:%._\\+~#?&//=]" + "{2,256}\\.[a-z]" + "{2,6}\\b([-a-zA-Z0-9@:%" + "._\\+~#?&//=]*)") p = re.compile(regex) if (str == None): return False if(re.search(p, str)): return True else: return False
[ "assert is_valid_URL(\"https://www.google.com\") == True", "assert is_valid_URL(\"https:/www.gmail.com\") == False", "assert is_valid_URL(\"https:// www.redit.com\") == False" ]
[]
404
Write a python function to find the minimum of two numbers.
def minimum(a,b): if a <= b: return a else: return b
[ "assert minimum(1,2) == 1", "assert minimum(-5,-4) == -5", "assert minimum(0,0) == 0" ]
[]
405
Write a function to check whether an element exists within a tuple.
def check_tuplex(tuplex,tuple1): if tuple1 in tuplex: return True else: return False
[ "assert check_tuplex((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),'r')==True", "assert check_tuplex((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\", \"e\"),'5')==False", "assert check_tuplex((\"w\", 3, \"r\", \"e\", \"s\", \"o\", \"u\", \"r\", \"c\",\"e\"),3)==True" ]
[]
406
Write a python function to find the parity of a given number.
def find_Parity(x): y = x ^ (x >> 1); y = y ^ (y >> 2); y = y ^ (y >> 4); y = y ^ (y >> 8); y = y ^ (y >> 16); if (y & 1): return ("Odd Parity"); return ("Even Parity");
[ "assert find_Parity(12) == \"Even Parity\"", "assert find_Parity(7) == \"Odd Parity\"", "assert find_Parity(10) == \"Even Parity\"" ]
[]
407
Write a function to create the next bigger number by rearranging the digits of a given number.
def rearrange_bigger(n): nums = list(str(n)) for i in range(len(nums)-2,-1,-1): if nums[i] < nums[i+1]: z = nums[i:] y = min(filter(lambda x: x > z[0], z)) z.remove(y) z.sort() nums[i:] = [y] + z return int("".join(nums)) return False
[ "assert rearrange_bigger(12)==21", "assert rearrange_bigger(10)==False", "assert rearrange_bigger(102)==120" ]
[]
408
Write a function to find k number of pairs which consist of one element from the first array and one element from the second array.
import heapq def k_smallest_pairs(nums1, nums2, k): queue = [] def push(i, j): if i < len(nums1) and j < len(nums2): heapq.heappush(queue, [nums1[i] + nums2[j], i, j]) push(0, 0) pairs = [] while queue and len(pairs) < k: _, i, j = heapq.heappop(queue) pairs.append([nums1[i], nums2[j]]) push(i, j + 1) if j == 0: push(i + 1, 0) return pairs
[ "assert k_smallest_pairs([1,3,7],[2,4,6],2)==[[1, 2], [1, 4]]", "assert k_smallest_pairs([1,3,7],[2,4,6],1)==[[1, 2]]", "assert k_smallest_pairs([1,3,7],[2,4,6],7)==[[1, 2], [1, 4], [3, 2], [1, 6], [3, 4], [3, 6], [7, 2]]" ]
[]
409
Write a function to find the minimum product from the pairs of tuples within a given list.
def min_product_tuple(list1): result_min = min([abs(x * y) for x, y in list1] ) return result_min
[ "assert min_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==8", "assert min_product_tuple([(10,20), (15,2), (5,10)] )==30", "assert min_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==100" ]
[]
410
Write a function to find the minimum value in a given heterogeneous list.
def min_val(listval): min_val = min(i for i in listval if isinstance(i, int)) return min_val
[ "assert min_val(['Python', 3, 2, 4, 5, 'version'])==2", "assert min_val(['Python', 15, 20, 25])==15", "assert min_val(['Python', 30, 20, 40, 50, 'version'])==20" ]
[]