,source,target,program_id 0,"Write a function to find the minimum cost path to reach (m, n) from (0, 0) for the given cost matrix cost[][] and a position (m, n) in cost[][].","R = 3 C = 3 def min_cost(cost, m, n): tc = [[0 for x in range(C)] for x in range(R)] tc[0][0] = cost[0][0] for i in range(1, m+1): tc[i][0] = tc[i-1][0] + cost[i][0] for j in range(1, n+1): tc[0][j] = tc[0][j-1] + cost[0][j] for i in range(1, m+1): for j in range(1, n+1): tc[i][j] = min(tc[i-1][j-1], tc[i-1][j], tc[i][j-1]) + cost[i][j] return tc[m][n]",MBPP_0 1,Write a function to find the similar elements from the given two tuple lists.,"def similar_elements(test_tup1, test_tup2): res = tuple(set(test_tup1) & set(test_tup2)) return (res) ",MBPP_1 2,Write a python function to identify non-prime numbers.,"import math def is_not_prime(n): result = False for i in range(2,int(math.sqrt(n)) + 1): if n % i == 0: result = True return result",MBPP_2 3,Write a function to find the largest integers from a given list of numbers using heap queue algorithm.,"import heapq as hq def heap_queue_largest(nums,n): largest_nums = hq.nlargest(n, nums) return largest_nums",MBPP_3 4,Write a function to find the number of ways to fill it with 2 x 1 dominoes for the given 3 x n board.,"def count_ways(n): A = [0] * (n + 1) B = [0] * (n + 1) A[0] = 1 A[1] = 0 B[0] = 0 B[1] = 1 for i in range(2, n+1): A[i] = A[i - 2] + 2 * B[i - 1] B[i] = A[i - 1] + B[i - 2] return A[n] ",MBPP_4 5,Write a python function to check whether the two numbers differ at one bit position only or not.,"def is_Power_Of_Two (x): return x and (not(x & (x - 1))) def differ_At_One_Bit_Pos(a,b): return is_Power_Of_Two(a ^ b)",MBPP_5 6,Write a function to find all words which are at least 4 characters long in a string by using regex.,"import re def find_char_long(text): return (re.findall(r""\b\w{4,}\b"", text))",MBPP_6 7,Write a function to find squares of individual elements in a list using lambda function.,"def square_nums(nums): square_nums = list(map(lambda x: x ** 2, nums)) return square_nums",MBPP_7 8,Write a python function to find the minimum number of rotations required to get the same string.,"def find_Rotations(str): tmp = str + str n = len(str) for i in range(1,n + 1): substring = tmp[i: i+n] if (str == substring): return i return n ",MBPP_8 9,Write a function to get the n smallest items from a dataset.,"import heapq def small_nnum(list1,n): smallest=heapq.nsmallest(n,list1) return smallest",MBPP_9 10,Write a python function to remove first and last occurrence of a given character from the string.,"def remove_Occ(s,ch): for i in range(len(s)): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break for i in range(len(s) - 1,-1,-1): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break return s ",MBPP_10 11,Write a function to sort a given matrix in ascending order according to the sum of its rows.,"def sort_matrix(M): result = sorted(M, key=sum) return result",MBPP_11 12,Write a function to count the most common words in a dictionary.,"from collections import Counter def count_common(words): word_counts = Counter(words) top_four = word_counts.most_common(4) return (top_four) ",MBPP_12 13,Write a python function to find the volume of a triangular prism.,"def find_Volume(l,b,h) : return ((l * b * h) / 2) ",MBPP_13 14,Write a function to split a string at lowercase letters.,"import re def split_lowerstring(text): return (re.findall('[a-z][^a-z]*', text))",MBPP_14 15,Write a function to find sequences of lowercase letters joined with an underscore.,"import re def text_lowercase_underscore(text): patterns = '^[a-z]+_[a-z]+$' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')",MBPP_15 16,Write a function to find the perimeter of a square.,"def square_perimeter(a): perimeter=4*a return perimeter",MBPP_16 17,Write a function to remove characters from the first string which are present in the second string.,"NO_OF_CHARS = 256 def str_to_list(string): temp = [] for x in string: temp.append(x) return temp def lst_to_string(List): return ''.join(List) def get_char_count_array(string): count = [0] * NO_OF_CHARS for i in string: count[ord(i)] += 1 return count def remove_dirty_chars(string, second_string): count = get_char_count_array(second_string) ip_ind = 0 res_ind = 0 temp = '' str_list = str_to_list(string) while ip_ind != len(str_list): temp = str_list[ip_ind] if count[ord(temp)] == 0: str_list[res_ind] = str_list[ip_ind] res_ind += 1 ip_ind+=1 return lst_to_string(str_list[0:res_ind]) ",MBPP_17 18,Write a function to find whether a given array of integers contains any duplicate element.,"def test_duplicate(arraynums): nums_set = set(arraynums) return len(arraynums) != len(nums_set) ",MBPP_18 19,Write a function to check if the given number is woodball or not.,"def is_woodall(x): if (x % 2 == 0): return False if (x == 1): return True x = x + 1 p = 0 while (x % 2 == 0): x = x/2 p = p + 1 if (p == x): return True return False",MBPP_19 20,Write a function to find m number of multiples of n.,"def multiples_of_num(m,n): multiples_of_num= list(range(n,(m+1)*n, n)) return list(multiples_of_num)",MBPP_20 21,Write a function to find the first duplicate element in a given array of integers.,"def find_first_duplicate(nums): num_set = set() no_duplicate = -1 for i in range(len(nums)): if nums[i] in num_set: return nums[i] else: num_set.add(nums[i]) return no_duplicate",MBPP_21 22,Write a python function to find the maximum sum of elements of list in a list of lists.,"def maximum_Sum(list1): maxi = -100000 for x in list1: sum = 0 for y in x: sum+= y maxi = max(sum,maxi) return maxi ",MBPP_22 23,Write a function to convert the given binary number to its decimal equivalent.,"def binary_to_decimal(binary): binary1 = binary decimal, i, n = 0, 0, 0 while(binary != 0): dec = binary % 10 decimal = decimal + dec * pow(2, i) binary = binary//10 i += 1 return (decimal)",MBPP_23 24,Write a python function to find the product of non-repeated elements in a given array.,"def find_Product(arr,n): arr.sort() prod = 1 for i in range(0,n,1): if (arr[i - 1] != arr[i]): prod = prod * arr[i] return prod; ",MBPP_24 25,Write a function to check if the given tuple list has all k elements.,"def check_k_elements(test_list, K): res = True for tup in test_list: for ele in tup: if ele != K: res = False return (res) ",MBPP_25 26,Write a python function to remove all digits from a list of strings.,"import re def remove(list): pattern = '[0-9]' list = [re.sub(pattern, '', i) for i in list] return list",MBPP_26 27,Write a python function to find binomial co-efficient.,"def binomial_Coeff(n,k): if k > n : return 0 if k==0 or k ==n : return 1 return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k) ",MBPP_27 28,Write a python function to find the element occurring odd number of times.,"def get_Odd_Occurrence(arr,arr_size): for i in range(0,arr_size): count = 0 for j in range(0,arr_size): if arr[i] == arr[j]: count+=1 if (count % 2 != 0): return arr[i] return -1",MBPP_28 29,Write a python function to count all the substrings starting and ending with same 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; ",MBPP_29 30,Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm.,"def func(nums, k): import collections d = collections.defaultdict(int) for row in nums: for i in row: d[i] += 1 temp = [] import heapq for key, v in d.items(): if len(temp) < k: temp.append((v, key)) if len(temp) == k: heapq.heapify(temp) else: if v > temp[0][0]: heapq.heappop(temp) heapq.heappush(temp, (v, key)) result = [] while temp: v, key = heapq.heappop(temp) result.append(key) return result",MBPP_30 31,Write a python function to find the largest prime factor of a given number.,"import math def max_Prime_Factors (n): maxPrime = -1 while n%2 == 0: maxPrime = 2 n >>= 1 for i in range(3,int(math.sqrt(n))+1,2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime)",MBPP_31 32,Write a python function to convert a decimal number to binary number.,"def decimal_To_Binary(N): B_Number = 0 cnt = 0 while (N != 0): rem = N % 2 c = pow(10,cnt) B_Number += rem*c N //= 2 cnt += 1 return B_Number ",MBPP_32 33,Write a python function to find the missing number in a sorted array.,"def find_missing(ar,N): l = 0 r = N - 1 while (l <= r): mid = (l + r) / 2 mid= int (mid) if (ar[mid] != mid + 1 and ar[mid - 1] == mid): return (mid + 1) elif (ar[mid] != mid + 1): r = mid - 1 else: l = mid + 1 return (-1) ",MBPP_33 34,Write a function to find the n-th rectangular number.,"def find_rect_num(n): return n*(n + 1) ",MBPP_34 35,Write a python function to find the nth digit in the proper fraction of two given numbers.,"def find_Nth_Digit(p,q,N) : while (N > 0) : N -= 1; p *= 10; res = p // q; p %= q; return res; ",MBPP_35 36,Write a function to sort a given mixed list of integers and strings.,"def sort_mixed_list(mixed_list): int_part = sorted([i for i in mixed_list if type(i) is int]) str_part = sorted([i for i in mixed_list if type(i) is str]) return int_part + str_part",MBPP_36 37,Write a function to find the division of first even and odd number of a given list.,"def div_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el for el in list1 if el%2!=0),-1) return (first_even/first_odd)",MBPP_37 38,Write a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different.,"import heapq from collections import Counter def rearange_string(S): ctr = Counter(S) heap = [(-value, key) for key, value in ctr.items()] heapq.heapify(heap) if (-heap[0][0]) * 2 > len(S) + 1: return """" ans = [] while len(heap) >= 2: nct1, char1 = heapq.heappop(heap) nct2, char2 = heapq.heappop(heap) ans.extend([char1, char2]) if nct1 + 1: heapq.heappush(heap, (nct1 + 1, char1)) if nct2 + 1: heapq.heappush(heap, (nct2 + 1, char2)) return """".join(ans) + (heap[0][1] if heap else """")",MBPP_38 39,Write a function to find frequency of the elements in a given list of lists using collections module.,"from collections import Counter from itertools import chain def freq_element(nums): result = Counter(chain.from_iterable(nums)) return result",MBPP_39 40,Write a function to filter even numbers using lambda function.,"def filter_evennumbers(nums): even_nums = list(filter(lambda x: x%2 == 0, nums)) return even_nums",MBPP_40 41,Write a python function to find the sum of repeated elements in a given array.,"def find_Sum(arr,n): return sum([x for x in arr if arr.count(x) > 1])",MBPP_41 42,Write a function to find sequences of lowercase letters joined with an underscore using regex.,"import re def text_match(text): patterns = '^[a-z]+_[a-z]+$' if re.search(patterns, text): return ('Found a match!') else: return ('Not matched!')",MBPP_42 43,Write a function that matches a word at the beginning of a string.,"import re def text_match_string(text): patterns = '^\w+' if re.search(patterns, text): return 'Found a match!' else: return 'Not matched!'",MBPP_43 44,Write a function to find the gcd of the given array elements.,"def find_gcd(x, y): while(y): x, y = y, x % y return x def get_gcd(l): num1 = l[0] num2 = l[1] gcd = find_gcd(num1, num2) for i in range(2, len(l)): gcd = find_gcd(gcd, l[i]) return gcd",MBPP_44 45,Write a python function to determine whether all the numbers are different from each other are not.,"def test_distinct(data): if len(data) == len(set(data)): return True else: return False;",MBPP_45 46,Write a python function to find the last digit when factorial of a divides factorial of b.,"def compute_Last_Digit(A,B): variable = 1 if (A == B): return 1 elif ((B - A) >= 5): return 0 else: for i in range(A + 1,B + 1): variable = (variable * (i % 10)) % 10 return variable % 10",MBPP_46 47,Write a python function to set all odd bits of a given number.,"def odd_bit_set_number(n): count = 0;res = 0;temp = n while temp > 0: if count % 2 == 0: res |= (1 << count) count += 1 temp >>= 1 return (n | res)",MBPP_47 48,Write a function to extract every first or specified element from a given two-dimensional list.,"def specified_element(nums, N): result = [i[N] for i in nums] return result ",MBPP_48 49,Write a function to find the list with minimum length using lambda function.,"def min_length_list(input_list): min_length = min(len(x) for x in input_list ) min_list = min(input_list, key = lambda i: len(i)) return(min_length, min_list)",MBPP_49 50,Write a function to print check if the triangle is equilateral or not.,"def check_equilateral(x,y,z): if x == y == z: return True else: return False",MBPP_50 51,Write a function to caluclate area of a parallelogram.,"def parallelogram_area(b,h): area=b*h return area",MBPP_51 52,Write a python function to check whether the first and last characters of a given string are equal or not.,"def check_Equality(str): if (str[0] == str[-1]): return (""Equal"") else: return (""Not Equal"") ",MBPP_52 53,Write a function to sort the given array by using counting sort.,"def counting_sort(my_list): max_value = 0 for i in range(len(my_list)): if my_list[i] > max_value: max_value = my_list[i] buckets = [0] * (max_value + 1) for i in my_list: buckets[i] += 1 i = 0 for j in range(max_value + 1): for a in range(buckets[j]): my_list[i] = j i += 1 return my_list",MBPP_53 54,Write a function to find t-nth term of geometric series.,"import math def tn_gp(a,n,r): tn = a * (math.pow(r, n - 1)) return tn",MBPP_54 55,Write a python function to check if a given number is one less than twice its reverse.,"def rev(num): rev_num = 0 while (num > 0): rev_num = (rev_num * 10 + num % 10) num = num // 10 return rev_num def check(n): return (2 * rev(n) == n + 1) ",MBPP_55 56,Write a python function to find the largest number that can be formed with the given digits.,"def find_Max_Num(arr,n) : arr.sort(reverse = True) num = arr[0] for i in range(1,n) : num = num * 10 + arr[i] return num ",MBPP_56 57,Write a python function to check whether the given two integers have opposite sign or not.,"def opposite_Signs(x,y): return ((x ^ y) < 0); ",MBPP_57 58,Write a function to find the nth octagonal number.,"def is_octagonal(n): return 3 * n * n - 2 * n ",MBPP_58 59,Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array.,"def max_len_sub( arr, n): mls=[] max = 0 for i in range(n): mls.append(1) for i in range(n): for j in range(i): if (abs(arr[i] - arr[j]) <= 1 and mls[i] < mls[j] + 1): mls[i] = mls[j] + 1 for i in range(n): if (max < mls[i]): max = mls[i] return max",MBPP_59 60,Write a python function to count number of substrings with the sum of digits equal to their length.,"from collections import defaultdict def count_Substrings(s,n): count,sum = 0,0 mp = defaultdict(lambda : 0) mp[0] += 1 for i in range(n): sum += ord(s[i]) - ord('0') count += mp[sum - (i + 1)] mp[sum - (i + 1)] += 1 return count",MBPP_60 61,Write a python function to find smallest number in a list.,"def smallest_num(xs): return min(xs) ",MBPP_61 62,Write a function to find the maximum difference between available pairs in the given tuple list.,"def max_difference(test_list): temp = [abs(b - a) for a, b in test_list] res = max(temp) return (res) ",MBPP_62 63,Write a function to sort a list of tuples using lambda.,"def subject_marks(subjectmarks): #subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]) subjectmarks.sort(key = lambda x: x[1]) return subjectmarks",MBPP_63 64,Write a function of recursion list sum.,"def recursive_list_sum(data_list): total = 0 for element in data_list: if type(element) == type([]): total = total + recursive_list_sum(element) else: total = total + element return total",MBPP_64 65,Write a python function to count positive numbers in a list.,"def pos_count(list): pos_count= 0 for num in list: if num >= 0: pos_count += 1 return pos_count ",MBPP_65 66,Write a function to find the number of ways to partition a set of bell numbers.,"def bell_number(n): bell = [[0 for i in range(n+1)] for j in range(n+1)] bell[0][0] = 1 for i in range(1, n+1): bell[i][0] = bell[i-1][i-1] for j in range(1, i+1): bell[i][j] = bell[i-1][j-1] + bell[i][j-1] return bell[n][0] ",MBPP_66 67,Write a python function to check whether the given array is monotonic or not.,"def is_Monotonic(A): return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or all(A[i] >= A[i + 1] for i in range(len(A) - 1))) ",MBPP_67 68,Write a function to check whether a list contains the given sublist or not.,"def is_sublist(l, s): sub_set = False if s == []: sub_set = True elif s == l: sub_set = True elif len(s) > len(l): sub_set = False else: for i in range(len(l)): if l[i] == s[0]: n = 1 while (n < len(s)) and (l[i+n] == s[n]): n += 1 if n == len(s): sub_set = True return sub_set",MBPP_68 69,Write a function to find whether all the given tuples have equal length or not.,"def find_equal_tuple(Input, k): flag = 1 for tuple in Input: if len(tuple) != k: flag = 0 break return flag def get_equal(Input, k): if find_equal_tuple(Input, k) == 1: return (""All tuples have same length"") else: return (""All tuples do not have same length"")",MBPP_69 70,Write a function to sort a list of elements using comb sort.,"def comb_sort(nums): shrink_fact = 1.3 gaps = len(nums) swapped = True i = 0 while gaps > 1 or swapped: gaps = int(float(gaps) / shrink_fact) swapped = False i = 0 while gaps + i < len(nums): if nums[i] > nums[i+gaps]: nums[i], nums[i+gaps] = nums[i+gaps], nums[i] swapped = True i += 1 return nums",MBPP_70 71,Write a python function to check whether the given number can be represented as difference of two squares or not.,"def dif_Square(n): if (n % 4 != 2): return True return False",MBPP_71 72,Write a function to split the given string with multiple delimiters by using regex.,"import re def multiple_split(text): return (re.split('; |, |\*|\n',text))",MBPP_72 73,Write a function to check whether it follows the sequence given in the patterns array.,"def is_samepatterns(colors, patterns): if len(colors) != len(patterns): return False sdict = {} pset = set() sset = set() for i in range(len(patterns)): pset.add(patterns[i]) sset.add(colors[i]) if patterns[i] not in sdict.keys(): sdict[patterns[i]] = [] keys = sdict[patterns[i]] keys.append(colors[i]) sdict[patterns[i]] = keys if len(pset) != len(sset): return False for values in sdict.values(): for i in range(len(values) - 1): if values[i] != values[i+1]: return False return True",MBPP_73 74,Write a function to find tuples which have all elements divisible by k from the given list of tuples.,"def find_tuples(test_list, K): res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)] return (str(res)) ",MBPP_74 75,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 ((m * (m + 1) * (2 * m + 1) / 6 + (n - m) * m * (m + 1) / 2))",MBPP_75 76,Write a python function to find the difference between sum of even and odd digits.,"def is_Diff(n): return (n % 11 == 0) ",MBPP_76 77,Write a python function to find number of integers with odd number of set bits.,"def count_With_Odd_SetBits(n): if (n % 2 != 0): return (n + 1) / 2 count = bin(n).count('1') ans = n / 2 if (count % 2 != 0): ans += 1 return ans ",MBPP_77 78,Write a python function to check whether the length of the word is odd or not.,"def word_len(s): s = s.split(' ') for word in s: if len(word)%2!=0: return True else: return False",MBPP_78 79,Write a function to find the nth tetrahedral number.,"def tetrahedral_number(n): return (n * (n + 1) * (n + 2)) / 6",MBPP_79 80,Write a function to zip the two given tuples.,"def zip_tuples(test_tup1, test_tup2): res = [] for i, j in enumerate(test_tup1): res.append((j, test_tup2[i % len(test_tup2)])) return (res) ",MBPP_80 81,Write a function to find the volume of a sphere.,"import math def volume_sphere(r): volume=(4/3)*math.pi*r*r*r return volume",MBPP_81 82,Write a python function to find the character made by adding all the characters of the given string.,"def get_Char(strr): summ = 0 for i in range(len(strr)): summ += (ord(strr[i]) - ord('a') + 1) if (summ % 26 == 0): return ord('z') else: summ = summ % 26 return chr(ord('a') + summ - 1)",MBPP_82 83,Write a function to find the n-th number in newman conway sequence.,"def sequence(n): if n == 1 or n == 2: return 1 else: return sequence(sequence(n-1)) + sequence(n-sequence(n-1))",MBPP_83 84,Write a function to find the surface area of a sphere.,"import math def surfacearea_sphere(r): surfacearea=4*math.pi*r*r return surfacearea",MBPP_84 85,Write a function to find nth centered hexagonal number.,"def centered_hexagonal_number(n): return 3 * n * (n - 1) + 1",MBPP_85 86,Write a function to merge three dictionaries into a single expression.,"import collections as ct def merge_dictionaries_three(dict1,dict2, dict3): merged_dict = dict(ct.ChainMap({},dict1,dict2,dict3)) return merged_dict",MBPP_86 87,Write a function to get the frequency of the elements in a list.,"import collections def freq_count(list1): freq_count= collections.Counter(list1) return freq_count",MBPP_87 88,Write a function to find the closest smaller number than n.,"def closest_num(N): return (N - 1)",MBPP_88 89,Write a python function to find the length of the longest word.,"def len_log(list1): max=len(list1[0]) for i in list1: if len(i)>max: max=len(i) return max",MBPP_89 90,Write a function to check if a substring is present in a given list of string values.,"def find_substring(str1, sub_str): if any(sub_str in s for s in str1): return True return False",MBPP_90 91,Write a function to check whether the given number is undulating or not.,"def is_undulating(n): if (len(n) <= 2): return False for i in range(2, len(n)): if (n[i - 2] != n[i]): return False return True",MBPP_91 92,Write a function to calculate the value of 'a' to the power 'b'.,"def power(a,b): if b==0: return 1 elif a==0: return 0 elif b==1: return a else: return a*power(a,b-1)",MBPP_92 93,Write a function to extract the index minimum value record from the given tuples.,"from operator import itemgetter def index_minimum(test_list): res = min(test_list, key = itemgetter(1))[0] return (res) ",MBPP_93 94,Write a python function to find the minimum length of sublist.,"def Find_Min_Length(lst): minLength = min(len(x) for x in lst ) return minLength ",MBPP_94 95,Write a python function to find the number of divisors of a given integer.,"def divisor(n): for i in range(n): x = len([i for i in range(1,n+1) if not n % i]) return x",MBPP_95 96,Write a function to find frequency count of list of lists.,"def frequency_lists(list1): list1 = [item for sublist in list1 for item in sublist] dic_data = {} for num in list1: if num in dic_data.keys(): dic_data[num] += 1 else: key = num value = 1 dic_data[key] = value return dic_data ",MBPP_96 97,Write a function to multiply all the numbers in a list and divide with the length of the list.,"def multiply_num(numbers): total = 1 for x in numbers: total *= x return total/len(numbers) ",MBPP_97 98,Write a function to convert the given decimal number to its binary equivalent.,"def decimal_to_binary(n): return bin(n).replace(""0b"","""") ",MBPP_98 99,Write a function to find the next smallest palindrome of a specified number.,"import sys def next_smallest_palindrome(num): numstr = str(num) for i in range(num+1,sys.maxsize): if str(i) == str(i)[::-1]: return i",MBPP_99 100,Write a function to find the kth element in the given array.,"def kth_element(arr, n, k): for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] == arr[j+1], arr[j] return arr[k-1]",MBPP_100 101,Write a function to convert snake case string to camel case string.,"def snake_to_camel(word): import re return ''.join(x.capitalize() or '_' for x in word.split('_'))",MBPP_101 102,"Write a function to find eulerian number a(n, m).","def eulerian_num(n, m): if (m >= n or n == 0): return 0 if (m == 0): return 1 return ((n - m) * eulerian_num(n - 1, m - 1) +(m + 1) * eulerian_num(n - 1, m))",MBPP_102 103,Write a function to sort each sublist of strings in a given list of lists using lambda function.,"def sort_sublists(input_list): result = [sorted(x, key = lambda x:x[0]) for x in input_list] return result ",MBPP_103 104,Write a python function to count true booleans in the given list.,"def count(lst): return sum(lst) ",MBPP_104 105,Write a function to add the given list to the given tuples.,"def add_lists(test_list, test_tup): res = tuple(list(test_tup) + test_list) return (res) ",MBPP_105 106,Write a python function to count hexadecimal numbers for a given range.,"def count_Hexadecimal(L,R) : count = 0; for i in range(L,R + 1) : if (i >= 10 and i <= 15) : count += 1; elif (i > 15) : k = i; while (k != 0) : if (k % 16 >= 10) : count += 1; k = k // 16; return count; ",MBPP_106 107,Write a function to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm.,"import heapq def merge_sorted_list(num1,num2,num3): num1=sorted(num1) num2=sorted(num2) num3=sorted(num3) result = heapq.merge(num1,num2,num3) return list(result)",MBPP_107 108,Write a python function to find the count of rotations of a binary string with odd value.,"def odd_Equivalent(s,n): count=0 for i in range(0,n): if (s[i] == '1'): count = count + 1 return count ",MBPP_108 109,Write a function to extract the ranges that are missing from the given list with the given start range and end range values.,"def extract_missing(test_list, strt_val, stop_val): res = [] for sub in test_list: if sub[0] > strt_val: res.append((strt_val, sub[0])) strt_val = sub[1] if strt_val < stop_val: res.append((strt_val, stop_val)) return (res) ",MBPP_109 110,Write a function to find common elements in given nested lists. * list item * list item * list item * list item,"def common_in_nested_lists(nestedlist): result = list(set.intersection(*map(set, nestedlist))) return result",MBPP_110 111,Write a python function to find the perimeter of a cylinder.,"def perimeter(diameter,height) : return 2*(diameter+height) ",MBPP_111 112,Write a function to check if a string represents an integer or not.,"def check_integer(text): text = text.strip() if len(text) < 1: return None else: if all(text[i] in ""0123456789"" for i in range(len(text))): return True elif (text[0] in ""+-"") and \ all(text[i] in ""0123456789"" for i in range(1,len(text))): return True else: return False",MBPP_112 113,Write a function to assign frequency to each tuple in the given tuple list.,"from collections import Counter def assign_freq(test_list): res = [(*key, val) for key, val in Counter(test_list).items()] return (str(res)) ",MBPP_113 114,Write a function to check whether all dictionaries in a list are empty or not.,"def empty_dit(list1): empty_dit=all(not d for d in list1) return empty_dit",MBPP_114 115,Write a function to convert a given tuple of positive integers into an integer.,"def tuple_to_int(nums): result = int(''.join(map(str,nums))) return result",MBPP_115 116,Write a function to convert all possible convertible elements in the list to float.,"def list_to_float(test_list): res = [] for tup in test_list: temp = [] for ele in tup: if ele.isalpha(): temp.append(ele) else: temp.append(float(ele)) res.append((temp[0],temp[1])) return (str(res)) ",MBPP_116 117,[link text](https:// [link text](https:// [link text](https://)))write a function to convert a string to a list.,"def string_to_list(string): lst = list(string.split("" "")) return lst",MBPP_117 118,Write a python function to find the element that appears only once in a sorted array.,"def search(arr,n) : XOR = 0 for i in range(n) : XOR = XOR ^ arr[i] return (XOR)",MBPP_118 119,Write a function to find the maximum product from the pairs of tuples within a given list.,"def max_product_tuple(list1): result_max = max([abs(x * y) for x, y in list1] ) return result_max",MBPP_119 120,Write a function to find the triplet with sum of the given array,"def check_triplet(A, n, sum, count): if count == 3 and sum == 0: return True if count == 3 or n == 0 or sum < 0: return False return check_triplet(A, n - 1, sum - A[n - 1], count + 1) or\ check_triplet(A, n - 1, sum, count)",MBPP_120 121,Write a function to find n’th smart number.,"MAX = 3000 def smartNumber(n): primes = [0] * MAX result = [] for i in range(2, MAX): if (primes[i] == 0): primes[i] = 1 j = i * 2 while (j < MAX): primes[j] -= 1 if ( (primes[j] + 3) == 0): result.append(j) j = j + i result.sort() return result[n - 1] ",MBPP_121 122,Write a function to sum all amicable numbers from 1 to a specified number.,"def amicable_numbers_sum(limit): if not isinstance(limit, int): return ""Input is not an integer!"" if limit < 1: return ""Input must be bigger than 0!"" amicables = set() for num in range(2, limit+1): if num in amicables: continue sum_fact = sum([fact for fact in range(1, num) if num % fact == 0]) sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0]) if num == sum_fact2 and num != sum_fact: amicables.add(num) amicables.add(sum_fact2) return sum(amicables)",MBPP_122 123,Write a function to get the angle of a complex number.,"import cmath def angle_complex(a,b): cn=complex(a,b) angle=cmath.phase(a+b) return angle",MBPP_123 124,Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string.,"def find_length(string, n): current_sum = 0 max_sum = 0 for i in range(n): current_sum += (1 if string[i] == '0' else -1) if current_sum < 0: current_sum = 0 max_sum = max(current_sum, max_sum) return max_sum if max_sum else 0",MBPP_124 125,Write a python function to find the sum of common divisors of two given numbers.,"def sum(a,b): sum = 0 for i in range (1,min(a,b)): if (a % i == 0 and b % i == 0): sum += i return sum",MBPP_125 126,Write a function to multiply two integers without using the * operator in python.,"def multiply_int(x, y): if y < 0: return -multiply_int(x, -y) elif y == 0: return 0 elif y == 1: return x else: return x + multiply_int(x, y - 1)",MBPP_126 127,Write a function to shortlist words that are longer than n from a given list of words.,"def long_words(n, str): word_len = [] txt = str.split("" "") for x in txt: if len(x) > n: word_len.append(x) return word_len ",MBPP_127 128,Write a function to calculate magic square.,"def magic_square_test(my_matrix): iSize = len(my_matrix[0]) sum_list = [] sum_list.extend([sum (lines) for lines in my_matrix]) for col in range(iSize): sum_list.append(sum(row[col] for row in my_matrix)) result1 = 0 for i in range(0,iSize): result1 +=my_matrix[i][i] sum_list.append(result1) result2 = 0 for i in range(iSize-1,-1,-1): result2 +=my_matrix[i][i] sum_list.append(result2) if len(set(sum_list))>1: return False return True",MBPP_128 129,Write a function to find the item with maximum frequency in a given list.,"from collections import defaultdict def max_occurrences(nums): dict = defaultdict(int) for i in nums: dict[i] += 1 result = max(dict.items(), key=lambda x: x[1]) return result",MBPP_129 130,Write a python function to reverse only the vowels of a given string.,"def reverse_vowels(str1): vowels = """" for char in str1: if char in ""aeiouAEIOU"": vowels += char result_string = """" for char in str1: if char in ""aeiouAEIOU"": result_string += vowels[-1] vowels = vowels[:-1] else: result_string += char return result_string",MBPP_130 131,Write a function to convert tuple to a string.,"def tup_string(tup1): str = ''.join(tup1) return str",MBPP_131 132,Write a function to calculate the sum of the negative numbers of a given list of numbers using lambda function.,"def sum_negativenum(nums): sum_negativenum = list(filter(lambda nums:nums<0,nums)) return sum(sum_negativenum)",MBPP_132 133,Write a python function to check whether the last element of given array is even or odd after performing an operation p times.,"def check_last (arr,n,p): _sum = 0 for i in range(n): _sum = _sum + arr[i] if p == 1: if _sum % 2 == 0: return ""ODD"" else: return ""EVEN"" return ""EVEN"" ",MBPP_133 134,Write a function to find the nth hexagonal number.,"def hexagonal_num(n): return n*(2*n - 1) ",MBPP_134 135,Write a function to calculate electricity bill.,"def cal_electbill(units): if(units < 50): amount = units * 2.60 surcharge = 25 elif(units <= 100): amount = 130 + ((units - 50) * 3.25) surcharge = 35 elif(units <= 200): amount = 130 + 162.50 + ((units - 100) * 5.26) surcharge = 45 else: amount = 130 + 162.50 + 526 + ((units - 200) * 8.45) surcharge = 75 total = amount + surcharge return total",MBPP_135 136,Write a function to find the ration of zeroes in an array of integers.,"from array import array def zero_count(nums): n = len(nums) n1 = 0 for x in nums: if x == 0: n1 += 1 else: None return round(n1/n,2)",MBPP_136 137,Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.,"def is_Sum_Of_Powers_Of_Two(n): if (n % 2 == 1): return False else: return True",MBPP_137 138,Write a function to find the circumference of a circle.,"def circle_circumference(r): perimeter=2*3.1415*r return perimeter",MBPP_138 139,Write a function to extract elements that occur singly in the given tuple list.,"def extract_singly(test_list): res = [] temp = set() for inner in test_list: for ele in inner: if not ele in temp: temp.add(ele) res.append(ele) return (res) ",MBPP_139 140,Write a function to sort a list of elements using pancake sort.,"def pancake_sort(nums): arr_len = len(nums) while arr_len > 1: mi = nums.index(max(nums[0:arr_len])) nums = nums[mi::-1] + nums[mi+1:len(nums)] nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)] arr_len -= 1 return nums",MBPP_140 141,Write a function to count the same pair in three given lists.,"def count_samepair(list1,list2,list3): result = sum(m == n == o for m, n, o in zip(list1,list2,list3)) return result",MBPP_141 142,Write a function to find number of lists present in the given tuple.,"def find_lists(Input): if isinstance(Input, list): return 1 else: return len(Input) ",MBPP_142 143,Write a python function to find the sum of absolute differences in all pairs of the given array.,"def sum_Pairs(arr,n): sum = 0 for i in range(n - 1,-1,-1): sum += i*arr[i] - (n-1-i) * arr[i] return sum",MBPP_143 144,Write a python function to find the maximum difference between any two elements in a given array.,"def max_Abs_Diff(arr,n): minEle = arr[0] maxEle = arr[0] for i in range(1, n): minEle = min(minEle,arr[i]) maxEle = max(maxEle,arr[i]) return (maxEle - minEle) ",MBPP_144 145,Write a function to find the ascii value of total characters in a string.,"def ascii_value_string(str1): for i in range(len(str1)): return ord(str1[i])",MBPP_145 146,Write a function to find the maximum total path sum in the given triangle.,"def max_path_sum(tri, m, n): for i in range(m-1, -1, -1): for j in range(i+1): if (tri[i+1][j] > tri[i+1][j+1]): tri[i][j] += tri[i+1][j] else: tri[i][j] += tri[i+1][j+1] return tri[0][0]",MBPP_146 147,Write a function to divide a number into two parts such that the sum of digits is maximum.,"def sum_digits_single(x) : ans = 0 while x : ans += x % 10 x //= 10 return ans def closest(x) : ans = 0 while (ans * 10 + 9 <= x) : ans = ans * 10 + 9 return ans def sum_digits_twoparts(N) : A = closest(N) return sum_digits_single(A) + sum_digits_single(N - A) ",MBPP_147 148,Write a function to find the longest subsequence such that the difference between adjacents is one for the given array.,"def longest_subseq_with_diff_one(arr, n): dp = [1 for i in range(n)] for i in range(n): for j in range(i): if ((arr[i] == arr[j]+1) or (arr[i] == arr[j]-1)): dp[i] = max(dp[i], dp[j]+1) result = 1 for i in range(n): if (result < dp[i]): result = dp[i] return result",MBPP_148 149,Write a python function to find whether the given number is present in the infinite sequence or not.,"def does_Contain_B(a,b,c): if (a == b): return True if ((b - a) * c > 0 and (b - a) % c == 0): return True return False",MBPP_149 150,Write a python function to check whether the given number is co-prime or not.,"def gcd(p,q): while q != 0: p, q = q,p%q return p def is_coprime(x,y): return gcd(x,y) == 1",MBPP_150 151,Write a function to sort the given array by using merge sort.,"def merge(a,b): c = [] while len(a) != 0 and len(b) != 0: if a[0] < b[0]: c.append(a[0]) a.remove(a[0]) else: c.append(b[0]) b.remove(b[0]) if len(a) == 0: c += b else: c += a return c def merge_sort(x): if len(x) == 0 or len(x) == 1: return x else: middle = len(x)//2 a = merge_sort(x[:middle]) b = merge_sort(x[middle:]) return merge(a,b) ",MBPP_151 152,Write a function to find the vertex of a parabola.,"def parabola_vertex(a, b, c): vertex=(((-b / (2 * a)),(((4 * a * c) - (b * b)) / (4 * a)))) return vertex",MBPP_152 153,Write a function to extract every specified element from a given two dimensional list.,"def specified_element(nums, N): result = [i[N] for i in nums] return result",MBPP_153 154,Write a python function to toggle all even bits of a given number.,"def even_bit_toggle_number(n) : res = 0; count = 0; temp = n while (temp > 0) : if (count % 2 == 1) : res = res | (1 << count) count = count + 1 temp >>= 1 return n ^ res ",MBPP_154 155,Write a function to convert a tuple of string values to a tuple of integer values.,"def tuple_int_str(tuple_str): result = tuple((int(x[0]), int(x[1])) for x in tuple_str) return result",MBPP_155 156,Write a function to reflect the run-length encoding from a list.,"from itertools import groupby def encode_list(list1): return [[len(list(group)), key] for key, group in groupby(list1)]",MBPP_156 157,Write a python function to find k number of operations required to make all elements equal.,"def min_Ops(arr,n,k): max1 = max(arr) res = 0 for i in range(0,n): if ((max1 - arr[i]) % k != 0): return -1 else: res += (max1 - arr[i]) / k return int(res) ",MBPP_157 158,Write a function to print the season for the given month and day.,"def month_season(month,days): if month in ('January', 'February', 'March'): season = 'winter' elif month in ('April', 'May', 'June'): season = 'spring' elif month in ('July', 'August', 'September'): season = 'summer' else: season = 'autumn' if (month == 'March') and (days > 19): season = 'spring' elif (month == 'June') and (days > 20): season = 'summer' elif (month == 'September') and (days > 21): season = 'autumn' elif (month == 'October') and (days > 21): season = 'autumn' elif (month == 'November') and (days > 21): season = 'autumn' elif (month == 'December') and (days > 20): season = 'winter' return season",MBPP_158 159,Write a function to find x and y that satisfies ax + by = n.,"def solution (a, b, n): i = 0 while i * a <= n: if (n - (i * a)) % b == 0: return (""x = "",i ,"", y = "", int((n - (i * a)) / b)) return 0 i = i + 1 return (""No solution"") ",MBPP_159 160,Write a function to remove all elements from a given list present in another list.,"def remove_elements(list1, list2): result = [x for x in list1 if x not in list2] return result",MBPP_160 161,Write a function to calculate the sum of the positive integers of n+(n-2)+(n-4)... (until n-x =< 0).,"def sum_series(n): if n < 1: return 0 else: return n + sum_series(n - 2)",MBPP_161 162,Write a function to calculate the area of a regular polygon.,"from math import tan, pi def area_polygon(s,l): area = s * (l ** 2) / (4 * tan(pi / s)) return area",MBPP_162 163,Write a python function to check whether the sum of divisors are same or not.,"import math def divSum(n): sum = 1; i = 2; while(i * i <= n): if (n % i == 0): sum = (sum + i +math.floor(n / i)); i += 1; return sum; def areEquivalent(num1,num2): return divSum(num1) == divSum(num2); ",MBPP_163 164,Write a python function to count characters at same position in a given string (lower and uppercase characters) as in english alphabet.,"def count_char_position(str1): count_chars = 0 for i in range(len(str1)): if ((i == ord(str1[i]) - ord('A')) or (i == ord(str1[i]) - ord('a'))): count_chars += 1 return count_chars ",MBPP_164 165,Write a python function to count the pairs with xor as an even number.,"def find_even_Pair(A,N): evenPair = 0 for i in range(0,N): for j in range(i+1,N): if ((A[i] ^ A[j]) % 2 == 0): evenPair+=1 return evenPair; ",MBPP_165 166,Write a python function to find smallest power of 2 greater than or equal to n.,"def next_Power_Of_2(n): count = 0; if (n and not(n & (n - 1))): return n while( n != 0): n >>= 1 count += 1 return 1 << count; ",MBPP_166 167,Write a python function to find the frequency of a number in a given array.,"def frequency(a,x): count = 0 for i in a: if i == x: count += 1 return count ",MBPP_167 168,Write a function to calculate the nth pell number.,"def get_pell(n): if (n <= 2): return n a = 1 b = 2 for i in range(3, n+1): c = 2 * b + a a = b b = c return b ",MBPP_168 169,Write a function to find sum of the numbers in a list between the indices of a specified range.,"def sum_range_list(list1, m, n): sum_range = 0 for i in range(m, n+1, 1): sum_range += list1[i] return sum_range ",MBPP_169 170,Write a function to find the perimeter of a pentagon.,"import math def perimeter_pentagon(a): perimeter=(5*a) return perimeter",MBPP_170 171,Write a function to find the occurence of characters 'std' in the given string 1. list item 1. list item 1. list item 2. list item 2. list item 2. list item,"def count_occurance(s): count=0 for i in range(len(s)): if (s[i]== 's' and s[i+1]=='t' and s[i+2]== 'd'): count = count + 1 return count",MBPP_171 172,Write a function to remove everything except alphanumeric characters from a string.,"import re def remove_splchar(text): pattern = re.compile('[\W_]+') return (pattern.sub('', text))",MBPP_172 173,Write a function to group a sequence of key-value pairs into a dictionary of lists.,"def group_keyvalue(l): result = {} for k, v in l: result.setdefault(k, []).append(v) return result",MBPP_173 174,Write a function to verify validity of a string of parentheses.,"def is_valid_parenthese( str1): stack, pchar = [], {""("": "")"", ""{"": ""}"", ""["": ""]""} for parenthese in str1: if parenthese in pchar: stack.append(parenthese) elif len(stack) == 0 or pchar[stack.pop()] != parenthese: return False return len(stack) == 0",MBPP_174 175,Write a function to find the perimeter of a triangle.,"def perimeter_triangle(a,b,c): perimeter=a+b+c return perimeter",MBPP_175 176,Write a python function to find two distinct numbers such that their lcm lies within the given range.,"def answer(L,R): if (2 * L <= R): return (L ,2*L) else: return (-1) ",MBPP_176 177,Write a function to search some literals strings in a string.,"import re def string_literals(patterns,text): for pattern in patterns: if re.search(pattern, text): return ('Matched!') else: return ('Not Matched!')",MBPP_177 178,Write a function to find if the given number is a keith number or not.,"def is_num_keith(x): terms = [] temp = x n = 0 while (temp > 0): terms.append(temp % 10) temp = int(temp / 10) n+=1 terms.reverse() next_term = 0 i = n while (next_term < x): next_term = 0 for j in range(1,n+1): next_term += terms[i - j] terms.append(next_term) i+=1 return (next_term == x) ",MBPP_178 179,Write a function to calculate distance between two points using latitude and longitude.,"from math import radians, sin, cos, acos def distance_lat_long(slat,slon,elat,elon): dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon)) return dist",MBPP_179 180,Write a function to find the longest common prefix in the given set of strings.,"def common_prefix_util(str1, str2): result = """"; n1 = len(str1) n2 = len(str2) i = 0 j = 0 while i <= n1 - 1 and j <= n2 - 1: if (str1[i] != str2[j]): break result += str1[i] i += 1 j += 1 return (result) def common_prefix (arr, n): prefix = arr[0] for i in range (1, n): prefix = common_prefix_util(prefix, arr[i]) return (prefix) ",MBPP_180 181,"Write a function to find uppercase, lowercase, special character and numeric values using regex.","import re def find_character(string): uppercase_characters = re.findall(r""[A-Z]"", string) lowercase_characters = re.findall(r""[a-z]"", string) numerical_characters = re.findall(r""[0-9]"", string) special_characters = re.findall(r""[, .!?]"", string) return uppercase_characters, lowercase_characters, numerical_characters, special_characters",MBPP_181 182,Write a function to count all the distinct pairs having a difference of k in any array.,"def count_pairs(arr, n, k): count=0; for i in range(0,n): for j in range(i+1, n): if arr[i] - arr[j] == k or arr[j] - arr[i] == k: count += 1 return count",MBPP_182 183,Write a function to find all the values in a list that are greater than a specified number.,"def greater_specificnum(list,num): greater_specificnum=all(x >= num for x in list) return greater_specificnum",MBPP_183 184,Write a function to find the focus of a parabola.,"def parabola_focus(a, b, c): focus= (((-b / (2 * a)),(((4 * a * c) - (b * b) + 1) / (4 * a)))) return focus",MBPP_184 185,Write a function to search some literals strings in a string by using regex.,"import re def check_literals(text, patterns): for pattern in patterns: if re.search(pattern, text): return ('Matched!') else: return ('Not Matched!')",MBPP_185 186,Write a function to find the longest common subsequence for the given two sequences.,"def longest_common_subsequence(X, Y, m, n): if m == 0 or n == 0: return 0 elif X[m-1] == Y[n-1]: return 1 + longest_common_subsequence(X, Y, m-1, n-1) else: return max(longest_common_subsequence(X, Y, m, n-1), longest_common_subsequence(X, Y, m-1, n))",MBPP_186 187,Write a python function to check whether the given number can be represented by product of two squares or not.,"def prod_Square(n): for i in range(2,(n) + 1): if (i*i < (n+1)): for j in range(2,n + 1): if ((i*i*j*j) == n): return True; return False;",MBPP_187 188,Write a python function to find the first missing positive number.,"def first_Missing_Positive(arr,n): ptr = 0 for i in range(n): if arr[i] == 1: ptr = 1 break if ptr == 0: return(1) for i in range(n): if arr[i] <= 0 or arr[i] > n: arr[i] = 1 for i in range(n): arr[(arr[i] - 1) % n] += n for i in range(n): if arr[i] <= n: return(i + 1) return(n + 1)",MBPP_188 189,Write a python function to count the number of integral co-ordinates that lie inside a square.,"def count_Intgral_Points(x1,y1,x2,y2): return ((y2 - y1 - 1) * (x2 - x1 - 1)) ",MBPP_189 190,Write a function to check whether the given month name contains 30 days or not.,"def check_monthnumber(monthname3): if monthname3 ==""April"" or monthname3== ""June"" or monthname3== ""September"" or monthname3== ""November"": return True else: return False",MBPP_190 191,Write a python function to check whether a string has atleast one letter and one number.,"def check_String(str): flag_l = False flag_n = False for i in str: if i.isalpha(): flag_l = True if i.isdigit(): flag_n = True return flag_l and flag_n ",MBPP_191 192,Write a function to remove the duplicates from the given tuple.,"def remove_tuple(test_tup): res = tuple(set(test_tup)) return (res) ",MBPP_192 193,Write a python function to convert octal number to decimal number.,"def octal_To_Decimal(n): num = n; dec_value = 0; base = 1; temp = num; while (temp): last_digit = temp % 10; temp = int(temp / 10); dec_value += last_digit*base; base = base * 8; return dec_value; ",MBPP_193 194,Write a python function to find the first position of an element in a sorted array.,"def first(arr,x,n): low = 0 high = n - 1 res = -1 while (low <= high): mid = (low + high) // 2 if arr[mid] > x: high = mid - 1 elif arr[mid] < x: low = mid + 1 else: res = mid high = mid - 1 return res",MBPP_194 195,Write a function to remove all the tuples with length k.,"def remove_tuples(test_list, K): res = [ele for ele in test_list if len(ele) != K] return (res) ",MBPP_195 196,Write a function to perform the exponentiation of the given two tuples.,"def find_exponentio(test_tup1, test_tup2): res = tuple(ele1 ** ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res) ",MBPP_196 197,Write a function to find the largest triangle that can be inscribed in an ellipse.,"import math def largest_triangle(a,b): if (a < 0 or b < 0): return -1 area = (3 * math.sqrt(3) * pow(a, 2)) / (4 * b); return area ",MBPP_197 198,Write a python function to find highest power of 2 less than or equal to given number.,"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; ",MBPP_198 199,Write a function to find all index positions of the maximum values in a given list.,"def position_max(list1): max_val = max(list1) max_result = [i for i, j in enumerate(list1) if j == max_val] return max_result",MBPP_199 200,Write a python function to check whether the elements in a list are same or not.,"def chkList(lst): return len(set(lst)) == 1",MBPP_200 201,Write a function to remove even characters in a string.,"def remove_even(str1): str2 = '' for i in range(1, len(str1) + 1): if(i % 2 != 0): str2 = str2 + str1[i - 1] return str2",MBPP_201 202,Write a python function to find the hamming distance between given two integers.,"def hamming_Distance(n1,n2) : x = n1 ^ n2 setBits = 0 while (x > 0) : setBits += x & 1 x >>= 1 return setBits ",MBPP_202 203,Write a python function to count the occurrence of a given character in a string.,"def count(s,c) : res = 0 for i in range(len(s)) : if (s[i] == c): res = res + 1 return res ",MBPP_203 204,Write a function to find the inversions of tuple elements in the given tuple list.,"def inversion_elements(test_tup): res = tuple(list(map(lambda x: ~x, list(test_tup)))) return (res) ",MBPP_204 205,Write a function to perform the adjacent element concatenation in the given tuples.,"def concatenate_elements(test_tup): res = tuple(i + j for i, j in zip(test_tup, test_tup[1:])) return (res) ",MBPP_205 206,Write a function to count the longest repeating subsequences such that the two subsequences don’t have same string characters at same positions.,"def find_longest_repeating_subseq(str): n = len(str) dp = [[0 for k in range(n+1)] for l in range(n+1)] for i in range(1, n+1): for j in range(1, n+1): if (str[i-1] == str[j-1] and i != j): dp[i][j] = 1 + dp[i-1][j-1] else: dp[i][j] = max(dp[i][j-1], dp[i-1][j]) return dp[n][n]",MBPP_206 207,Write a function to check the given decimal with a precision of 2 by using regex.,"import re def is_decimal(num): num_fetch = re.compile(r""""""^[0-9]+(\.[0-9]{1,2})?$"""""") result = num_fetch.search(num) return bool(result)",MBPP_207 208,Write a function to delete the smallest element from the given heap and then insert a new item.,"import heapq as hq def heap_replace(heap,a): hq.heapify(heap) hq.heapreplace(heap, a) return heap",MBPP_208 209,"Write a function to check that the given string contains only a certain set of characters(in this case a-z, a-z and 0-9) by using regex.","import re def is_allowed_specific_char(string): get_char = re.compile(r'[^a-zA-Z0-9.]') string = get_char.search(string) return not bool(string)",MBPP_209 210,Write a python function to count numbers whose oth and nth bits are set.,"def count_Num(n): if (n == 1): return 1 count = pow(2,n - 2) return count ",MBPP_210 211,Write a python function to find the sum of fourth power of n natural numbers.,"import math def fourth_Power_Sum(n): sum = 0 for i in range(1,n+1) : sum = sum + (i*i*i*i) return sum",MBPP_211 212,Write a function to perform the concatenation of two string tuples.,"def concatenate_strings(test_tup1, test_tup2): res = tuple(ele1 + ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res) ",MBPP_212 213,Write a function to convert radians to degrees.,"import math def degree_radian(radian): degree = radian*(180/math.pi) return degree",MBPP_213 214,Write a function to decode a run-length encoded given list.,"def decode_list(alist): def aux(g): if isinstance(g, list): return [(g[1], range(g[0]))] else: return [(g, [0])] return [x for g in alist for x, R in aux(g) for i in R]",MBPP_214 215,Write a function to check if a nested list is a subset of another nested list.,"def check_subset_list(list1, list2): l1, l2 = list1[0], list2[0] exist = True for i in list2: if i not in list1: exist = False return exist ",MBPP_215 216,Write a python function to find the first repeated character in a given string.,"def first_Repeated_Char(str): h = {} for ch in str: if ch in h: return ch; else: h[ch] = 0 return '\0'",MBPP_216 217,Write a python function to find the minimum operations required to make two numbers equal.,"import math def min_Operations(A,B): if (A > B): swap(A,B) B = B // math.gcd(A,B); return B - 1",MBPP_217 218,Write a function to extract maximum and minimum k elements in the given tuple.," def extract_min_max(test_tup, K): res = [] test_tup = list(test_tup) temp = sorted(test_tup) for idx, val in enumerate(temp): if idx < K or idx >= len(temp) - K: res.append(val) res = tuple(res) return (res) ",MBPP_218 219,"Write a function to replace maximum n occurrences of spaces, commas, or dots with a colon.","import re def replace_max_specialchar(text,n): return (re.sub(""[ ,.]"", "":"", text, n))",MBPP_219 220,Write a python function to find the first even number in a given list of numbers.,"def first_even(nums): first_even = next((el for el in nums if el%2==0),-1) return first_even",MBPP_220 221,Write a function to check if all the elements in tuple have same data type or not.,"def check_type(test_tuple): res = True for ele in test_tuple: if not isinstance(ele, type(test_tuple[0])): res = False break return (res) ",MBPP_221 222,Write a function to check for majority element in the given sorted array.,"def is_majority(arr, n, x): i = binary_search(arr, 0, n-1, x) if i == -1: return False if ((i + n//2) <= (n -1)) and arr[i + n//2] == x: return True else: return False def binary_search(arr, low, high, x): if high >= low: mid = (low + high)//2 if (mid == 0 or x > arr[mid-1]) and (arr[mid] == x): return mid elif x > arr[mid]: return binary_search(arr, (mid + 1), high, x) else: return binary_search(arr, low, (mid -1), x) return -1",MBPP_222 223,Write a python function to count set bits of a given number.,"def count_Set_Bits(n): count = 0 while (n): count += n & 1 n >>= 1 return count ",MBPP_223 224,Write a python function to find the minimum element in a sorted and rotated array.,"def find_Min(arr,low,high): while (low < high): mid = low + (high - low) // 2; if (arr[mid] == arr[high]): high -= 1; elif (arr[mid] > arr[high]): low = mid + 1; else: high = mid; return arr[high]; ",MBPP_224 225,Write a python function to remove the characters which have odd index values of a given string.,"def odd_values_string(str): result = """" for i in range(len(str)): if i % 2 == 0: result = result + str[i] return result",MBPP_225 226,Write a function to find minimum of three numbers.,"def min_of_three(a,b,c): if (a <= b) and (a <= c): smallest = a elif (b <= a) and (b <= c): smallest = b else: smallest = c return smallest ",MBPP_226 227,Write a python function to check whether all the bits are unset in the given range or not.,"def all_Bits_Set_In_The_Given_Range(n,l,r): num = (((1 << r) - 1) ^ ((1 << (l - 1)) - 1)) new_num = n & num if (new_num == 0): return True return False",MBPP_227 228,Write a function to re-arrange the elements of the given array so that all negative elements appear before positive ones.,"def re_arrange_array(arr, n): j=0 for i in range(0, n): if (arr[i] < 0): temp = arr[i] arr[i] = arr[j] arr[j] = temp j = j + 1 return arr",MBPP_228 229,Write a function to replace blank spaces with any character in a string.,"def replace_blank(str1,char): str2 = str1.replace(' ', char) return str2",MBPP_229 230,Write a function to find the maximum sum in the given right triangle of numbers.,"def max_sum(tri, n): if n > 1: tri[1][1] = tri[1][1]+tri[0][0] tri[1][0] = tri[1][0]+tri[0][0] for i in range(2, n): tri[i][0] = tri[i][0] + tri[i-1][0] tri[i][i] = tri[i][i] + tri[i-1][i-1] for j in range(1, i): if tri[i][j]+tri[i-1][j-1] >= tri[i][j]+tri[i-1][j]: tri[i][j] = tri[i][j] + tri[i-1][j-1] else: tri[i][j] = tri[i][j]+tri[i-1][j] return (max(tri[n-1]))",MBPP_230 231,Write a function to get the n largest items from a dataset.,"import heapq def larg_nnum(list1,n): largest=heapq.nlargest(n,list1) return largest",MBPP_231 232,Write a function to find the lateral surface area of a cylinder.,"def lateralsuface_cylinder(r,h): lateralsurface= 2*3.1415*r*h return lateralsurface",MBPP_232 233,Write a function to find the volume of a cube.,"def volume_cube(l): volume = l * l * l return volume",MBPP_233 234,Write a python function to set all even bits of a given number.,"def even_bit_set_number(n): count = 0;res = 0;temp = n while(temp > 0): if (count % 2 == 1): res |= (1 << count) count+=1 temp >>= 1 return (n | res) ",MBPP_234 235,Write a python function to count the maximum number of equilateral triangles that can be formed within a given equilateral triangle.,"def No_of_Triangle(N,K): if (N < K): return -1; else: Tri_up = 0; Tri_up = ((N - K + 1) *(N - K + 2)) // 2; Tri_down = 0; Tri_down = ((N - 2 * K + 1) *(N - 2 * K + 2)) // 2; return Tri_up + Tri_down;",MBPP_235 236,Write a function to check the occurrences of records which occur similar times in the given tuples.,"from collections import Counter def check_occurences(test_list): res = dict(Counter(tuple(ele) for ele in map(sorted, test_list))) return (res) ",MBPP_236 237,Write a python function to count number of non-empty substrings of a given string.,"def number_of_substrings(str): str_len = len(str); return int(str_len * (str_len + 1) / 2); ",MBPP_237 238,Write a function to find the number of possible sequences of length n such that each of the next element is greater than or equal to twice of the previous element but less than or equal to m.,"def get_total_number_of_sequences(m,n): T=[[0 for i in range(n+1)] for i in range(m+1)] for i in range(m+1): for j in range(n+1): if i==0 or j==0: T[i][j]=0 elif i arr[j] and MSIBS[i] < MSIBS[j] + arr[i]: MSIBS[i] = MSIBS[j] + arr[i] MSDBS = arr[:] for i in range(1, n + 1): for j in range(1, i): if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]: MSDBS[-i] = MSDBS[-j] + arr[-i] max_sum = float(""-Inf"") for i, j, k in zip(MSIBS, MSDBS, arr): max_sum = max(max_sum, i + j - k) return max_sum",MBPP_244 245,Write a function for computing square roots using the babylonian method.,"def babylonian_squareroot(number): if(number == 0): return 0; g = number/2.0; g2 = g + 1; while(g != g2): n = number/ g; g2 = g; g = (g + n)/2; return g;",MBPP_245 246,Write a function to find the longest palindromic subsequence in the given string.,"def lps(str): n = len(str) L = [[0 for x in range(n)] for x in range(n)] for i in range(n): L[i][i] = 1 for cl in range(2, n+1): for i in range(n-cl+1): j = i+cl-1 if str[i] == str[j] and cl == 2: L[i][j] = 2 elif str[i] == str[j]: L[i][j] = L[i+1][j-1] + 2 else: L[i][j] = max(L[i][j-1], L[i+1][j]); return L[0][n-1]",MBPP_246 247,Write a function to calculate the harmonic sum of n-1.,"def harmonic_sum(n): if n < 2: return 1 else: return 1 / n + (harmonic_sum(n - 1)) ",MBPP_247 248,Write a function to find the intersection of two arrays using lambda function.,"def intersection_array(array_nums1,array_nums2): result = list(filter(lambda x: x in array_nums1, array_nums2)) return result",MBPP_248 249,Write a python function to count the occcurences of an element in a tuple.,"def count_X(tup, x): count = 0 for ele in tup: if (ele == x): count = count + 1 return count ",MBPP_249 250,Write a function to insert an element before each element of a list.,"def insert_element(list,element): list = [v for elt in list for v in (element, elt)] return list",MBPP_250 251,Write a python function to convert complex numbers to polar coordinates.,"import cmath def convert(numbers): num = cmath.polar(numbers) return (num) ",MBPP_251 252,Write a python function to count integers from a given list.,"def count_integer(list1): ctr = 0 for i in list1: if isinstance(i, int): ctr = ctr + 1 return ctr",MBPP_252 253,Write a function to find all words starting with 'a' or 'e' in a given string.,"import re def words_ae(text): list = re.findall(""[ae]\w+"", text) return list",MBPP_253 254,Write a function to choose specified number of colours from three different colours and generate all the combinations with repetitions.,"from itertools import combinations_with_replacement def combinations_colors(l, n): return list(combinations_with_replacement(l,n)) ",MBPP_254 255,Write a python function to count the number of prime numbers less than a given non-negative number.,"def count_Primes_nums(n): ctr = 0 for num in range(n): if num <= 1: continue for i in range(2,num): if (num % i) == 0: break else: ctr += 1 return ctr",MBPP_255 256,Write a function to swap two numbers.,"def swap_numbers(a,b): temp = a a = b b = temp return (a,b)",MBPP_256 257,Write a function to find number of odd elements in the given list using lambda function.,"def count_odd(array_nums): count_odd = len(list(filter(lambda x: (x%2 != 0) , array_nums))) return count_odd",MBPP_257 258,Write a function to maximize the given two tuples.,"def maximize_elements(test_tup1, test_tup2): res = tuple(tuple(max(a, b) for a, b in zip(tup1, tup2)) for tup1, tup2 in zip(test_tup1, test_tup2)) return (res) ",MBPP_258 259,Write a function to find the nth newman–shanks–williams prime number.,"def newman_prime(n): if n == 0 or n == 1: return 1 return 2 * newman_prime(n - 1) + newman_prime(n - 2)",MBPP_259 260,Write a function to perform mathematical division operation across the given tuples.,"def division_elements(test_tup1, test_tup2): res = tuple(ele1 // ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res) ",MBPP_260 261,Write a function to split a given list into two parts where the length of the first part of the list is given.,"def split_two_parts(list1, L): return list1[:L], list1[L:]",MBPP_261 262,Write a function to merge two dictionaries.,"def merge_dict(d1,d2): d = d1.copy() d.update(d2) return d",MBPP_262 263,Write a function to calculate a dog's age in dog's years.,"def dog_age(h_age): if h_age < 0: exit() elif h_age <= 2: d_age = h_age * 10.5 else: d_age = 21 + (h_age - 2)*4 return d_age",MBPP_263 264,Write a function to split a list for every nth element.,"def list_split(S, step): return [S[i::step] for i in range(step)]",MBPP_264 265,Write a function to find the lateral surface area of a cube.,"def lateralsurface_cube(l): LSA = 4 * (l * l) return LSA",MBPP_265 266,Write a python function to find the sum of squares of first n odd natural numbers.,"def square_Sum(n): return int(n*(4*n*n-1)/3) ",MBPP_266 267,Write a function to find the n'th star number.,"def find_star_num(n): return (6 * n * (n - 1) + 1) ",MBPP_267 268,Write a function to find the ascii value of a character.,"def ascii_value(k): ch=k return ord(ch)",MBPP_268 269,Write a python function to find the sum of even numbers at even positions.,"def sum_even_and_even_index(arr,n): i = 0 sum = 0 for i in range(0,n,2): if (arr[i] % 2 == 0) : sum += arr[i] return sum",MBPP_269 270,Write a python function to find the sum of fifth power of first n even natural numbers.,"def even_Power_Sum(n): sum = 0; for i in range(1,n+1): j = 2*i; sum = sum + (j*j*j*j*j); return sum; ",MBPP_270 271,Write a function to perfom the rear element extraction from list of tuples records.,"def rear_extract(test_list): res = [lis[-1] for lis in test_list] return (res) ",MBPP_271 272,Write a function to substract the contents of one tuple with corresponding index of other tuple.,"def substract_elements(test_tup1, test_tup2): res = tuple(map(lambda i, j: i - j, test_tup1, test_tup2)) return (res) ",MBPP_272 273,Write a python function to find sum of even index binomial coefficients.,"import math def even_binomial_Coeff_Sum( n): return (1 << (n - 1)) ",MBPP_273 274,Write a python function to find the position of the last removed element from the given array.,"import math as mt def get_Position(a,n,m): for i in range(n): a[i] = (a[i] // m + (a[i] % m != 0)) result,maxx = -1,-1 for i in range(n - 1,-1,-1): if (maxx < a[i]): maxx = a[i] result = i return result + 1",MBPP_274 275,Write a function to find the volume of a cylinder.,"def volume_cylinder(r,h): volume=3.1415*r*r*h return volume",MBPP_275 276,Write a function to filter a dictionary based on values.,"def dict_filter(dict,n): result = {key:value for (key, value) in dict.items() if value >=n} return result",MBPP_276 277,Write a function to find the element count that occurs before the record in the given tuple.,"def count_first_elements(test_tup): for count, ele in enumerate(test_tup): if isinstance(ele, tuple): break return (count) ",MBPP_277 278,Write a function to find the nth decagonal number.,"def is_num_decagonal(n): return 4 * n * n - 3 * n ",MBPP_278 279,Write a function to search an element in the given array by using sequential search.,"def sequential_search(dlist, item): pos = 0 found = False while pos < len(dlist) and not found: if dlist[pos] == item: found = True else: pos = pos + 1 return found, pos",MBPP_279 280,Write a python function to check if the elements of a given list are unique or not.,"def all_unique(test_list): if len(test_list) > len(set(test_list)): return False return True",MBPP_280 281,Write a function to substaract two lists using map and lambda function.,"def sub_list(nums1,nums2): result = map(lambda x, y: x - y, nums1, nums2) return list(result)",MBPP_281 282,Write a python function to check whether the frequency of each digit is less than or equal to the digit itself.,"def validate(n): for i in range(10): temp = n; count = 0; while (temp): if (temp % 10 == i): count+=1; if (count > i): return False temp //= 10; return True",MBPP_282 283,Write a function to check whether all items of a list are equal to a given string.,"def check_element(list,element): check_element=all(v== element for v in list) return check_element",MBPP_283 284,Write a function that matches a string that has an a followed by two to three 'b'.,"import re def text_match_two_three(text): patterns = 'ab{2,3}' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')",MBPP_284 285,Write a function to find the largest sum of contiguous array in the modified array which is formed by repeating the given array k times.,"def max_sub_array_sum_repeated(a, n, k): max_so_far = -2147483648 max_ending_here = 0 for i in range(n*k): max_ending_here = max_ending_here + a[i%n] if (max_so_far < max_ending_here): max_so_far = max_ending_here if (max_ending_here < 0): max_ending_here = 0 return max_so_far",MBPP_285 286,Write a python function to find the sum of squares of first n even natural numbers.,"def square_Sum(n): return int(2*n*(n+1)*(2*n+1)/3)",MBPP_286 287,Write a function to count array elements having modular inverse under given prime number p equal to itself.,"def modular_inverse(arr, N, P): current_element = 0 for i in range(0, N): if ((arr[i] * arr[i]) % P == 1): current_element = current_element + 1 return current_element",MBPP_287 288,Write a python function to calculate the number of odd days in a given year.,"def odd_Days(N): hund1 = N // 100 hund4 = N // 400 leap = N >> 2 ordd = N - leap if (hund1): ordd += hund1 leap -= hund1 if (hund4): ordd -= hund4 leap += hund4 days = ordd + leap * 2 odd = days % 7 return odd ",MBPP_288 289,Write a function to find the list of lists with maximum length.,"def max_length(list1): max_length = max(len(x) for x in list1 ) max_list = max((x) for x in list1) return(max_length, max_list)",MBPP_289 290,Write a function to find out the number of ways of painting the fence such that at most 2 adjacent posts have the same color for the given fence with n posts and k colors.,"def count_no_of_ways(n, k): dp = [0] * (n + 1) total = k mod = 1000000007 dp[1] = k dp[2] = k * k for i in range(3,n+1): dp[i] = ((k - 1) * (dp[i - 1] + dp[i - 2])) % mod return dp[n]",MBPP_290 291,Write a python function to find quotient of two numbers.,"def find(n,m): q = n//m return (q)",MBPP_291 292,Write a function to find the third side of a right angled triangle.,"import math def otherside_rightangle(w,h): s=math.sqrt((w*w)+(h*h)) return s",MBPP_292 293,Write a function to find the maximum value in a given heterogeneous list.,"def max_val(listval): max_val = max(i for i in listval if isinstance(i, int)) return(max_val)",MBPP_293 294,Write a function to return the sum of all divisors of a number.,"def sum_div(number): divisors = [1] for i in range(2, number): if (number % i)==0: divisors.append(i) return sum(divisors)",MBPP_294 295,Write a python function to count inversions in an array.,"def get_Inv_Count(arr,n): inv_count = 0 for i in range(n): for j in range(i + 1,n): if (arr[i] > arr[j]): inv_count += 1 return inv_count ",MBPP_295 296,Write a function to flatten a given nested list structure.,"def flatten_list(list1): result_list = [] if not list1: return result_list stack = [list(list1)] while stack: c_num = stack.pop() next = c_num.pop() if c_num: stack.append(c_num) if isinstance(next, list): if next: stack.append(list(next)) else: result_list.append(next) result_list.reverse() return result_list ",MBPP_296 297,Write a function to find the nested list elements which are present in another list.,"def intersection_nested_lists(l1, l2): result = [[n for n in lst if n in l1] for lst in l2] return result",MBPP_297 298,Write a function to calculate the maximum aggregate from the list of tuples.,"from collections import defaultdict def max_aggregate(stdata): temp = defaultdict(int) for name, marks in stdata: temp[name] += marks return max(temp.items(), key=lambda x: x[1])",MBPP_298 299,Write a function to find the count of all binary sequences of length 2n such that sum of first n bits is same as sum of last n bits.,"def count_binary_seq(n): nCr = 1 res = 1 for r in range(1, n + 1): nCr = (nCr * (n + 1 - r)) / r res += nCr * nCr return res ",MBPP_299 300,Write a function to find the depth of a dictionary.,"def dict_depth(d): if isinstance(d, dict): return 1 + (max(map(dict_depth, d.values())) if d else 0) return 0",MBPP_300 301,Write a python function to find the most significant bit number which is also a set bit.,"def set_Bit_Number(n): if (n == 0): return 0; msb = 0; n = int(n / 2); while (n > 0): n = int(n / 2); msb += 1; return (1 << msb)",MBPP_301 302,Write a python function to check whether the count of inversion of two types are same or not.,"import sys def solve(a,n): mx = -sys.maxsize - 1 for j in range(1,n): if (mx > a[j]): return False mx = max(mx,a[j - 1]) return True",MBPP_302 303,Write a python function to find element at a given index after number of rotations.,"def find_Element(arr,ranges,rotations,index) : for i in range(rotations - 1,-1,-1 ) : left = ranges[i][0] right = ranges[i][1] if (left <= index and right >= index) : if (index == left) : index = right else : index = index - 1 return arr[index] ",MBPP_303 304,Write a function to match two words from a list of words starting with letter 'p'.,"import re def start_withp(words): for w in words: m = re.match(""(P\w+)\W(P\w+)"", w) if m: return m.groups()",MBPP_304 305,"Write a function to find the maximum sum of increasing subsequence from prefix till ith index and also including a given kth element which is after i, i.e., k > i .","def max_sum_increasing_subseq(a, n, index, k): dp = [[0 for i in range(n)] for i in range(n)] for i in range(n): if a[i] > a[0]: dp[0][i] = a[i] + a[0] else: dp[0][i] = a[i] for i in range(1, n): for j in range(n): if a[j] > a[i] and j > i: if dp[i - 1][i] + a[j] > dp[i - 1][j]: dp[i][j] = dp[i - 1][i] + a[j] else: dp[i][j] = dp[i - 1][j] else: dp[i][j] = dp[i - 1][j] return dp[index][k]",MBPP_305 306,Write a function to get a colon of a tuple.,"from copy import deepcopy def colon_tuplex(tuplex,m,n): tuplex_colon = deepcopy(tuplex) tuplex_colon[m].append(n) return tuplex_colon",MBPP_306 307,Write a function to find the specified number of largest products from two given lists.,"def large_product(nums1, nums2, N): result = sorted([x*y for x in nums1 for y in nums2], reverse=True)[:N] return result",MBPP_307 308,Write a python function to find the maximum of two numbers.,"def maximum(a,b): if a >= b: return a else: return b ",MBPP_308 309,Write a function to convert a given string to a tuple.,"def string_to_tuple(str1): result = tuple(x for x in str1 if not x.isspace()) return result",MBPP_309 310,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))) ",MBPP_310 311,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",MBPP_311 312,Write a python function to print positive numbers in a list.,"def pos_nos(list1): for num in list1: if num >= 0: return num ",MBPP_312 313,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)",MBPP_313 314,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] ",MBPP_314 315,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 ",MBPP_315 316,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)]",MBPP_316 317,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 ",MBPP_317 318,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))",MBPP_318 319,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",MBPP_319 320,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 ",MBPP_320 321,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",MBPP_321 322,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",MBPP_322 323,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)) ",MBPP_323 324,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;",MBPP_324 325,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)) ",MBPP_325 326,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",MBPP_326 327,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",MBPP_327 328,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 ",MBPP_328 329,"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))",MBPP_329 330,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 ",MBPP_330 331,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",MBPP_331 332,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 ",MBPP_332 333,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 ",MBPP_333 334,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",MBPP_334 335,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",MBPP_335 336,"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!'",MBPP_336 337,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; ",MBPP_337 338,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",MBPP_338 339,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])",MBPP_339 340,Write a function to convert the given set into ordered tuples.,"def set_to_tuple(s): t = tuple(sorted(s)) return (t)",MBPP_340 341,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])",MBPP_341 342,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)",MBPP_342 343,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) ",MBPP_343 344,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",MBPP_344 345,"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)",MBPP_345 346,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",MBPP_346 347,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) ",MBPP_347 348,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"") ",MBPP_348 349,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 ",MBPP_349 350,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",MBPP_350 351,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;",MBPP_351 352,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",MBPP_352 353,Write a function to find t-nth term of arithemetic progression.,"def tn_ap(a,n,d): tn = a + (n - 1) * d return tn",MBPP_353 354,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 ",MBPP_354 355,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 ",MBPP_355 356,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) ",MBPP_356 357,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)",MBPP_357 358,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""); ",MBPP_358 359,Write a function to find the n’th carol number.,"def get_carol(n): result = (2**n) - 1 return result * result - 2",MBPP_359 360,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",MBPP_360 361,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",MBPP_361 362,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) ",MBPP_362 363,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')) ",MBPP_363 364,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",MBPP_364 365,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:]))",MBPP_365 366,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",MBPP_366 367,Write a function to repeat the given tuple n times.,"def repeat_tuples(test_tup, N): res = ((test_tup, ) * N) return (res) ",MBPP_367 368,Write a function to find the lateral surface area of cuboid,"def lateralsurface_cuboid(l,w,h): LSA = 2*h*(l+w) return LSA",MBPP_368 369,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",MBPP_369 370,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)",MBPP_370 371,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",MBPP_371 372,Write a function to find the volume of a cuboid.,"def volume_cuboid(l,w,h): volume=l*w*h return volume",MBPP_372 373,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",MBPP_373 374,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)",MBPP_374 375,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)",MBPP_375 376,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) ",MBPP_376 377,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",MBPP_377 378,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",MBPP_378 379,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 ",MBPP_379 380,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",MBPP_380 381,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",MBPP_381 382,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 ",MBPP_382 383,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 ",MBPP_383 384,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)",MBPP_384 385,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",MBPP_385 386,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"") ",MBPP_386 387,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; ",MBPP_387 388,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) ",MBPP_388 389,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",MBPP_389 390,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",MBPP_390 391,"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 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",MBPP_396 397,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())",MBPP_397 398,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) ",MBPP_398 399,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)",MBPP_399 400,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) ",MBPP_400 401,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] ",MBPP_401 402,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",MBPP_402 403,Write a python function to find the minimum of two numbers.,"def minimum(a,b): if a <= b: return a else: return b ",MBPP_403 404,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",MBPP_404 405,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""); ",MBPP_405 406,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",MBPP_406 407,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",MBPP_407 408,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",MBPP_408 409,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",MBPP_409 410,Write a function to convert the given snake case string to camel case string by using regex.,"import re def snake_to_camel(word): return ''.join(x.capitalize() or '_' for x in word.split('_'))",MBPP_410 411,Write a python function to remove odd numbers from a given list.,"def remove_odd(l): for i in l: if i % 2 != 0: l.remove(i) return l",MBPP_411 412,Write a function to extract the nth element from a given list of tuples.,"def extract_nth_element(list1, n): result = [x[n] for x in list1] return result",MBPP_412 413,Write a python function to check whether the value exists in a sequence or not.,"def overlapping(list1,list2): c=0 d=0 for i in list1: c+=1 for i in list2: d+=1 for i in range(0,c): for j in range(0,d): if(list1[i]==list2[j]): return 1 return 0",MBPP_413 414,Write a python function to find a pair with highest product from a given array of integers.,"def max_Product(arr): arr_len = len(arr) if (arr_len < 2): return (""No pairs exists"") x = arr[0]; y = arr[1] for i in range(0,arr_len): for j in range(i + 1,arr_len): if (arr[i] * arr[j] > x * y): x = arr[i]; y = arr[j] return x,y ",MBPP_414 415,Write a function to find the maximum sum we can make by dividing number in three parts recursively and summing them up together for the given number.,"MAX = 1000000 def breakSum(n): dp = [0]*(n+1) dp[0] = 0 dp[1] = 1 for i in range(2, n+1): dp[i] = max(dp[int(i/2)] + dp[int(i/3)] + dp[int(i/4)], i); return dp[n]",MBPP_415 416,Write a function to find common first element in given list of tuple.,"def group_tuples(Input): out = {} for elem in Input: try: out[elem[0]].extend(elem[1:]) except KeyError: out[elem[0]] = list(elem) return [tuple(values) for values in out.values()] ",MBPP_416 417,Write a python function to find the sublist having maximum length.,"def Find_Max(lst): maxList = max((x) for x in lst) return maxList",MBPP_417 418,Write a function to round every number of a given list of numbers and print the total sum multiplied by the length of the list.,"def round_and_sum(list1): lenght=len(list1) round_and_sum=sum(list(map(round,list1))* lenght) return round_and_sum",MBPP_418 419,Write a python function to find the cube sum of first n even natural numbers.,"def cube_Sum(n): sum = 0 for i in range(1,n + 1): sum += (2*i)*(2*i)*(2*i) return sum",MBPP_419 420,Write a function to concatenate each element of tuple by the delimiter.,"def concatenate_tuple(test_tup): delim = ""-"" res = ''.join([str(ele) + delim for ele in test_tup]) res = res[ : len(res) - len(delim)] return (str(res)) ",MBPP_420 421,Write a python function to find the average of cubes of first n natural numbers.,"def find_Average_Of_Cube(n): sum = 0 for i in range(1, n + 1): sum += i * i * i return round(sum / n, 6) ",MBPP_421 422,Write a function to solve gold mine problem.,"def get_maxgold(gold, m, n): goldTable = [[0 for i in range(n)] for j in range(m)] for col in range(n-1, -1, -1): for row in range(m): if (col == n-1): right = 0 else: right = goldTable[row][col+1] if (row == 0 or col == n-1): right_up = 0 else: right_up = goldTable[row-1][col+1] if (row == m-1 or col == n-1): right_down = 0 else: right_down = goldTable[row+1][col+1] goldTable[row][col] = gold[row][col] + max(right, right_up, right_down) res = goldTable[0][0] for i in range(1, m): res = max(res, goldTable[i][0]) return res ",MBPP_422 423,Write a function to extract only the rear index element of each string in the given tuple.,"def extract_rear(test_tuple): res = list(sub[len(sub) - 1] for sub in test_tuple) return (res) ",MBPP_423 424,Write a function to count the number of sublists containing a particular element.,"def count_element_in_list(list1, x): ctr = 0 for i in range(len(list1)): if x in list1[i]: ctr+= 1 return ctr",MBPP_424 425,Write a function to filter odd numbers using lambda function.,"def filter_oddnumbers(nums): odd_nums = list(filter(lambda x: x%2 != 0, nums)) return odd_nums",MBPP_425 426,Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format by using regex.,"import re def change_date_format(dt): return re.sub(r'(\d{4})-(\d{1,2})-(\d{1,2})', '\\3-\\2-\\1', dt)",MBPP_426 427,Write a function to sort the given array by using shell sort.,"def shell_sort(my_list): gap = len(my_list) // 2 while gap > 0: for i in range(gap, len(my_list)): current_item = my_list[i] j = i while j >= gap and my_list[j - gap] > current_item: my_list[j] = my_list[j - gap] j -= gap my_list[j] = current_item gap //= 2 return my_list",MBPP_427 428,Write a function to extract the elementwise and tuples from the given two tuples.,"def and_tuples(test_tup1, test_tup2): res = tuple(ele1 & ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res) ",MBPP_428 429,Write a function to find the directrix of a parabola.,"def parabola_directrix(a, b, c): directrix=((int)(c - ((b * b) + 1) * 4 * a )) return directrix",MBPP_429 430,Write a function that takes two lists and returns true if they have at least one common element.,"def common_element(list1, list2): result = False for x in list1: for y in list2: if x == y: result = True return result",MBPP_430 431,Write a function to find the median of a trapezium.,"def median_trapezium(base1,base2,height): median = 0.5 * (base1+ base2) return median",MBPP_431 432,Write a function to check whether the entered number is greater than the elements of the given array.,"def check_greater(arr, number): arr.sort() if number > arr[-1]: return ('Yes, the entered number is greater than those in the array') else: return ('No, entered number is less than those in the array')",MBPP_432 433,Write a function that matches a string that has an a followed by one or more b's.,"import re def text_match_one(text): patterns = 'ab+?' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!') ",MBPP_433 434,Write a python function to find the last digit of a given number.,"def last_Digit(n) : return (n % 10) ",MBPP_434 435,Write a python function to print negative numbers in a list.,"def neg_nos(list1): for num in list1: if num < 0: return num ",MBPP_435 436,Write a function to remove odd characters in a string.,"def remove_odd(str1): str2 = '' for i in range(1, len(str1) + 1): if(i % 2 == 0): str2 = str2 + str1[i - 1] return str2",MBPP_436 437,Write a function to count bidirectional tuple pairs.,"def count_bidirectional(test_list): res = 0 for idx in range(0, len(test_list)): for iidx in range(idx + 1, len(test_list)): if test_list[iidx][0] == test_list[idx][1] and test_list[idx][1] == test_list[iidx][0]: res += 1 return (str(res)) ",MBPP_437 438,Write a function to convert a list of multiple integers into a single integer.,"def multiple_to_single(L): x = int("""".join(map(str, L))) return x",MBPP_438 439,Write a function to find all adverbs and their positions in a given sentence.,"import re def find_adverb_position(text): for m in re.finditer(r""\w+ly"", text): return (m.start(), m.end(), m.group(0))",MBPP_439 440,Write a function to find the surface area of a cube.,"def surfacearea_cube(l): surfacearea= 6*l*l return surfacearea",MBPP_440 441,Write a function to find the ration of positive numbers in an array of integers.,"from array import array def positive_count(nums): n = len(nums) n1 = 0 for x in nums: if x > 0: n1 += 1 else: None return round(n1/n,2)",MBPP_441 442,Write a python function to find the largest negative number from the given list.,"def largest_neg(list1): max = list1[0] for x in list1: if x < max : max = x return max",MBPP_442 443,Write a function to trim each tuple by k in the given tuple list.,"def trim_tuple(test_list, K): res = [] for ele in test_list: N = len(ele) res.append(tuple(list(ele)[K: N - K])) return (str(res)) ",MBPP_443 444,Write a function to perform index wise multiplication of tuple elements in the given two tuples.,"def index_multiplication(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) ",MBPP_444 445,Write a python function to count the occurence of all elements of list in a tuple.,"from collections import Counter def count_Occurrence(tup, lst): count = 0 for item in tup: if item in lst: count+= 1 return count ",MBPP_445 446,Write a function to find cubes of individual elements in a list using lambda function.,"def cube_nums(nums): cube_nums = list(map(lambda x: x ** 3, nums)) return cube_nums",MBPP_446 447,Write a function to calculate the sum of perrin numbers.,"def cal_sum(n): a = 3 b = 0 c = 2 if (n == 0): return 3 if (n == 1): return 3 if (n == 2): return 5 sum = 5 while (n > 2): d = a + b sum = sum + d a = b b = c c = d n = n-1 return sum",MBPP_447 448,Write a python function to check whether the triangle is valid or not if 3 points are given.,"def check_Triangle(x1,y1,x2,y2,x3,y3): a = (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)) if a == 0: return ('No') else: return ('Yes') ",MBPP_448 449,Write a function to extract specified size of strings from a give list of string values.,"def extract_string(str, l): result = [e for e in str if len(e) == l] return result",MBPP_449 450,Write a function to remove all whitespaces from the given string using regex.,"import re def remove_whitespaces(text1): return (re.sub(r'\s+', '',text1))",MBPP_450 451,Write a function that gives loss amount if the given amount has loss else return none.,"def loss_amount(actual_cost,sale_amount): if(sale_amount > actual_cost): amount = sale_amount - actual_cost return amount else: return None",MBPP_451 452,Write a python function to find the sum of even factors of a number.,"import math def sumofFactors(n) : if (n % 2 != 0) : return 0 res = 1 for i in range(2, (int)(math.sqrt(n)) + 1) : count = 0 curr_sum = 1 curr_term = 1 while (n % i == 0) : count= count + 1 n = n // i if (i == 2 and count == 1) : curr_sum = 0 curr_term = curr_term * i curr_sum = curr_sum + curr_term res = res * curr_sum if (n >= 2) : res = res * (1 + n) return res ",MBPP_452 453,Write a function that matches a word containing 'z'.,"import re def text_match_wordz(text): patterns = '\w*z.\w*' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')",MBPP_453 454,Write a function to check whether the given month number contains 31 days or not.,"def check_monthnumb_number(monthnum2): if(monthnum2==1 or monthnum2==3 or monthnum2==5 or monthnum2==7 or monthnum2==8 or monthnum2==10 or monthnum2==12): return True else: return False",MBPP_454 455,Write a function to reverse strings in a given list of string values.,"def reverse_string_list(stringlist): result = [x[::-1] for x in stringlist] return result",MBPP_455 456,Write a python function to find the sublist having minimum length.,"def Find_Min(lst): minList = min((x) for x in lst) return minList",MBPP_456 457,Write a function to find the area of a rectangle.,"def rectangle_area(l,b): area=l*b return area",MBPP_457 458,Write a function to remove uppercase substrings from a given string by using regex.,"import re def remove_uppercase(str1): remove_upper = lambda text: re.sub('[A-Z]', '', text) result = remove_upper(str1) return (result)",MBPP_458 459,Write a python function to get the first element of each sublist.,"def Extract(lst): return [item[0] for item in lst] ",MBPP_459 460,Write a python function to count the upper case characters in a given string.,"def upper_ctr(str): upper_ctr = 0 for i in range(len(str)): if str[i] >= 'A' and str[i] <= 'Z': upper_ctr += 1 return upper_ctr",MBPP_460 461,Write a function to find all possible combinations of the elements of a given list.,"def combinations_list(list1): if len(list1) == 0: return [[]] result = [] for el in combinations_list(list1[1:]): result += [el, el+[list1[0]]] return result",MBPP_461 462,Write a function to find the maximum product subarray of the given array.,"def max_subarray_product(arr): n = len(arr) max_ending_here = 1 min_ending_here = 1 max_so_far = 0 flag = 0 for i in range(0, n): if arr[i] > 0: max_ending_here = max_ending_here * arr[i] min_ending_here = min (min_ending_here * arr[i], 1) flag = 1 elif arr[i] == 0: max_ending_here = 1 min_ending_here = 1 else: temp = max_ending_here max_ending_here = max (min_ending_here * arr[i], 1) min_ending_here = temp * arr[i] if (max_so_far < max_ending_here): max_so_far = max_ending_here if flag == 0 and max_so_far == 0: return 0 return max_so_far",MBPP_462 463,Write a function to check if all values are same in a dictionary.,"def check_value(dict, n): result = all(x == n for x in dict.values()) return result",MBPP_463 464,Write a function to drop empty items from a given dictionary.,"def drop_empty(dict1): dict1 = {key:value for (key, value) in dict1.items() if value is not None} return dict1",MBPP_464 465,Write a function to find the peak element in the given array.,"def find_peak_util(arr, low, high, n): mid = low + (high - low)/2 mid = int(mid) if ((mid == 0 or arr[mid - 1] <= arr[mid]) and (mid == n - 1 or arr[mid + 1] <= arr[mid])): return mid elif (mid > 0 and arr[mid - 1] > arr[mid]): return find_peak_util(arr, low, (mid - 1), n) else: return find_peak_util(arr, (mid + 1), high, n) def find_peak(arr, n): return find_peak_util(arr, 0, n - 1, n) ",MBPP_465 466,Write a python function to convert decimal number to octal number.,"def decimal_to_Octal(deciNum): octalNum = 0 countval = 1; dNo = deciNum; while (deciNum!= 0): remainder= deciNum % 8; octalNum+= remainder*countval; countval= countval*10; deciNum //= 8; return (octalNum)",MBPP_466 467,Write a function to find the maximum product formed by multiplying numbers of an increasing subsequence of that array.,"def max_product(arr, n ): mpis =[0] * (n) for i in range(n): mpis[i] = arr[i] for i in range(1, n): for j in range(i): if (arr[i] > arr[j] and mpis[i] < (mpis[j] * arr[i])): mpis[i] = mpis[j] * arr[i] return max(mpis)",MBPP_467 468,Write a function to find the maximum profit earned from a maximum of k stock transactions,"def max_profit(price, k): n = len(price) final_profit = [[None for x in range(n)] for y in range(k + 1)] for i in range(k + 1): for j in range(n): if i == 0 or j == 0: final_profit[i][j] = 0 else: max_so_far = 0 for x in range(j): curr_price = price[j] - price[x] + final_profit[i-1][x] if max_so_far < curr_price: max_so_far = curr_price final_profit[i][j] = max(final_profit[i][j-1], max_so_far) return final_profit[k][n-1]",MBPP_468 469,Write a function to find the pairwise addition of the elements of the given tuples.,"def add_pairwise(test_tup): res = tuple(i + j for i, j in zip(test_tup, test_tup[1:])) return (res) ",MBPP_469 470,Write a python function to find remainder of array multiplication divided by n.,"def find_remainder(arr, lens, n): mul = 1 for i in range(lens): mul = (mul * (arr[i] % n)) % n return mul % n ",MBPP_470 471,Write a python function to check whether the given list contains consecutive numbers or not.,"def check_Consecutive(l): return sorted(l) == list(range(min(l),max(l)+1)) ",MBPP_471 472,Write a function to find the tuple intersection of elements in the given tuple list irrespective of their order.,"def tuple_intersection(test_list1, test_list2): res = set([tuple(sorted(ele)) for ele in test_list1]) & set([tuple(sorted(ele)) for ele in test_list2]) return (res)",MBPP_472 473,Write a function to replace characters in a string.,"def replace_char(str1,ch,newch): str2 = str1.replace(ch, newch) return str2",MBPP_473 474,Write a function to sort counter by value.,"from collections import Counter def sort_counter(dict1): x = Counter(dict1) sort_counter=x.most_common() return sort_counter",MBPP_474 475,Write a python function to find the sum of the largest and smallest value in a given array.,"def big_sum(nums): sum= max(nums)+min(nums) return sum",MBPP_475 476,Write a python function to convert the given string to lower case.,"def is_lower(string): return (string.lower())",MBPP_476 477,Write a function to remove lowercase substrings from a given string.,"import re def remove_lowercase(str1): remove_lower = lambda text: re.sub('[a-z]', '', text) result = remove_lower(str1) return result",MBPP_477 478,Write a python function to find the first digit of a given number.,"def first_Digit(n) : while n >= 10: n = n / 10; return int(n) ",MBPP_478 479,Write a python function to find the maximum occurring character in a given string.,"def get_max_occuring_char(str1): ASCII_SIZE = 256 ctr = [0] * ASCII_SIZE max = -1 ch = '' for i in str1: ctr[ord(i)]+=1; for i in str1: if max < ctr[ord(i)]: max = ctr[ord(i)] ch = i return ch",MBPP_479 480,Write a function to determine if there is a subset of the given set with sum equal to the given sum.,"def is_subset_sum(set, n, sum): if (sum == 0): return True if (n == 0): return False if (set[n - 1] > sum): return is_subset_sum(set, n - 1, sum) return is_subset_sum(set, n-1, sum) or is_subset_sum(set, n-1, sum-set[n-1])",MBPP_480 481,Write a function to find sequences of one upper case letter followed by lower case letters in the given string by using regex.,"import re def match(text): pattern = '[A-Z]+[a-z]+$' if re.search(pattern, text): return('Yes') else: return('No') ",MBPP_481 482,Write a python function to find the first natural number whose factorial is divisible by x.,"def first_Factorial_Divisible_Number(x): i = 1; fact = 1; for i in range(1,x): fact = fact * i if (fact % x == 0): break return i ",MBPP_482 483,Write a function to remove the matching tuples from the given two tuples.,"def remove_matching_tuple(test_list1, test_list2): res = [sub for sub in test_list1 if sub not in test_list2] return (res) ",MBPP_483 484,Write a function to find the largest palindromic number in the given array.,"def is_palindrome(n) : divisor = 1 while (n / divisor >= 10) : divisor *= 10 while (n != 0) : leading = n // divisor trailing = n % 10 if (leading != trailing) : return False n = (n % divisor) // 10 divisor = divisor // 100 return True def largest_palindrome(A, n) : A.sort() for i in range(n - 1, -1, -1) : if (is_palindrome(A[i])) : return A[i] return -1",MBPP_484 485,Write a function to compute binomial probability for the given number.,"def nCr(n, r): if (r > n / 2): r = n - r answer = 1 for i in range(1, r + 1): answer *= (n - r + i) answer /= i return answer def binomial_probability(n, k, p): return (nCr(n, k) * pow(p, k) * pow(1 - p, n - k)) ",MBPP_485 486,Write a function to sort a list of tuples in increasing order by the last element in each tuple.,"def sort_tuple(tup): lst = len(tup) for i in range(0, lst): for j in range(0, lst-i-1): if (tup[j][-1] > tup[j + 1][-1]): temp = tup[j] tup[j]= tup[j + 1] tup[j + 1]= temp return tup",MBPP_486 487,Write a function to find the area of a pentagon.,"import math def area_pentagon(a): area=(math.sqrt(5*(5+2*math.sqrt(5)))*pow(a,2))/4.0 return area",MBPP_487 488,Write a python function to find the frequency of the largest value in a given array.,"def frequency_Of_Largest(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 ",MBPP_488 489,Write a function to extract all the pairs which are symmetric in the given tuple list.,"def extract_symmetric(test_list): temp = set(test_list) & {(b, a) for a, b in test_list} res = {(a, b) for a, b in temp if a < b} return (res) ",MBPP_489 490,Write a function to find the sum of geometric progression series.,"import math def sum_gp(a,n,r): total = (a * (1 - math.pow(r, n ))) / (1- r) return total",MBPP_490 491,Write a function to search an element in the given array by using binary search.,"def binary_search(item_list,item): first = 0 last = len(item_list)-1 found = False while( first<=last and not found): mid = (first + last)//2 if item_list[mid] == item : found = True else: if item < item_list[mid]: last = mid - 1 else: first = mid + 1 return found",MBPP_491 492,"Write a function to calculate a grid of hexagon coordinates where function returns a list of lists containing 6 tuples of x, y point coordinates.","import math def calculate_polygons(startx, starty, endx, endy, radius): sl = (2 * radius) * math.tan(math.pi / 6) p = sl * 0.5 b = sl * math.cos(math.radians(30)) w = b * 2 h = 2 * sl startx = startx - w starty = starty - h endx = endx + w endy = endy + h origx = startx origy = starty xoffset = b yoffset = 3 * p polygons = [] row = 1 counter = 0 while starty < endy: if row % 2 == 0: startx = origx + xoffset else: startx = origx while startx < endx: p1x = startx p1y = starty + p p2x = startx p2y = starty + (3 * p) p3x = startx + b p3y = starty + h p4x = startx + w p4y = starty + (3 * p) p5x = startx + w p5y = starty + p p6x = startx + b p6y = starty poly = [ (p1x, p1y), (p2x, p2y), (p3x, p3y), (p4x, p4y), (p5x, p5y), (p6x, p6y), (p1x, p1y)] polygons.append(poly) counter += 1 startx += w starty += yoffset row += 1 return polygons",MBPP_492 493,Write a function to convert the given binary tuple to integer.,"def binary_to_integer(test_tup): res = int("""".join(str(ele) for ele in test_tup), 2) return (str(res)) ",MBPP_493 494,Write a function to remove lowercase substrings from a given string by using regex.,"import re def remove_lowercase(str1): remove_lower = lambda text: re.sub('[a-z]', '', text) result = remove_lower(str1) return (result)",MBPP_494 495,Write a function to find the smallest integers from a given list of numbers using heap queue algorithm.,"import heapq as hq def heap_queue_smallest(nums,n): smallest_nums = hq.nsmallest(n, nums) return smallest_nums",MBPP_495 496,Write a function to find the surface area of a cone.,"import math def surfacearea_cone(r,h): l = math.sqrt(r * r + h * h) SA = math.pi * r * (r + l) return SA",MBPP_496 497,Write a python function to find gcd of two positive integers.,"def gcd(x, y): gcd = 1 if x % y == 0: return y for k in range(int(y / 2), 0, -1): if x % k == 0 and y % k == 0: gcd = k break return gcd",MBPP_497 498,Write a function to find the diameter of a circle.,"def diameter_circle(r): diameter=2*r return diameter",MBPP_498 499,Write a function to concatenate all elements of the given list into a string.,"def concatenate_elements(list): ans = ' ' for i in list: ans = ans+ ' '+i return (ans) ",MBPP_499 500,Write a python function to find common divisor between two numbers in a given pair.,"def ngcd(x,y): i=1 while(i<=x and i<=y): if(x%i==0 and y%i == 0): gcd=i; i+=1 return gcd; def num_comm_div(x,y): n = ngcd(x,y) result = 0 z = int(n**0.5) i = 1 while(i <= z): if(n % i == 0): result += 2 if(i == n/i): result-=1 i+=1 return result",MBPP_500 501,Write a python function to find remainder of two numbers.,"def find(n,m): r = n%m return (r)",MBPP_501 502,Write a function to add consecutive numbers of a given list.,"def add_consecutive_nums(nums): result = [b+a for a, b in zip(nums[:-1], nums[1:])] return result",MBPP_502 503,Write a python function to find the cube sum of first n natural numbers.,"def sum_Of_Series(n): sum = 0 for i in range(1,n + 1): sum += i * i*i return sum",MBPP_503 504,Write a function to move all zeroes to the end of the given array.,"def re_order(A): k = 0 for i in A: if i: A[k] = i k = k + 1 for i in range(k, len(A)): A[i] = 0 return A",MBPP_504 505,"Write a function to calculate the permutation coefficient of given p(n, k).","def permutation_coefficient(n, k): P = [[0 for i in range(k + 1)] for j in range(n + 1)] for i in range(n + 1): for j in range(min(i, k) + 1): if (j == 0): P[i][j] = 1 else: P[i][j] = P[i - 1][j] + ( j * P[i - 1][j - 1]) if (j < k): P[i][j + 1] = 0 return P[n][k] ",MBPP_505 506,Write a function to remove specific words from a given list.,"def remove_words(list1, removewords): for word in list(list1): if word in removewords: list1.remove(word) return list1 ",MBPP_506 507,Write a function to check if the common elements between two given lists are in the same order or not.,"def same_order(l1, l2): common_elements = set(l1) & set(l2) l1 = [e for e in l1 if e in common_elements] l2 = [e for e in l2 if e in common_elements] return l1 == l2",MBPP_507 508,Write a python function to find the average of odd numbers till a given odd number.,"def average_Odd(n) : if (n%2==0) : return (""Invalid Input"") return -1 sm =0 count =0 while (n>=1) : count=count+1 sm = sm + n n = n-2 return sm//count ",MBPP_508 509,Write a function to find the number of subsequences having product smaller than k for the given non negative array.,"def no_of_subsequences(arr, k): n = len(arr) dp = [[0 for i in range(n + 1)] for j in range(k + 1)] for i in range(1, k + 1): for j in range(1, n + 1): dp[i][j] = dp[i][j - 1] if arr[j - 1] <= i and arr[j - 1] > 0: dp[i][j] += dp[i // arr[j - 1]][j - 1] + 1 return dp[k][n]",MBPP_509 510,Write a python function to find minimum sum of factors of a given number.,"def find_Min_Sum(num): sum = 0 i = 2 while(i * i <= num): while(num % i == 0): sum += i num /= i i += 1 sum += num return sum",MBPP_510 511,Write a function to count the element frequency in the mixed nested tuple.,"def flatten(test_tuple): for tup in test_tuple: if isinstance(tup, tuple): yield from flatten(tup) else: yield tup def count_element_freq(test_tuple): res = {} for ele in flatten(test_tuple): if ele not in res: res[ele] = 0 res[ele] += 1 return (res) ",MBPP_511 512,Write a function to convert tuple into list by adding the given string after every element.,"def add_str(test_tup, K): res = [ele for sub in test_tup for ele in (sub, K)] return (res) ",MBPP_512 513,Write a function to find the summation of tuple elements in the given tuple list.,"def sum_elements(test_tup): res = sum(list(test_tup)) return (res) ",MBPP_513 514,Write a function to check if there is a subset with sum divisible by m.,"def modular_sum(arr, n, m): if (n > m): return True DP = [False for i in range(m)] for i in range(n): if (DP[0]): return True temp = [False for i in range(m)] for j in range(m): if (DP[j] == True): if (DP[(j + arr[i]) % m] == False): temp[(j + arr[i]) % m] = True for j in range(m): if (temp[j]): DP[j] = True DP[arr[i] % m] = True return DP[0]",MBPP_514 515,Write a function to sort a list of elements using radix sort.,"def radix_sort(nums): RADIX = 10 placement = 1 max_digit = max(nums) while placement < max_digit: buckets = [list() for _ in range( RADIX )] for i in nums: tmp = int((i / placement) % RADIX) buckets[tmp].append(i) a = 0 for b in range( RADIX ): buck = buckets[b] for i in buck: nums[a] = i a += 1 placement *= RADIX return nums",MBPP_515 516,Write a python function to find the largest postive number from the given list.,"def largest_pos(list1): max = list1[0] for x in list1: if x > max : max = x return max",MBPP_516 517,Write a function to find the square root of a perfect number.,"import math def sqrt_root(num): sqrt_root = math.pow(num, 0.5) return sqrt_root ",MBPP_517 518,Write a function to calculate volume of a tetrahedron.,"import math def volume_tetrahedron(num): volume = (num ** 3 / (6 * math.sqrt(2))) return round(volume, 2)",MBPP_518 519,Write a function to find the lcm of the given array elements.,"def find_lcm(num1, num2): if(num1>num2): num = num1 den = num2 else: num = num2 den = num1 rem = num % den while (rem != 0): num = den den = rem rem = num % den gcd = den lcm = int(int(num1 * num2)/int(gcd)) return lcm def get_lcm(l): num1 = l[0] num2 = l[1] lcm = find_lcm(num1, num2) for i in range(2, len(l)): lcm = find_lcm(lcm, l[i]) return lcm ",MBPP_519 520,Write a function to print check if the triangle is scalene or not.,"def check_isosceles(x,y,z): if x!=y & y!=z & z!=x: return True else: return False",MBPP_520 521,Write a function to find the longest bitonic subsequence for the given array.,"def lbs(arr): n = len(arr) lis = [1 for i in range(n+1)] for i in range(1 , n): for j in range(0 , i): if ((arr[i] > arr[j]) and (lis[i] < lis[j] +1)): lis[i] = lis[j] + 1 lds = [1 for i in range(n+1)] for i in reversed(range(n-1)): for j in reversed(range(i-1 ,n)): if(arr[i] > arr[j] and lds[i] < lds[j] + 1): lds[i] = lds[j] + 1 maximum = lis[0] + lds[0] - 1 for i in range(1 , n): maximum = max((lis[i] + lds[i]-1), maximum) return maximum",MBPP_521 522,"Write a function to check whether a given string has a capital letter, a lower case letter, a number and specified length using lambda function.","def check_string(str1): messg = [ lambda str1: any(x.isupper() for x in str1) or 'String must have 1 upper case character.', lambda str1: any(x.islower() for x in str1) or 'String must have 1 lower case character.', lambda str1: any(x.isdigit() for x in str1) or 'String must have 1 number.', lambda str1: len(str1) >= 7 or 'String length should be atleast 8.',] result = [x for x in [i(str1) for i in messg] if x != True] if not result: result.append('Valid string.') return result ",MBPP_522 523,Write a function to find the sum of maximum increasing subsequence of the given array.,"def max_sum_increasing_subsequence(arr, n): max = 0 msis = [0 for x in range(n)] for i in range(n): msis[i] = arr[i] for i in range(1, n): for j in range(i): if (arr[i] > arr[j] and msis[i] < msis[j] + arr[i]): msis[i] = msis[j] + arr[i] for i in range(n): if max < msis[i]: max = msis[i] return max",MBPP_523 524,Write a python function to check whether two given lines are parallel or not.,"def parallel_lines(line1, line2): return line1[0]/line1[1] == line2[0]/line2[1]",MBPP_524 525,Write a python function to capitalize first and last letters of each word of a given string.,"def capitalize_first_last_letters(str1): str1 = result = str1.title() result = """" for word in str1.split(): result += word[:-1] + word[-1].upper() + "" "" return result[:-1] ",MBPP_525 526,Write a function to find all pairs in an integer array whose sum is equal to a given number.,"def get_pairs_count(arr, n, sum): count = 0 for i in range(0, n): for j in range(i + 1, n): if arr[i] + arr[j] == sum: count += 1 return count",MBPP_526 527,Write a function to find the list of lists with minimum length.,"def min_length(list1): min_length = min(len(x) for x in list1 ) min_list = min((x) for x in list1) return(min_length, min_list) ",MBPP_527 528,Write a function to find the nth jacobsthal-lucas number.,"def jacobsthal_lucas(n): dp=[0] * (n + 1) dp[0] = 2 dp[1] = 1 for i in range(2, n+1): dp[i] = dp[i - 1] + 2 * dp[i - 2]; return dp[n]",MBPP_528 529,Write a function to find the ration of negative numbers in an array of integers.,"from array import array def negative_count(nums): n = len(nums) n1 = 0 for x in nums: if x < 0: n1 += 1 else: None return round(n1/n,2)",MBPP_529 530,Write a function to find minimum number of coins that make a given value.,"import sys def min_coins(coins, m, V): if (V == 0): return 0 res = sys.maxsize for i in range(0, m): if (coins[i] <= V): sub_res = min_coins(coins, m, V-coins[i]) if (sub_res != sys.maxsize and sub_res + 1 < res): res = sub_res + 1 return res ",MBPP_530 531,Write a function to check if the two given strings are permutations of each other.,"def check_permutation(str1, str2): n1=len(str1) n2=len(str2) if(n1!=n2): return False a=sorted(str1) str1="" "".join(a) b=sorted(str2) str2="" "".join(b) for i in range(0, n1, 1): if(str1[i] != str2[i]): return False return True",MBPP_531 532,Write a function to remove particular data type elements from the given tuple.,"def remove_datatype(test_tuple, data_type): res = [] for ele in test_tuple: if not isinstance(ele, data_type): res.append(ele) return (res) ",MBPP_532 533,Write a function to search a literals string in a string and also find the location within the original string where the pattern occurs.,"import re def search_literal(pattern,text): match = re.search(pattern, text) s = match.start() e = match.end() return (s, e)",MBPP_533 534,Write a function to find the top or bottom surface area of a cylinder.,"def topbottom_surfacearea(r): toporbottomarea=3.1415*r*r return toporbottomarea",MBPP_534 535,Write a function to select the nth items of a list.,"def nth_items(list,n): return list[::n]",MBPP_535 536,Write a python function to find the first repeated word in a given string.,"def first_repeated_word(str1): temp = set() for word in str1.split(): if word in temp: return word; else: temp.add(word) return 'None'",MBPP_536 537,Write a python function to convert a given string list to a tuple.,"def string_list_to_tuple(str1): result = tuple(x for x in str1 if not x.isspace()) return result",MBPP_537 538,Write a function to create a list containing the power of said number in bases raised to the corresponding number in the index using map function.,"def basesnum_coresspondingnum(bases_num,index): result = list(map(pow, bases_num, index)) return result",MBPP_538 539,Write a python function to find the difference between highest and least frequencies in a given array.,"def find_Diff(arr,n): arr.sort() count = 0; max_count = 0; min_count = n for i in range(0,(n-1)): if arr[i] == arr[i + 1]: count += 1 continue else: max_count = max(max_count,count) min_count = min(min_count,count) count = 0 return max_count - min_count ",MBPP_539 540,Write a function to find if the given number is abundant or not.,"import math def get_sum(n): sum = 0 i = 1 while i <= (math.sqrt(n)): if n%i == 0: if n/i == i : sum = sum + i else: sum = sum + i sum = sum + (n / i ) i = i + 1 sum = sum - n return sum def check_abundant(n): if (get_sum(n) > n): return True else: return False",MBPP_540 541,"Write a function to replace all occurrences of spaces, commas, or dots with a colon in the given string by using regex.","import re def fill_spaces(text): return (re.sub(""[ ,.]"", "":"", text))",MBPP_541 542,Write a function to add two numbers and print number of digits of sum.,"def count_digits(num1,num2): number=num1+num2 count = 0 while(number > 0): number = number // 10 count = count + 1 return count",MBPP_542 543,Write a function to flatten the tuple list to a string.,"def flatten_tuple(test_list): res = ' '.join([idx for tup in test_list for idx in tup]) return (res) ",MBPP_543 544,Write a python function to toggle only first and last bits of a given number.,"def take_L_and_F_set_bits(n) : n = n | n >> 1 n = n | n >> 2 n = n | n >> 4 n = n | n >> 8 n = n | n >> 16 return ((n + 1) >> 1) + 1 def toggle_F_and_L_bits(n) : if (n == 1) : return 0 return n ^ take_L_and_F_set_bits(n) ",MBPP_544 545,Write a function to find the last occurrence of a character in a string.,"def last_occurence_char(string,char): flag = -1 for i in range(len(string)): if(string[i] == char): flag = i if(flag == -1): return None else: return flag + 1",MBPP_545 546,Write a python function to find the sum of hamming distances of all consecutive numbers from o to n.,"def Total_Hamming_Distance(n): i = 1 sum = 0 while (n // i > 0): sum = sum + n // i i = i * 2 return sum",MBPP_546 547,Write a function to find the length of the longest increasing subsequence of the given sequence.,"def longest_increasing_subsequence(arr): n = len(arr) longest_increasing_subsequence = [1]*n for i in range (1 , n): for j in range(0 , i): if arr[i] > arr[j] and longest_increasing_subsequence[i]< longest_increasing_subsequence[j] + 1 : longest_increasing_subsequence[i] = longest_increasing_subsequence[j]+1 maximum = 0 for i in range(n): maximum = max(maximum , longest_increasing_subsequence[i]) return maximum",MBPP_547 548,Write a python function to find the sum of fifth power of first n odd natural numbers.,"def odd_Num_Sum(n) : j = 0 sm = 0 for i in range(1,n+1) : j = (2*i-1) sm = sm + (j*j*j*j*j) return sm ",MBPP_548 549,Write a python function to find the maximum element in a sorted and rotated array.,"def find_Max(arr,low,high): if (high < low): return arr[0] if (high == low): return arr[low] mid = low + (high - low) // 2 if (mid < high and arr[mid + 1] < arr[mid]): return arr[mid] if (mid > low and arr[mid] < arr[mid - 1]): return arr[mid - 1] if (arr[low] > arr[mid]): return find_Max(arr,low,mid - 1) else: return find_Max(arr,mid + 1,high) ",MBPP_549 550,Write a function to extract a specified column from a given nested list.,"def extract_column(list1, n): result = [i.pop(n) for i in list1] return result ",MBPP_550 551,Write a python function to check whether a given sequence is linear or not.,"def Seq_Linear(seq_nums): seq_nums = [seq_nums[x] - seq_nums[x-1] for x in range(1, len(seq_nums))] if len(set(seq_nums)) == 1: return ""Linear Sequence"" else: return ""Non Linear Sequence""",MBPP_551 552,Write a function to convert the given tuple to a floating-point number.,"def tuple_to_float(test_tup): res = float('.'.join(str(ele) for ele in test_tup)) return (res) ",MBPP_552 553,Write a python function to find odd numbers from a mixed list.,"def Split(list): od_li = [] for i in list: if (i % 2 != 0): od_li.append(i) return od_li",MBPP_553 554,Write a python function to find the difference between sum of cubes of first n natural numbers and the sum of first n natural numbers.,"def difference(n) : S = (n*(n + 1))//2; res = S*(S-1); return res; ",MBPP_554 555,Write a python function to count the pairs with xor as an odd number.,"def find_Odd_Pair(A,N) : oddPair = 0 for i in range(0,N) : for j in range(i+1,N) : if ((A[i] ^ A[j]) % 2 != 0): oddPair+=1 return oddPair ",MBPP_555 556,Write a function to toggle characters case in a string.,"def toggle_string(string): string1 = string.swapcase() return string1",MBPP_556 557,Write a python function to find the digit distance between two integers.,"def digit_distance_nums(n1, n2): return sum(map(int,str(abs(n1-n2))))",MBPP_557 558,Write a function to find the largest sum of contiguous subarray in the given array.,"def max_sub_array_sum(a, size): max_so_far = 0 max_ending_here = 0 for i in range(0, size): max_ending_here = max_ending_here + a[i] if max_ending_here < 0: max_ending_here = 0 elif (max_so_far < max_ending_here): max_so_far = max_ending_here return max_so_far",MBPP_558 559,Write a function to find the union of elements of the given tuples.,"def union_elements(test_tup1, test_tup2): res = tuple(set(test_tup1 + test_tup2)) return (res) ",MBPP_559 560,"Write a function to assign with each element, its pair elements from other similar pairs in the given tuple.","def assign_elements(test_list): res = dict() for key, val in test_list: res.setdefault(val, []) res.setdefault(key, []).append(val) return (res) ",MBPP_560 561,Write a python function to find the maximum length of sublist.,"def Find_Max_Length(lst): maxLength = max(len(x) for x in lst ) return maxLength ",MBPP_561 562,Write a function to extract values between quotation marks of a string.,"import re def extract_values(text): return (re.findall(r'""(.*?)""', text))",MBPP_562 563,Write a python function to count unequal element pairs from the given array.,"def count_Pairs(arr,n): cnt = 0; for i in range(n): for j in range(i + 1,n): if (arr[i] != arr[j]): cnt += 1; return cnt; ",MBPP_563 564,Write a python function to split a string into characters.,"def split(word): return [char for char in word] ",MBPP_564 565,Write a function to get the sum of a non-negative integer.,"def sum_digits(n): if n == 0: return 0 else: return n % 10 + sum_digits(int(n / 10))",MBPP_565 566,Write a function to check whether a specified list is sorted or not.,"def issort_list(list1): result = all(list1[i] <= list1[i+1] for i in range(len(list1)-1)) return result",MBPP_566 567,Write a function to create a list of empty dictionaries.,"def empty_list(length): empty_list = [{} for _ in range(length)] return empty_list",MBPP_567 568,Write a function to sort each sublist of strings in a given list of lists.,"def sort_sublists(list1): result = list(map(sorted,list1)) return result",MBPP_568 569,Write a function to remove words from a given list of strings containing a character or string.,"def remove_words(list1, charlist): new_list = [] for line in list1: new_words = ' '.join([word for word in line.split() if not any([phrase in word for phrase in charlist])]) new_list.append(new_words) return new_list",MBPP_569 570,Write a function to find maximum possible sum of disjoint pairs for the given array of integers and a number k.,"def max_sum_pair_diff_lessthan_K(arr, N, K): arr.sort() dp = [0] * N dp[0] = 0 for i in range(1, N): dp[i] = dp[i-1] if (arr[i] - arr[i-1] < K): if (i >= 2): dp[i] = max(dp[i], dp[i-2] + arr[i] + arr[i-1]); else: dp[i] = max(dp[i], arr[i] + arr[i-1]); return dp[N - 1]",MBPP_570 571,Write a python function to remove two duplicate numbers from a given number of lists.,"def two_unique_nums(nums): return [i for i in nums if nums.count(i)==1]",MBPP_571 572,Write a python function to calculate the product of the unique numbers of a given list.,"def unique_product(list_data): temp = list(set(list_data)) p = 1 for i in temp: p *= i return p",MBPP_572 573,Write a function to find the surface area of a cylinder.,"def surfacearea_cylinder(r,h): surfacearea=((2*3.1415*r*r) +(2*3.1415*r*h)) return surfacearea",MBPP_573 574,Write a python function to find nth number in a sequence which is not a multiple of a given number.,"def count_no (A,N,L,R): count = 0 for i in range (L,R + 1): if (i % A != 0): count += 1 if (count == N): break return (i) ",MBPP_574 575,Write a python function to check whether an array is subarray of another or not.,"def is_Sub_Array(A,B,n,m): i = 0; j = 0; while (i < n and j < m): if (A[i] == B[j]): i += 1; j += 1; if (j == m): return True; else: i = i - j + 1; j = 0; return False; ",MBPP_575 576,Write a python function to find the last digit in factorial of a given number.,"def last_Digit_Factorial(n): if (n == 0): return 1 elif (n <= 2): return n elif (n == 3): return 6 elif (n == 4): return 4 else: return 0",MBPP_576 577,Write a function to interleave lists of the same length.,"def interleave_lists(list1,list2,list3): result = [el for pair in zip(list1, list2, list3) for el in pair] return result",MBPP_577 578,Write a function to find the dissimilar elements in the given two tuples.,"def find_dissimilar(test_tup1, test_tup2): res = tuple(set(test_tup1) ^ set(test_tup2)) return (res) ",MBPP_578 579,Write a function to extract the even elements in the nested mixed tuple.,"def even_ele(test_tuple, even_fnc): res = tuple() for ele in test_tuple: if isinstance(ele, tuple): res += (even_ele(ele, even_fnc), ) elif even_fnc(ele): res += (ele, ) return res def extract_even(test_tuple): res = even_ele(test_tuple, lambda x: x % 2 == 0) return (res) ",MBPP_579 580,Write a python function to find the surface area of the square pyramid.,"def surface_Area(b,s): return 2 * b * s + pow(b,2) ",MBPP_580 581,Write a function to check if a dictionary is empty or not.,"def my_dict(dict1): if bool(dict1): return False else: return True",MBPP_581 582,Write a function for nth catalan number.,"def catalan_number(num): if num <=1: return 1 res_num = 0 for i in range(num): res_num += catalan_number(i) * catalan_number(num-i-1) return res_num",MBPP_582 583,Write a function to find all adverbs and their positions in a given sentence by using regex.,"import re def find_adverbs(text): for m in re.finditer(r""\w+ly"", text): return ('%d-%d: %s' % (m.start(), m.end(), m.group(0)))",MBPP_583 584,Write a function to find the n - expensive price items from a given dataset using heap queue algorithm.,"import heapq def expensive_items(items,n): expensive_items = heapq.nlargest(n, items, key=lambda s: s['price']) return expensive_items",MBPP_584 585,Write a python function to split the array and add the first part to the end.,"def split_Arr(a,n,k): b = a[:k] return (a[k::]+b[::]) ",MBPP_585 586,Write a function to convert a list to a tuple.,"def list_tuple(listx): tuplex = tuple(listx) return tuplex",MBPP_586 587,Write a python function to find the difference between largest and smallest value in a given array.,"def big_diff(nums): diff= max(nums)-min(nums) return diff",MBPP_587 588,Write a function to find perfect squares between two given numbers.,"def perfect_squares(a, b): lists=[] for i in range (a,b+1): j = 1; while j*j <= i: if j*j == i: lists.append(i) j = j+1 i = i+1 return lists",MBPP_588 589,Write a function to convert polar coordinates to rectangular coordinates.,"import cmath def polar_rect(x,y): cn = complex(x,y) cn=cmath.polar(cn) cn1 = cmath.rect(2, cmath.pi) return (cn,cn1)",MBPP_589 590,Write a python function to interchange the first and last elements in a list.,"def swap_List(newList): size = len(newList) temp = newList[0] newList[0] = newList[size - 1] newList[size - 1] = temp return newList ",MBPP_590 591,Write a python function to find sum of product of binomial co-efficients.,"def binomial_Coeff(n,k): C = [0] * (k + 1); C[0] = 1; # nC0 is 1 for i in range(1,n + 1): for j in range(min(i, k),0,-1): C[j] = C[j] + C[j - 1]; return C[k]; def sum_Of_product(n): return binomial_Coeff(2 * n,n - 1); ",MBPP_591 592,Write a function to remove leading zeroes from an ip address.,"import re def removezero_ip(ip): string = re.sub('\.[0]*', '.', ip) return string ",MBPP_592 593,Write a function to find the difference of first even and odd number of a given list.,"def diff_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el for el in list1 if el%2!=0),-1) return (first_even-first_odd)",MBPP_593 594,Write a python function to count minimum number of swaps required to convert one binary string to another.,"def min_Swaps(str1,str2) : count = 0 for i in range(len(str1)) : if str1[i] != str2[i] : count += 1 if count % 2 == 0 : return (count // 2) else : return (""Not Possible"") ",MBPP_594 595,Write a function to find the size of the given tuple.,"import sys def tuple_size(tuple_list): return (sys.getsizeof(tuple_list)) ",MBPP_595 596,Write a function to find kth element from the given two sorted arrays.,"def find_kth(arr1, arr2, m, n, k): sorted1 = [0] * (m + n) i = 0 j = 0 d = 0 while (i < m and j < n): if (arr1[i] < arr2[j]): sorted1[d] = arr1[i] i += 1 else: sorted1[d] = arr2[j] j += 1 d += 1 while (i < m): sorted1[d] = arr1[i] d += 1 i += 1 while (j < n): sorted1[d] = arr2[j] d += 1 j += 1 return sorted1[k - 1]",MBPP_596 597,Write a function to check whether the given number is armstrong or not.,"def armstrong_number(number): sum = 0 times = 0 temp = number while temp > 0: times = times + 1 temp = temp // 10 temp = number while temp > 0: reminder = temp % 10 sum = sum + (reminder ** times) temp //= 10 if number == sum: return True else: return False",MBPP_597 598,Write a function to find sum and average of first n natural numbers.,"def sum_average(number): total = 0 for value in range(1, number + 1): total = total + value average = total / number return (total,average)",MBPP_598 599,Write a python function to check whether the given number is even or not using bitwise operator.,"def is_Even(n) : if (n^1 == n+1) : return True; else : return False; ",MBPP_599 600,Write a function to find the longest chain which can be formed from the given set of pairs.,"class Pair(object): def __init__(self, a, b): self.a = a self.b = b def max_chain_length(arr, n): max = 0 mcl = [1 for i in range(n)] for i in range(1, n): for j in range(0, i): if (arr[i].a > arr[j].b and mcl[i] < mcl[j] + 1): mcl[i] = mcl[j] + 1 for i in range(n): if (max < mcl[i]): max = mcl[i] return max",MBPP_600 601,Write a python function to find the first repeated character in a given string.,"def first_repeated_char(str1): for index,c in enumerate(str1): if str1[:index+1].count(c) > 1: return c return ""None""",MBPP_601 602,Write a function to get a lucid number smaller than or equal to n.,"def get_ludic(n): ludics = [] for i in range(1, n + 1): ludics.append(i) index = 1 while(index != len(ludics)): first_ludic = ludics[index] remove_index = index + first_ludic while(remove_index < len(ludics)): ludics.remove(ludics[remove_index]) remove_index = remove_index + first_ludic - 1 index += 1 return ludics",MBPP_602 603,Write a function to reverse words in a given string.,"def reverse_words(s): return ' '.join(reversed(s.split()))",MBPP_603 604,Write a function to check if the given integer is a prime number.,"def prime_num(num): if num >=1: for i in range(2, num//2): if (num % i) == 0: return False else: return True else: return False",MBPP_604 605,Write a function to convert degrees to radians.,"import math def radian_degree(degree): radian = degree*(math.pi/180) return radian",MBPP_605 606,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.,"import re pattern = 'fox' text = 'The quick brown fox jumps over the lazy dog.' def find_literals(text, pattern): match = re.search(pattern, text) s = match.start() e = match.end() return (match.re.pattern, s, e)",MBPP_606 607,Write a python function to find nth bell number.,"def bell_Number(n): bell = [[0 for i in range(n+1)] for j in range(n+1)] bell[0][0] = 1 for i in range(1, n+1): bell[i][0] = bell[i-1][i-1] for j in range(1, i+1): bell[i][j] = bell[i-1][j-1] + bell[i][j-1] return bell[n][0] ",MBPP_607 608,Write a python function to find minimum possible value for the given periodic function.,"def floor_Min(A,B,N): x = max(B - 1,N) return (A*x) // B",MBPP_608 609,Write a python function to remove the k'th element from a given list.,"def remove_kth_element(list1, L): return list1[:L-1] + list1[L:]",MBPP_609 610,Write a function to find the maximum of nth column from the given tuple list.,"def max_of_nth(test_list, N): res = max([sub[N] for sub in test_list]) return (res) ",MBPP_610 611,Write a python function to merge the first and last elements separately in a list of lists.,"def merge(lst): return [list(ele) for ele in list(zip(*lst))] ",MBPP_611 612,Write a function to find the maximum value in record list as tuple attribute in the given tuple list.,"def maximum_value(test_list): res = [(key, max(lst)) for key, lst in test_list] return (res) ",MBPP_612 613,Write a function to find the cumulative sum of all the values that are present in the given tuple list.,"def cummulative_sum(test_list): res = sum(map(sum, test_list)) return (res)",MBPP_613 614,Write a function to find average value of the numbers in a given tuple of tuples.,"def average_tuple(nums): result = [sum(x) / len(x) for x in zip(*nums)] return result",MBPP_614 615,Write a function to perfom the modulo of tuple elements in the given two tuples.,"def tuple_modulo(test_tup1, test_tup2): res = tuple(ele1 % ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res) ",MBPP_615 616,"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.","def min_Jumps(a, b, d): temp = a a = min(a, b) b = max(temp, b) if (d >= b): return (d + b - 1) / b if (d == 0): return 0 if (d == a): return 1 else: return 2",MBPP_616 617,Write a function to divide two lists using map and lambda function.,"def div_list(nums1,nums2): result = map(lambda x, y: x / y, nums1, nums2) return list(result)",MBPP_617 618,Write a function to move all the numbers in it to the given string.,"def move_num(test_str): res = '' dig = '' for ele in test_str: if ele.isdigit(): dig += ele else: res += ele res += dig return (res) ",MBPP_618 619,Write a function to find the largest subset where each pair is divisible.,"def largest_subset(a, n): dp = [0 for i in range(n)] dp[n - 1] = 1; for i in range(n - 2, -1, -1): mxm = 0; for j in range(i + 1, n): if a[j] % a[i] == 0 or a[i] % a[j] == 0: mxm = max(mxm, dp[j]) dp[i] = 1 + mxm return max(dp)",MBPP_619 620,Write a function to increment the numeric values in the given strings by k.,"def increment_numerics(test_list, K): res = [str(int(ele) + K) if ele.isdigit() else ele for ele in test_list] return res ",MBPP_620 621,Write a function to find the median of two sorted arrays of same size.,"def get_median(arr1, arr2, n): i = 0 j = 0 m1 = -1 m2 = -1 count = 0 while count < n + 1: count += 1 if i == n: m1 = m2 m2 = arr2[0] break elif j == n: m1 = m2 m2 = arr1[0] break if arr1[i] <= arr2[j]: m1 = m2 m2 = arr1[i] i += 1 else: m1 = m2 m2 = arr2[j] j += 1 return (m1 + m2)/2",MBPP_621 622,Write a function to find the n-th power of individual elements in a list using lambda function.,"def nth_nums(nums,n): nth_nums = list(map(lambda x: x ** n, nums)) return nth_nums",MBPP_622 623,Write a python function to convert the given string to upper case.,"def is_upper(string): return (string.upper())",MBPP_623 624,Write a python function to interchange first and last elements in a given list.,"def swap_List(newList): size = len(newList) temp = newList[0] newList[0] = newList[size - 1] newList[size - 1] = temp return newList ",MBPP_624 625,Write a python function to find the largest triangle that can be inscribed in the semicircle.,"def triangle_area(r) : if r < 0 : return -1 return r * r ",MBPP_625 626,Write a python function to find the smallest missing number from the given array.,"def find_First_Missing(array,start,end): if (start > end): return end + 1 if (start != array[start]): return start; mid = int((start + end) / 2) if (array[mid] == mid): return find_First_Missing(array,mid+1,end) return find_First_Missing(array,start,mid) ",MBPP_626 627,Write a function to replace all spaces in the given string with character * list item * list item * list item * list item '%20'.,"MAX=1000; def replace_spaces(string): string=string.strip() i=len(string) space_count=string.count(' ') new_length = i + space_count*2 if new_length > MAX: return -1 index = new_length-1 string=list(string) for f in range(i-2, new_length-2): string.append('0') for j in range(i-1, 0, -1): if string[j] == ' ': string[index] = '0' string[index-1] = '2' string[index-2] = '%' index=index-3 else: string[index] = string[j] index -= 1 return ''.join(string)",MBPP_627 628,Write a python function to find even numbers from a mixed list.,"def Split(list): ev_li = [] for i in list: if (i % 2 == 0): ev_li.append(i) return ev_li",MBPP_628 629,Write a function to extract all the adjacent coordinates of the given coordinate tuple.,"def adjac(ele, sub = []): if not ele: yield sub else: yield from [idx for j in range(ele[0] - 1, ele[0] + 2) for idx in adjac(ele[1:], sub + [j])] def get_coordinates(test_tup): res = list(adjac(test_tup)) return (res) ",MBPP_629 630,Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.,"import re text = 'Python Exercises' def replace_spaces(text): text =text.replace ("" "", ""_"") return (text) text =text.replace (""_"", "" "") return (text)",MBPP_630 631,Write a python function to move all zeroes to the end of the given list.,"def move_zero(num_list): a = [0 for i in range(num_list.count(0))] x = [ i for i in num_list if i != 0] x.extend(a) return (x)",MBPP_631 632,Write a python function to find the sum of xor of all pairs of numbers in the given array.,"def pair_OR_Sum(arr,n) : ans = 0 for i in range(0,n) : for j in range(i + 1,n) : ans = ans + (arr[i] ^ arr[j]) return ans ",MBPP_632 633,Write a python function to find the sum of fourth power of first n even natural numbers.,"def even_Power_Sum(n): sum = 0; for i in range(1,n + 1): j = 2*i; sum = sum + (j*j*j*j); return sum; ",MBPP_633 634,Write a function to push all values into a heap and then pop off the smallest values one at a time.,"import heapq as hq def heap_sort(iterable): h = [] for value in iterable: hq.heappush(h, value) return [hq.heappop(h) for i in range(len(h))]",MBPP_634 635,Write a python function to check if roots of a quadratic equation are reciprocal of each other or not.,"def Check_Solution(a,b,c): if (a == c): return (""Yes""); else: return (""No""); ",MBPP_635 636,Write a function to check whether the given amount has no profit and no loss,"def noprofit_noloss(actual_cost,sale_amount): if(sale_amount == actual_cost): return True else: return False",MBPP_636 637,Write a function to calculate wind chill index.,"import math def wind_chill(v,t): windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16) return int(round(windchill, 0))",MBPP_637 638,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.,"def sample_nam(sample_names): sample_names=list(filter(lambda el:el[0].isupper() and el[1:].islower(),sample_names)) return len(''.join(sample_names))",MBPP_638 639,Write a function to remove the parenthesis area in a string.,"import re def remove_parenthesis(items): for item in items: return (re.sub(r"" ?\([^)]+\)"", """", item))",MBPP_639 640,Write a function to find the nth nonagonal number.,"def is_nonagonal(n): return int(n * (7 * n - 5) / 2) ",MBPP_640 641,Write a function to remove similar rows from the given tuple matrix.,"def remove_similar_row(test_list): res = set(sorted([tuple(sorted(set(sub))) for sub in test_list])) return (res) ",MBPP_641 642,"Write a function that matches a word containing 'z', not at the start or end of the word.","import re def text_match_wordz_middle(text): patterns = '\Bz\B' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')",MBPP_642 643,Write a python function to reverse an array upto a given position.,"def reverse_Array_Upto_K(input, k): return (input[k-1::-1] + input[k:]) ",MBPP_643 644,Write a function to find the product of it’s kth index in the given tuples.,"def get_product(val) : res = 1 for ele in val: res *= ele return res def find_k_product(test_list, K): res = get_product([sub[K] for sub in test_list]) return (res) ",MBPP_644 645,Write a python function to count number of cubes of size k in a cube of size n.,"def No_of_cubes(N,K): No = 0 No = (N - K + 1) No = pow(No, 3) return No",MBPP_645 646,Write a function to split a string at uppercase letters.,"import re def split_upperstring(text): return (re.findall('[A-Z][^A-Z]*', text))",MBPP_646 647,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.,"from itertools import zip_longest, chain, tee def exchange_elements(lst): lst1, lst2 = tee(iter(lst), 2) return list(chain.from_iterable(zip_longest(lst[1::2], lst[::2])))",MBPP_647 648,Write a python function to calculate the sum of the numbers in a list between the indices of a specified range.,"def sum_Range_list(nums, m, n): sum_range = 0 for i in range(m, n+1, 1): sum_range += nums[i] return sum_range ",MBPP_648 649,Write a python function to check whether the given two arrays are equal or not.,"def are_Equal(arr1,arr2,n,m): if (n != m): return False arr1.sort() arr2.sort() for i in range(0,n - 1): if (arr1[i] != arr2[i]): return False return True",MBPP_649 650,Write a function to check if one tuple is a subset of another tuple.,"def check_subset(test_tup1, test_tup2): res = set(test_tup2).issubset(test_tup1) return (res) ",MBPP_650 651,Write a function to flatten the given tuple matrix into the tuple list with each tuple representing each column.,"def matrix_to_list(test_list): temp = [ele for sub in test_list for ele in sub] res = list(zip(*temp)) return (str(res))",MBPP_651 652,Write a function to group a sequence of key-value pairs into a dictionary of lists using collections module.,"from collections import defaultdict def grouping_dictionary(l): d = defaultdict(list) for k, v in l: d[k].append(v) return d",MBPP_652 653,Write a function to find the perimeter of a rectangle.,"def rectangle_perimeter(l,b): perimeter=2*(l+b) return perimeter",MBPP_653 654,Write a python function to find the sum of fifth power of n natural numbers.,"def fifth_Power_Sum(n) : sm = 0 for i in range(1,n+1) : sm = sm + (i*i*i*i*i) return sm ",MBPP_654 655,Write a python function to find the minimum sum of absolute differences of two arrays.,"def find_Min_Sum(a,b,n): a.sort() b.sort() sum = 0 for i in range(n): sum = sum + abs(a[i] - b[i]) return sum",MBPP_655 656,Write a python function to find the first digit in factorial of a given number.,"import math def first_Digit(n) : fact = 1 for i in range(2,n + 1) : fact = fact * i while (fact % 10 == 0) : fact = int(fact / 10) while (fact >= 10) : fact = int(fact / 10) return math.floor(fact) ",MBPP_656 657,Write a function to find the item with maximum occurrences in a given list.,"def max_occurrences(list1): max_val = 0 result = list1[0] for i in list1: occu = list1.count(i) if occu > max_val: max_val = occu result = i return result",MBPP_657 658,Write a python function to print duplicants from a list of integers.,"def Repeat(x): _size = len(x) repeated = [] for i in range(_size): k = i + 1 for j in range(k, _size): if x[i] == x[j] and x[i] not in repeated: repeated.append(x[i]) return repeated ",MBPP_658 659,Write a python function to choose points from two ranges such that no point lies in both the ranges.,"def find_Points(l1,r1,l2,r2): x = min(l1,l2) if (l1 != l2) else -1 y = max(r1,r2) if (r1 != r2) else -1 return (x,y)",MBPP_659 660,Write a function to find the maximum sum that can be formed which has no three consecutive elements present.,"def max_sum_of_three_consecutive(arr, n): sum = [0 for k in range(n)] if n >= 1: sum[0] = arr[0] if n >= 2: sum[1] = arr[0] + arr[1] if n > 2: sum[2] = max(sum[1], max(arr[1] + arr[2], arr[0] + arr[2])) for i in range(3, n): sum[i] = max(max(sum[i-1], sum[i-2] + arr[i]), arr[i] + arr[i-1] + sum[i-3]) return sum[n-1]",MBPP_660 661,Write a function to sort a list in a dictionary.,"def sorted_dict(dict1): sorted_dict = {x: sorted(y) for x, y in dict1.items()} return sorted_dict",MBPP_661 662,Write a function to find the largest possible value of k such that k modulo x is y.,"import sys def find_max_val(n, x, y): ans = -sys.maxsize for k in range(n + 1): if (k % x == y): ans = max(ans, k) return (ans if (ans >= 0 and ans <= n) else -1) ",MBPP_662 663,Write a python function to find the average of even numbers till a given even number.,"def average_Even(n) : if (n% 2!= 0) : return (""Invalid Input"") return -1 sm = 0 count = 0 while (n>= 2) : count = count+1 sm = sm+n n = n-2 return sm // count ",MBPP_663 664,Write a python function to shift first element to the end of given list.,"def move_last(num_list): a = [num_list[0] for i in range(num_list.count(num_list[0]))] x = [ i for i in num_list if i != num_list[0]] x.extend(a) return (x)",MBPP_664 665,Write a function to count occurrence of a character in a string.,"def count_char(string,char): count = 0 for i in range(len(string)): if(string[i] == char): count = count + 1 return count",MBPP_665 666,Write a python function to count number of vowels in the string.,"def Check_Vow(string, vowels): final = [each for each in string if each in vowels] return(len(final)) ",MBPP_666 667,Write a python function to replace multiple occurence of character by single.,"import re def replace(string, char): pattern = char + '{2,}' string = re.sub(pattern, char, string) return string ",MBPP_667 668,Write a function to check whether the given ip address is valid or not using regex.,"import re regex = '''^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$''' def check_IP(Ip): if(re.search(regex, Ip)): return (""Valid IP address"") else: return (""Invalid IP address"") ",MBPP_668 669,Write a python function to check whether a sequence of numbers has a decreasing trend or not.,"def decreasing_trend(nums): if (sorted(nums)== nums): return True else: return False",MBPP_669 670,Write a python function to set the right most unset bit.,"import math def get_Pos_Of_Right_most_Set_Bit(n): return int(math.log2(n&-n)+1) def set_Right_most_Unset_Bit(n): if (n == 0): return 1 if ((n & (n + 1)) == 0): return n pos = get_Pos_Of_Right_most_Set_Bit(~n) return ((1 << (pos - 1)) | n) ",MBPP_670 671,Write a function to find maximum of three numbers.,"def max_of_three(num1,num2,num3): if (num1 >= num2) and (num1 >= num3): lnum = num1 elif (num2 >= num1) and (num2 >= num3): lnum = num2 else: lnum = num3 return lnum",MBPP_671 672,Write a python function to convert a list of multiple integers into a single integer.,"def convert(list): s = [str(i) for i in list] res = int("""".join(s)) return (res) ",MBPP_672 673,Write a function to remove duplicate words from a given string using collections module.,"from collections import OrderedDict def remove_duplicate(string): result = ' '.join(OrderedDict((w,w) for w in string.split()).keys()) return result",MBPP_673 674,"Write a function to add two integers. however, if the sum is between the given range it will return 20.","def sum_nums(x, y,m,n): sum_nums= x + y if sum_nums in range(m, n): return 20 else: return sum_nums",MBPP_674 675,Write a function to remove everything except alphanumeric characters from the given string by using regex.,"import re def remove_extra_char(text1): pattern = re.compile('[\W_]+') return (pattern.sub('', text1))",MBPP_675 676,Write a function to check if the triangle is valid or not.,"def validity_triangle(a,b,c): total = a + b + c if total == 180: return True else: return False",MBPP_676 677,Write a python function to remove spaces from a given string.,"def remove_spaces(str1): str1 = str1.replace(' ','') return str1",MBPP_677 678,Write a function to access dictionary key’s element by index.,"def access_key(ditionary,key): return list(ditionary)[key]",MBPP_678 679,Write a python function to check whether a sequence of numbers has an increasing trend or not.,"def increasing_trend(nums): if (sorted(nums)== nums): return True else: return False",MBPP_679 680,Write a python function to find the smallest prime divisor of a number.,"def smallest_Divisor(n): if (n % 2 == 0): return 2; i = 3; while (i*i <= n): if (n % i == 0): return i; i += 2; return n; ",MBPP_680 681,Write a function to multiply two lists using map and lambda function.,"def mul_list(nums1,nums2): result = map(lambda x, y: x * y, nums1, nums2) return list(result)",MBPP_681 682,Write a python function to check whether the given number can be represented by sum of two squares or not.,"def sum_Square(n) : i = 1 while i*i <= n : j = 1 while (j*j <= n) : if (i*i+j*j == n) : return True j = j+1 i = i+1 return False",MBPP_682 683,Write a python function to count occurences of a character in a repeated string.,"def count_Char(str,x): count = 0 for i in range(len(str)): if (str[i] == x) : count += 1 n = 10 repititions = n // len(str) count = count * repititions l = n % len(str) for i in range(l): if (str[i] == x): count += 1 return count ",MBPP_683 684,Write a python function to find sum of prime numbers between 1 to n.,"def sum_Of_Primes(n): prime = [True] * (n + 1) p = 2 while p * p <= n: if prime[p] == True: i = p * 2 while i <= n: prime[i] = False i += p p += 1 sum = 0 for i in range (2,n + 1): if(prime[i]): sum += i return sum",MBPP_684 685,Write a function to find the frequency of each element in the given list.,"from collections import defaultdict def freq_element(test_tup): res = defaultdict(int) for ele in test_tup: res[ele] += 1 return (str(dict(res))) ",MBPP_685 686,Write a function to find the greatest common divisor (gcd) of two integers by using recursion.,"def recur_gcd(a, b): low = min(a, b) high = max(a, b) if low == 0: return high elif low == 1: return 1 else: return recur_gcd(low, high%low)",MBPP_686 687,Write a function to get the length of a complex number.,"import cmath def len_complex(a,b): cn=complex(a,b) length=abs(cn) return length",MBPP_687 688,## 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,"def min_jumps(arr, n): jumps = [0 for i in range(n)] if (n == 0) or (arr[0] == 0): return float('inf') jumps[0] = 0 for i in range(1, n): jumps[i] = float('inf') for j in range(i): if (i <= j + arr[j]) and (jumps[j] != float('inf')): jumps[i] = min(jumps[i], jumps[j] + 1) break return jumps[n-1]",MBPP_688 689,Write a function to multiply consecutive numbers of a given list.,"def mul_consecutive_nums(nums): result = [b*a for a, b in zip(nums[:-1], nums[1:])] return result",MBPP_689 690,Write a function to group the 1st elements on the basis of 2nd elements in the given tuple list.,"from itertools import groupby def group_element(test_list): res = dict() for key, val in groupby(sorted(test_list, key = lambda ele: ele[1]), key = lambda ele: ele[1]): res[key] = [ele[0] for ele in val] return (res) ",MBPP_690 691,Write a python function to find the last two digits in factorial of a given number.,"def last_Two_Digits(N): if (N >= 10): return fac = 1 for i in range(1,N + 1): fac = (fac * i) % 100 return (fac) ",MBPP_691 692,Write a function to remove multiple spaces in a string by using regex.,"import re def remove_multiple_spaces(text1): return (re.sub(' +',' ',text1))",MBPP_692 693,Write a function to extract unique values from the given dictionary values.,"def extract_unique(test_dict): res = list(sorted({ele for val in test_dict.values() for ele in val})) return res",MBPP_693 694,Write a function to check if each element of the second tuple is greater than its corresponding index in the first tuple.,"def check_greater(test_tup1, test_tup2): res = all(x < y for x, y in zip(test_tup1, test_tup2)) return (res) ",MBPP_694 695,Write a function to zip two given lists of lists.,"def zip_list(list1,list2): result = list(map(list.__add__, list1, list2)) return result",MBPP_695 696,Write a function to find number of even elements in the given list using lambda function.,"def count_even(array_nums): count_even = len(list(filter(lambda x: (x%2 == 0) , array_nums))) return count_even",MBPP_696 697,Write a function to sort dictionary items by tuple product of keys for the given dictionary with tuple keys.,"def sort_dict_item(test_dict): res = {key: test_dict[key] for key in sorted(test_dict.keys(), key = lambda ele: ele[1] * ele[0])} return (res) ",MBPP_697 698,Write a python function to find the minimum number of swaps required to convert one binary string to another.,"def min_Swaps(str1,str2) : count = 0 for i in range(len(str1)) : if str1[i] != str2[i] : count += 1 if count % 2 == 0 : return (count // 2) else : return (""Not Possible"") ",MBPP_698 699,Write a function to count the number of elements in a list which are within a specific range.,"def count_range_in_list(li, min, max): ctr = 0 for x in li: if min <= x <= max: ctr += 1 return ctr",MBPP_699 700,Write a function to find the equilibrium index of the given array.,"def equilibrium_index(arr): total_sum = sum(arr) left_sum=0 for i, num in enumerate(arr): total_sum -= num if left_sum == total_sum: return i left_sum += num return -1",MBPP_700 701,Write a function to find the minimum number of elements that should be removed such that amax-amin<=k.,"def find_ind(key, i, n, k, arr): ind = -1 start = i + 1 end = n - 1; while (start < end): mid = int(start + (end - start) / 2) if (arr[mid] - key <= k): ind = mid start = mid + 1 else: end = mid return ind def removals(arr, n, k): ans = n - 1 arr.sort() for i in range(0, n): j = find_ind(arr[i], i, n, k, arr) if (j != -1): ans = min(ans, n - (j - i + 1)) return ans",MBPP_701 702,Write a function to check whether the given key is present in the dictionary or not.,"def is_key_present(d,x): if x in d: return True else: return False",MBPP_702 703,Write a function to calculate the harmonic sum of n-1.,"def harmonic_sum(n): if n < 2: return 1 else: return 1 / n + (harmonic_sum(n - 1))",MBPP_703 704,Write a function to sort a list of lists by length and value.,"def sort_sublists(list1): list1.sort() list1.sort(key=len) return list1",MBPP_704 705,Write a function to find whether an array is subset of another array.,"def is_subset(arr1, m, arr2, n): hashset = set() for i in range(0, m): hashset.add(arr1[i]) for i in range(0, n): if arr2[i] in hashset: continue else: return False return True ",MBPP_705 706,Write a python function to count the total set bits from 1 to n.,"def count_Set_Bits(n) : n += 1; powerOf2 = 2; cnt = n // 2; while (powerOf2 <= n) : totalPairs = n // powerOf2; cnt += (totalPairs // 2) * powerOf2; if (totalPairs & 1) : cnt += (n % powerOf2) else : cnt += 0 powerOf2 <<= 1; return cnt; ",MBPP_706 707,Write a python function to convert a string to a list.,"def Convert(string): li = list(string.split("" "")) return li ",MBPP_707 708,Write a function to count unique keys for each value present in the tuple.,"from collections import defaultdict def get_unique(test_list): res = defaultdict(list) for sub in test_list: res[sub[1]].append(sub[0]) res = dict(res) res_dict = dict() for key in res: res_dict[key] = len(list(set(res[key]))) return (str(res_dict)) ",MBPP_708 709,Write a function to access the initial and last data of the given tuple record.,"def front_and_rear(test_tup): res = (test_tup[0], test_tup[-1]) return (res) ",MBPP_709 710,Write a python function to check whether the product of digits of a number at even and odd places is equal or not.,"def product_Equal(n): if n < 10: return False prodOdd = 1; prodEven = 1 while n > 0: digit = n % 10 prodOdd *= digit n = n//10 if n == 0: break; digit = n % 10 prodEven *= digit n = n//10 if prodOdd == prodEven: return True return False",MBPP_710 711,Write a function to remove duplicates from a list of lists.,"import itertools def remove_duplicate(list1): list.sort(list1) remove_duplicate = list(list1 for list1,_ in itertools.groupby(list1)) return remove_duplicate",MBPP_711 712,Write a function to check if the given tuple contains all valid values or not.,"def check_valid(test_tup): res = not any(map(lambda ele: not ele, test_tup)) return (res) ",MBPP_712 713,Write a python function to count the number of distinct power of prime factor of given number.,"def count_Fac(n): m = n count = 0 i = 2 while((i * i) <= m): total = 0 while (n % i == 0): n /= i total += 1 temp = 0 j = 1 while((temp + j) <= total): temp += j count += 1 j += 1 i += 1 if (n != 1): count += 1 return count ",MBPP_713 714,Write a function to convert the given string of integers into a tuple.,"def str_to_tuple(test_str): res = tuple(map(int, test_str.split(', '))) return (res) ",MBPP_714 715,Write a function to find the perimeter of a rombus.,"def rombus_perimeter(a): perimeter=4*a return perimeter",MBPP_715 716,Write a function to calculate the standard deviation.,"import math import sys def sd_calc(data): n = len(data) if n <= 1: return 0.0 mean, sd = avg_calc(data), 0.0 for el in data: sd += (float(el) - mean)**2 sd = math.sqrt(sd / float(n-1)) return sd def avg_calc(ls): n, mean = len(ls), 0.0 if n <= 1: return ls[0] for el in ls: mean = mean + float(el) mean = mean / float(n) return mean",MBPP_716 717,Write a function to create a list taking alternate elements from another given list.,"def alternate_elements(list1): result=[] for item in list1[::2]: result.append(item) return result ",MBPP_717 718,Write a function that matches a string that has an a followed by zero or more b's.,"import re def text_match(text): patterns = 'ab*?' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')",MBPP_718 719,Write a function to add a dictionary to the tuple.,"def add_dict_to_tuple(test_tup, test_dict): test_tup = list(test_tup) test_tup.append(test_dict) test_tup = tuple(test_tup) return (test_tup) ",MBPP_719 720,Write a function to find a path with the maximum average over all existing paths for the given square matrix of size n*n.,"M = 100 def maxAverageOfPath(cost, N): dp = [[0 for i in range(N + 1)] for j in range(N + 1)] dp[0][0] = cost[0][0] for i in range(1, N): dp[i][0] = dp[i - 1][0] + cost[i][0] for j in range(1, N): dp[0][j] = dp[0][j - 1] + cost[0][j] for i in range(1, N): for j in range(1, N): dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + cost[i][j] return dp[N - 1][N - 1] / (2 * N - 1)",MBPP_720 721,Write a function to filter the height and width of students which are stored in a dictionary.,"def filter_data(students,h,w): result = {k: s for k, s in students.items() if s[0] >=h and s[1] >=w} return result ",MBPP_721 722,Write a function to count the same pair in two given lists using map function.,"from operator import eq def count_same_pair(nums1, nums2): result = sum(map(eq, nums1, nums2)) return result",MBPP_722 723,Write a function to calculate the sum of all digits of the base to the specified power.,"def power_base_sum(base, power): return sum([int(i) for i in str(pow(base, power))])",MBPP_723 724,Write a function to extract values between quotation marks of the given string by using regex.,"import re def extract_quotation(text1): return (re.findall(r'""(.*?)""', text1))",MBPP_724 725,Write a function to multiply the adjacent elements of the given tuple.,"def multiply_elements(test_tup): res = tuple(i * j for i, j in zip(test_tup, test_tup[1:])) return (res) ",MBPP_725 726,Write a function to remove all characters except letters and numbers using regex,"import re def remove_char(S): result = re.sub('[\W_]+', '', S) return result",MBPP_726 727,Write a function to sum elements in two lists.,"def sum_list(lst1,lst2): res_list = [lst1[i] + lst2[i] for i in range(len(lst1))] return res_list",MBPP_727 728,Write a function to add two lists using map and lambda function.,"def add_list(nums1,nums2): result = map(lambda x, y: x + y, nums1, nums2) return list(result)",MBPP_728 729,Write a function to remove consecutive duplicates of a given list.,"from itertools import groupby def consecutive_duplicates(nums): return [key for key, group in groupby(nums)] ",MBPP_729 730,Write a function to find the lateral surface area of a cone.,"import math def lateralsurface_cone(r,h): l = math.sqrt(r * r + h * h) LSA = math.pi * r * l return LSA",MBPP_730 731,"Write a function to replace all occurrences of spaces, commas, or dots with a colon.","import re def replace_specialchar(text): return (re.sub(""[ ,.]"", "":"", text)) ",MBPP_731 732,Write a function to find the index of the first occurrence of a given number in a sorted array.,"def find_first_occurrence(A, x): (left, right) = (0, len(A) - 1) result = -1 while left <= right: mid = (left + right) // 2 if x == A[mid]: result = mid right = mid - 1 elif x < A[mid]: right = mid - 1 else: left = mid + 1 return result",MBPP_732 733,Write a python function to find sum of products of all possible subarrays.,"def sum_Of_Subarray_Prod(arr,n): ans = 0 res = 0 i = n - 1 while (i >= 0): incr = arr[i]*(1 + res) ans += incr res = incr i -= 1 return (ans)",MBPP_733 734,Write a python function to toggle bits of the number except the first and the last bit.,"def set_middle_bits(n): n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; return (n >> 1) ^ 1 def toggle_middle_bits(n): if (n == 1): return 1 return n ^ set_middle_bits(n) ",MBPP_734 735,Write a function to locate the left insertion point for a specified value in sorted order.,"import bisect def left_insertion(a, x): i = bisect.bisect_left(a, x) return i",MBPP_735 736,Write a function to check whether the given string is starting with a vowel or not using regex.,"import re regex = '^[aeiouAEIOU][A-Za-z0-9_]*' def check_str(string): if(re.search(regex, string)): return (""Valid"") else: return (""Invalid"") ",MBPP_736 737,Write a function to calculate the geometric sum of n-1.,"def geometric_sum(n): if n < 0: return 0 else: return 1 / (pow(2, n)) + geometric_sum(n - 1)",MBPP_737 738,Write a python function to find the index of smallest triangular number with n digits.,"import math def find_Index(n): x = math.sqrt(2 * math.pow(10,(n - 1))); return round(x); ",MBPP_738 739,Write a function to convert the given tuple to a key-value dictionary using adjacent elements.,"def tuple_to_dict(test_tup): res = dict(test_tup[idx : idx + 2] for idx in range(0, len(test_tup), 2)) return (res) ",MBPP_739 740,Write a python function to check whether all the characters are same or not.,"def all_Characters_Same(s) : n = len(s) for i in range(1,n) : if s[i] != s[0] : return False return True",MBPP_740 741,Write a function to caluclate the area of a tetrahedron.,"import math def area_tetrahedron(side): area = math.sqrt(3)*(side*side) return area",MBPP_741 742,Write a function to rotate a given list by specified number of items to the right direction.,"def rotate_right(list1,m,n): result = list1[-(m):]+list1[:-(n)] return result",MBPP_742 743,Write a function to check if the given tuple has any none value or not.,"def check_none(test_tup): res = any(map(lambda ele: ele is None, test_tup)) return (res) ",MBPP_743 744,Write a function to find numbers within a given range where every number is divisible by every digit it contains.,"def divisible_by_digits(startnum, endnum): return [n for n in range(startnum, endnum+1) \ if not any(map(lambda x: int(x) == 0 or n%int(x) != 0, str(n)))]",MBPP_744 745,Write a function to find area of a sector.,"def sector_area(r,a): pi=22/7 if a >= 360: return None sectorarea = (pi*r**2) * (a/360) return sectorarea",MBPP_745 746,Write a function to find the longest common subsequence for the given three string sequence.,"def lcs_of_three(X, Y, Z, m, n, o): L = [[[0 for i in range(o+1)] for j in range(n+1)] for k in range(m+1)] for i in range(m+1): for j in range(n+1): for k in range(o+1): if (i == 0 or j == 0 or k == 0): L[i][j][k] = 0 elif (X[i-1] == Y[j-1] and X[i-1] == Z[k-1]): L[i][j][k] = L[i-1][j-1][k-1] + 1 else: L[i][j][k] = max(max(L[i-1][j][k], L[i][j-1][k]), L[i][j][k-1]) return L[m][n][o]",MBPP_746 747,Write a function to put spaces between words starting with capital letters in a given string by using regex.,"import re def capital_words_spaces(str1): return re.sub(r""(\w)([A-Z])"", r""\1 \2"", str1)",MBPP_747 748,Write a function to sort a given list of strings of numbers numerically.,"def sort_numeric_strings(nums_str): result = [int(x) for x in nums_str] result.sort() return result",MBPP_748 749,Write a function to add the given tuple to the given list.,"def add_tuple(test_list, test_tup): test_list += test_tup return (test_list) ",MBPP_749 750,Write a function to check if the given array represents min heap or not.,"def check_min_heap(arr, i): if 2 * i + 2 > len(arr): return True left_child = (arr[i] <= arr[2 * i + 1]) and check_min_heap(arr, 2 * i + 1) right_child = (2 * i + 2 == len(arr)) or (arr[i] <= arr[2 * i + 2] and check_min_heap(arr, 2 * i + 2)) return left_child and right_child",MBPP_750 751,Write a function to find the nth jacobsthal number.,"def jacobsthal_num(n): dp = [0] * (n + 1) dp[0] = 0 dp[1] = 1 for i in range(2, n+1): dp[i] = dp[i - 1] + 2 * dp[i - 2] return dp[n]",MBPP_751 752,Write a function to find minimum k records from tuple list.,"def min_k(test_list, K): res = sorted(test_list, key = lambda x: x[1])[:K] return (res) ",MBPP_752 753,Write a function to find common index elements from three lists.,"def extract_index_list(l1, l2, l3): result = [] for m, n, o in zip(l1, l2, l3): if (m == n == o): result.append(m) return result",MBPP_753 754,Write a function to find the second smallest number in a list.,"def second_smallest(numbers): if (len(numbers)<2): return if ((len(numbers)==2) and (numbers[0] == numbers[1]) ): return dup_items = set() uniq_items = [] for x in numbers: if x not in dup_items: uniq_items.append(x) dup_items.add(x) uniq_items.sort() return uniq_items[1] ",MBPP_754 755,Write a function that matches a string that has an a followed by zero or one 'b'.,"import re def text_match_zero_one(text): patterns = 'ab?' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')",MBPP_755 756,Write a function to count the pairs of reverse strings in the given string list.,"def count_reverse_pairs(test_list): res = sum([1 for idx in range(0, len(test_list)) for idxn in range(idx, len( test_list)) if test_list[idxn] == str(''.join(list(reversed(test_list[idx]))))]) return str(res)",MBPP_756 757,Write a function to count number of unique lists within a list.,"def unique_sublists(list1): result ={} for l in list1: result.setdefault(tuple(l), list()).append(1) for a, b in result.items(): result[a] = sum(b) return result",MBPP_757 758,Write a function to check a decimal with a precision of 2.,"def is_decimal(num): import re dnumre = re.compile(r""""""^[0-9]+(\.[0-9]{1,2})?$"""""") result = dnumre.search(num) return bool(result)",MBPP_758 759,Write a python function to check whether an array contains only one distinct element or not.,"def unique_Element(arr,n): s = set(arr) if (len(s) == 1): return ('YES') else: return ('NO')",MBPP_759 760,Write a function to caluclate arc length of an angle.,"def arc_length(d,a): pi=22/7 if a >= 360: return None arclength = (pi*d) * (a/360) return arclength",MBPP_760 761,Write a function to check whether the given month number contains 30 days or not.,"def check_monthnumber_number(monthnum3): if(monthnum3==4 or monthnum3==6 or monthnum3==9 or monthnum3==11): return True else: return False",MBPP_761 762,Write a python function to find the minimum difference between any two elements in a given array.,"def find_Min_Diff(arr,n): arr = sorted(arr) diff = 10**20 for i in range(n-1): if arr[i+1] - arr[i] < diff: diff = arr[i+1] - arr[i] return diff ",MBPP_762 763,Write a python function to count numeric values in a given string.,"def number_ctr(str): number_ctr= 0 for i in range(len(str)): if str[i] >= '0' and str[i] <= '9': number_ctr += 1 return number_ctr",MBPP_763 764,Write a function to find nth polite number.,"import math def is_polite(n): n = n + 1 return (int)(n+(math.log((n + math.log(n, 2)), 2))) ",MBPP_764 765,Write a function to iterate over all pairs of consecutive items in a given list.,"def pair_wise(l1): temp = [] for i in range(len(l1) - 1): current_element, next_element = l1[i], l1[i + 1] x = (current_element, next_element) temp.append(x) return temp",MBPP_765 766,Write a python function to count the number of pairs whose sum is equal to ‘sum’.,"def get_Pairs_Count(arr,n,sum): count = 0 for i in range(0,n): for j in range(i + 1,n): if arr[i] + arr[j] == sum: count += 1 return count",MBPP_766 767,Write a python function to check for odd parity of a given number.,"def check_Odd_Parity(x): parity = 0 while (x != 0): x = x & (x - 1) parity += 1 if (parity % 2 == 1): return True else: return False",MBPP_767 768,Write a python function to get the difference between two lists.,"def Diff(li1,li2): return (list(list(set(li1)-set(li2)) + list(set(li2)-set(li1)))) ",MBPP_768 769,Write a python function to find the sum of fourth power of first n odd natural numbers.,"def odd_Num_Sum(n) : j = 0 sm = 0 for i in range(1,n + 1) : j = (2*i-1) sm = sm + (j*j*j*j) return sm ",MBPP_769 770,Write a function to check if the given expression is balanced or not.,"from collections import deque def check_expression(exp): if len(exp) & 1: return False stack = deque() for ch in exp: if ch == '(' or ch == '{' or ch == '[': stack.append(ch) if ch == ')' or ch == '}' or ch == ']': if not stack: return False top = stack.pop() if (top == '(' and ch != ')') or (top == '{' and ch != '}' or (top == '[' and ch != ']')): return False return not stack",MBPP_770 771,Write a function to remove all the words with k length in the given string.,"def remove_length(test_str, K): temp = test_str.split() res = [ele for ele in temp if len(ele) != K] res = ' '.join(res) return (res) ",MBPP_771 772,Write a function to find the occurrence and position of the substrings within a string.,"import re def occurance_substring(text,pattern): for match in re.finditer(pattern, text): s = match.start() e = match.end() return (text[s:e], s, e)",MBPP_772 773,Write a function to check if the string is a valid email address or not using regex.,"import re regex = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$' def check_email(email): if(re.search(regex,email)): return (""Valid Email"") else: return (""Invalid Email"") ",MBPP_773 774,Write a python function to check whether every odd index contains odd numbers of a given list.,"def odd_position(nums): return all(nums[i]%2==i%2 for i in range(len(nums)))",MBPP_774 775,Write a function to count those characters which have vowels as their neighbors in the given string.,"def count_vowels(test_str): res = 0 vow_list = ['a', 'e', 'i', 'o', 'u'] for idx in range(1, len(test_str) - 1): if test_str[idx] not in vow_list and (test_str[idx - 1] in vow_list or test_str[idx + 1] in vow_list): res += 1 if test_str[0] not in vow_list and test_str[1] in vow_list: res += 1 if test_str[-1] not in vow_list and test_str[-2] in vow_list: res += 1 return (res) ",MBPP_775 776,Write a python function to find the sum of non-repeated elements in a given array.,"def find_Sum(arr,n): arr.sort() sum = arr[0] for i in range(0,n-1): if (arr[i] != arr[i+1]): sum = sum + arr[i+1] return sum",MBPP_776 777,Write a function to pack consecutive duplicates of a given list elements into sublists.,"from itertools import groupby def pack_consecutive_duplicates(list1): return [list(group) for key, group in groupby(list1)]",MBPP_777 778,Write a function to count the number of unique lists within a list.,"def unique_sublists(list1): result ={} for l in list1: result.setdefault(tuple(l), list()).append(1) for a, b in result.items(): result[a] = sum(b) return result",MBPP_778 779,Write a function to find the combinations of sums with tuples in the given tuple list.,"from itertools import combinations def find_combinations(test_list): res = [(b1 + a1, b2 + a2) for (a1, a2), (b1, b2) in combinations(test_list, 2)] return (res) ",MBPP_779 780,Write a python function to check whether the count of divisors is even or odd.,"import math def count_Divisors(n) : count = 0 for i in range(1, (int)(math.sqrt(n)) + 2) : if (n % i == 0) : if( n // i == i) : count = count + 1 else : count = count + 2 if (count % 2 == 0) : return (""Even"") else : return (""Odd"") ",MBPP_780 781,Write a python function to find the sum of all odd length subarrays.,"def Odd_Length_Sum(arr): Sum = 0 l = len(arr) for i in range(l): Sum += ((((i + 1) *(l - i) + 1) // 2) * arr[i]) return Sum",MBPP_781 782,Write a function to convert rgb color to hsv color.,"def rgb_to_hsv(r, g, b): r, g, b = r/255.0, g/255.0, b/255.0 mx = max(r, g, b) mn = min(r, g, b) df = mx-mn if mx == mn: h = 0 elif mx == r: h = (60 * ((g-b)/df) + 360) % 360 elif mx == g: h = (60 * ((b-r)/df) + 120) % 360 elif mx == b: h = (60 * ((r-g)/df) + 240) % 360 if mx == 0: s = 0 else: s = (df/mx)*100 v = mx*100 return h, s, v",MBPP_782 783,Write a function to find the product of first even and odd number of a given list.,"def mul_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el for el in list1 if el%2!=0),-1) return (first_even*first_odd)",MBPP_783 784,Write a function to convert tuple string to integer tuple.,"def tuple_str_int(test_str): res = tuple(int(num) for num in test_str.replace('(', '').replace(')', '').replace('...', '').split(', ')) return (res) ",MBPP_784 785,Write a function to locate the right insertion point for a specified value in sorted order.,"import bisect def right_insertion(a, x): i = bisect.bisect_right(a, x) return i",MBPP_785 786,Write a function that matches a string that has an a followed by three 'b'.,"import re def text_match_three(text): patterns = 'ab{3}?' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')",MBPP_786 787,Write a function to create a new tuple from the given string and list.,"def new_tuple(test_list, test_str): res = tuple(test_list + [test_str]) return (res) ",MBPP_787 788,Write a function to calculate the perimeter of a regular polygon.,"from math import tan, pi def perimeter_polygon(s,l): perimeter = s*l return perimeter",MBPP_788 789,Write a python function to check whether every even index contains even numbers of a given list.,"def even_position(nums): return all(nums[i]%2==i%2 for i in range(len(nums)))",MBPP_789 790,Write a function to remove the nested record from the given tuple.,"def remove_nested(test_tup): res = tuple() for count, ele in enumerate(test_tup): if not isinstance(ele, tuple): res = res + (ele, ) return (res) ",MBPP_790 791,Write a python function to count the number of lists in a given number of lists.,"def count_list(input_list): return len(input_list)",MBPP_791 792,Write a python function to find the last position of an element in a sorted array.,"def last(arr,x,n): low = 0 high = n - 1 res = -1 while (low <= high): mid = (low + high) // 2 if arr[mid] > x: high = mid - 1 elif arr[mid] < x: low = mid + 1 else: res = mid low = mid + 1 return res",MBPP_792 793,"Write a function that matches a string that has an 'a' followed by anything, ending in 'b'.","import re def text_starta_endb(text): patterns = 'a.*?b$' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')",MBPP_793 794,Write a function to find the n - cheap price items from a given dataset using heap queue algorithm.,"import heapq def cheap_items(items,n): cheap_items = heapq.nsmallest(n, items, key=lambda s: s['price']) return cheap_items",MBPP_794 795,Write function to find the sum of all items in the given dictionary.,"def return_sum(dict): sum = 0 for i in dict.values(): sum = sum + i return sum",MBPP_795 796,Write a python function to find the sum of all odd natural numbers within the range l and r.,"def sum_Odd(n): terms = (n + 1)//2 sum1 = terms * terms return sum1 def sum_in_Range(l,r): return sum_Odd(r) - sum_Odd(l - 1)",MBPP_796 797,Write a python function to find the sum of an array.,"def _sum(arr): sum=0 for i in arr: sum = sum + i return(sum) ",MBPP_797 798,Write a python function to left rotate the bits of a given number.,"INT_BITS = 32 def left_Rotate(n,d): return (n << d)|(n >> (INT_BITS - d)) ",MBPP_798 799,Write a function to remove all whitespaces from a string.,"import re def remove_all_spaces(text): return (re.sub(r'\s+', '',text))",MBPP_799 800,Write a python function to count the number of equal numbers from three given integers.,"def test_three_equal(x,y,z): result= set([x,y,z]) if len(result)==3: return 0 else: return (4-len(result))",MBPP_800 801,Write a python function to count the number of rotations required to generate a sorted array.,"def count_Rotation(arr,n): for i in range (1,n): if (arr[i] < arr[i - 1]): return i return 0",MBPP_801 802,Write a python function to check whether the given number is a perfect square or not.,"def is_Perfect_Square(n) : i = 1 while (i * i<= n): if ((n % i == 0) and (n / i == i)): return True i = i + 1 return False",MBPP_802 803,Write a python function to check whether the product of numbers is even or not.,"def is_Product_Even(arr,n): for i in range(0,n): if ((arr[i] & 1) == 0): return True return False",MBPP_803 804,Write a function to find the list in a list of lists whose sum of elements is the highest.,"def max_sum_list(lists): return max(lists, key=sum)",MBPP_804 805,Write a function to find maximum run of uppercase characters in the given string.,"def max_run_uppercase(test_str): cnt = 0 res = 0 for idx in range(0, len(test_str)): if test_str[idx].isupper(): cnt += 1 else: res = cnt cnt = 0 if test_str[len(test_str) - 1].isupper(): res = cnt return (res)",MBPP_805 806,Write a python function to find the first odd number in a given list of numbers.,"def first_odd(nums): first_odd = next((el for el in nums if el%2!=0),-1) return first_odd",MBPP_806 807,Write a function to check if the given tuples contain the k or not.,"def check_K(test_tup, K): res = False for ele in test_tup: if ele == K: res = True break return (res) ",MBPP_807 808,Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple.,"def check_smaller(test_tup1, test_tup2): res = all(x > y for x, y in zip(test_tup1, test_tup2)) return (res) ",MBPP_808 809,Write a function to iterate over elements repeating each as many times as its count.,"from collections import Counter def count_variable(a,b,c,d): c = Counter(p=a, q=b, r=c, s=d) return list(c.elements())",MBPP_809 810,Write a function to check if two lists of tuples are identical or not.,"def check_identical(test_list1, test_list2): res = test_list1 == test_list2 return (res) ",MBPP_810 811,Write a function to abbreviate 'road' as 'rd.' in a given string.,"import re def road_rd(street): return (re.sub('Road$', 'Rd.', street))",MBPP_811 812,Write a function to find length of the string.,"def string_length(str1): count = 0 for char in str1: count += 1 return count",MBPP_812 813,Write a function to find the area of a rombus.,"def rombus_area(p,q): area=(p*q)/2 return area",MBPP_813 814,"Write a function to sort the given array without using any sorting algorithm. the given array consists of only 0, 1, and 2.","def sort_by_dnf(arr, n): low=0 mid=0 high=n-1 while mid <= high: if arr[mid] == 0: arr[low], arr[mid] = arr[mid], arr[low] low = low + 1 mid = mid + 1 elif arr[mid] == 1: mid = mid + 1 else: arr[mid], arr[high] = arr[high], arr[mid] high = high - 1 return arr",MBPP_814 815,Write a function to clear the values of the given tuples.,"def clear_tuple(test_tup): temp = list(test_tup) temp.clear() test_tup = tuple(temp) return (test_tup) ",MBPP_815 816,Write a function to find numbers divisible by m or n from a list of numbers using lambda function.,"def div_of_nums(nums,m,n): result = list(filter(lambda x: (x % m == 0 or x % n == 0), nums)) return result",MBPP_816 817,Write a python function to count lower case letters in a given string.,"def lower_ctr(str): lower_ctr= 0 for i in range(len(str)): if str[i] >= 'a' and str[i] <= 'z': lower_ctr += 1 return lower_ctr",MBPP_817 818,Write a function to count the frequency of consecutive duplicate elements in a given list of numbers.,"def count_duplic(lists): element = [] frequency = [] if not lists: return element running_count = 1 for i in range(len(lists)-1): if lists[i] == lists[i+1]: running_count += 1 else: frequency.append(running_count) element.append(lists[i]) running_count = 1 frequency.append(running_count) element.append(lists[i+1]) return element,frequency ",MBPP_818 819,Write a function to check whether the given month number contains 28 days or not.,"def check_monthnum_number(monthnum1): if monthnum1 == 2: return True else: return False",MBPP_819 820,Write a function to merge two dictionaries into a single expression.,"import collections as ct def merge_dictionaries(dict1,dict2): merged_dict = dict(ct.ChainMap({}, dict1, dict2)) return merged_dict",MBPP_820 821,Write a function to return true if the password is valid.,"import re def pass_validity(p): x = True while x: if (len(p)<6 or len(p)>12): break elif not re.search(""[a-z]"",p): break elif not re.search(""[0-9]"",p): break elif not re.search(""[A-Z]"",p): break elif not re.search(""[$#@]"",p): break elif re.search(""\s"",p): break else: return True x=False break if x: return False",MBPP_821 822,Write a function to check if the given string starts with a substring using regex.,"import re def check_substring(string, sample) : if (sample in string): y = ""\A"" + sample x = re.search(y, string) if x : return (""string starts with the given substring"") else : return (""string doesnt start with the given substring"") else : return (""entered string isnt a substring"")",MBPP_822 823,Write a python function to remove even numbers from a given list.,"def remove_even(l): for i in l: if i % 2 == 0: l.remove(i) return l",MBPP_823 824,Write a python function to access multiple elements of specified index from a given list.,"def access_elements(nums, list_index): result = [nums[i] for i in list_index] return result",MBPP_824 825,Write a python function to find the type of triangle from the given sides.,"def check_Type_Of_Triangle(a,b,c): sqa = pow(a,2) sqb = pow(b,2) sqc = pow(c,2) if (sqa == sqa + sqb or sqb == sqa + sqc or sqc == sqa + sqb): return (""Right-angled Triangle"") elif (sqa > sqc + sqb or sqb > sqa + sqc or sqc > sqa + sqb): return (""Obtuse-angled Triangle"") else: return (""Acute-angled Triangle"") ",MBPP_825 826,Write a function to sum a specific column of a list in a given list of lists.,"def sum_column(list1, C): result = sum(row[C] for row in list1) return result",MBPP_826 827,"Write a function to count alphabets,digits and special charactes in a given string.","def count_alpha_dig_spl(string): alphabets=digits = special = 0 for i in range(len(string)): if(string[i].isalpha()): alphabets = alphabets + 1 elif(string[i].isdigit()): digits = digits + 1 else: special = special + 1 return (alphabets,digits,special) ",MBPP_827 828,Write a function to find out the second most repeated (or frequent) string in the given sequence.,"from collections import Counter def second_frequent(input): dict = Counter(input) value = sorted(dict.values(), reverse=True) second_large = value[1] for (key, val) in dict.items(): if val == second_large: return (key) ",MBPP_828 829,Write a function to round up a number to specific digits.,"import math def round_up(a, digits): n = 10**-digits return round(math.ceil(a / n) * n, digits)",MBPP_829 830,Write a python function to count equal element pairs from the given array.,"def count_Pairs(arr,n): cnt = 0; for i in range(n): for j in range(i + 1,n): if (arr[i] == arr[j]): cnt += 1; return cnt; ",MBPP_830 831,Write a function to extract the maximum numeric value from a string by using regex.,"import re def extract_max(input): numbers = re.findall('\d+',input) numbers = map(int,numbers) return max(numbers)",MBPP_831 832,Write a function to get dictionary keys as a list.,"def get_key(dict): list = [] for key in dict.keys(): list.append(key) return list",MBPP_832 833,Write a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order.,"def generate_matrix(n): if n<=0: return [] matrix=[row[:] for row in [[0]*n]*n] row_st=0 row_ed=n-1 col_st=0 col_ed=n-1 current=1 while (True): if current>n*n: break for c in range (col_st, col_ed+1): matrix[row_st][c]=current current+=1 row_st+=1 for r in range (row_st, row_ed+1): matrix[r][col_ed]=current current+=1 col_ed-=1 for c in range (col_ed, col_st-1, -1): matrix[row_ed][c]=current current+=1 row_ed-=1 for r in range (row_ed, row_st-1, -1): matrix[r][col_st]=current current+=1 col_st+=1 return matrix",MBPP_833 834,Write a python function to find the slope of a line.,"def slope(x1,y1,x2,y2): return (float)(y2-y1)/(x2-x1) ",MBPP_834 835,Write a function to find length of the subarray having maximum sum.,"from sys import maxsize def max_sub_array_sum(a,size): max_so_far = -maxsize - 1 max_ending_here = 0 start = 0 end = 0 s = 0 for i in range(0,size): max_ending_here += a[i] if max_so_far < max_ending_here: max_so_far = max_ending_here start = s end = i if max_ending_here < 0: max_ending_here = 0 s = i+1 return (end - start + 1)",MBPP_835 836,Write a python function to find the cube sum of first n odd natural numbers.,"def cube_Sum(n): sum = 0 for i in range(0,n) : sum += (2*i+1)*(2*i+1)*(2*i+1) return sum",MBPP_836 837,Write a python function to find minimum number swaps required to make two binary strings equal.,"def min_Swaps(s1,s2) : c0 = 0; c1 = 0; for i in range(len(s1)) : if (s1[i] == '0' and s2[i] == '1') : c0 += 1; elif (s1[i] == '1' and s2[i] == '0') : c1 += 1; result = c0 // 2 + c1 // 2; if (c0 % 2 == 0 and c1 % 2 == 0) : return result; elif ((c0 + c1) % 2 == 0) : return result + 2; else : return -1; ",MBPP_837 838,Write a function to sort the tuples alphabetically by the first item of each tuple.,"def sort_tuple(tup): n = len(tup) for i in range(n): for j in range(n-i-1): if tup[j][0] > tup[j + 1][0]: tup[j], tup[j + 1] = tup[j + 1], tup[j] return tup",MBPP_838 839,Write a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not.,"def Check_Solution(a,b,c): if b == 0: return (""Yes"") else: return (""No"") ",MBPP_839 840,Write a function to count the number of inversions in the given array.,"def get_inv_count(arr, n): inv_count = 0 for i in range(n): for j in range(i + 1, n): if (arr[i] > arr[j]): inv_count += 1 return inv_count ",MBPP_840 841,Write a function to find the number which occurs for odd number of times in the given array.,"def get_odd_occurence(arr, arr_size): for i in range(0, arr_size): count = 0 for j in range(0, arr_size): if arr[i] == arr[j]: count += 1 if (count % 2 != 0): return arr[i] return -1",MBPP_841 842,Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm.,"import heapq def nth_super_ugly_number(n, primes): uglies = [1] def gen(prime): for ugly in uglies: yield ugly * prime merged = heapq.merge(*map(gen, primes)) while len(uglies) < n: ugly = next(merged) if ugly != uglies[-1]: uglies.append(ugly) return uglies[-1]",MBPP_842 843,Write a python function to find the kth element in an array containing odd elements first and then even elements.,"def get_Number(n, k): arr = [0] * n; i = 0; odd = 1; while (odd <= n): arr[i] = odd; i += 1; odd += 2; even = 2; while (even <= n): arr[i] = even; i += 1; even += 2; return arr[k - 1]; ",MBPP_843 844,Write a python function to count the number of digits in factorial of a given number.,"import math def find_Digits(n): if (n < 0): return 0; if (n <= 1): return 1; x = ((n * math.log10(n / math.e) + math.log10(2 * math.pi * n) /2.0)); return math.floor(x) + 1; ",MBPP_844 845,Write a function to find the minimum number of platforms required for a railway/bus station.,"def find_platform(arr, dep, n): arr.sort() dep.sort() plat_needed = 1 result = 1 i = 1 j = 0 while (i < n and j < n): if (arr[i] <= dep[j]): plat_needed+= 1 i+= 1 elif (arr[i] > dep[j]): plat_needed-= 1 j+= 1 if (plat_needed > result): result = plat_needed return result",MBPP_845 846,Write a python function to copy a list from a singleton tuple.,"def lcopy(xs): return xs[:] ",MBPP_846 847,Write a function to find the area of a trapezium.,"def area_trapezium(base1,base2,height): area = 0.5 * (base1 + base2) * height return area",MBPP_847 848,Write a python function to find sum of all prime divisors of a given number.,"def Sum(N): SumOfPrimeDivisors = [0]*(N + 1) for i in range(2,N + 1) : if (SumOfPrimeDivisors[i] == 0) : for j in range(i,N + 1,i) : SumOfPrimeDivisors[j] += i return SumOfPrimeDivisors[N] ",MBPP_848 849,Write a function to check if a triangle of positive area is possible with the given angles.,"def is_triangleexists(a,b,c): if(a != 0 and b != 0 and c != 0 and (a + b + c)== 180): if((a + b)>= c or (b + c)>= a or (a + c)>= b): return True else: return False else: return False",MBPP_849 850,Write a python function to find sum of inverse of divisors.,"def Sum_of_Inverse_Divisors(N,Sum): ans = float(Sum)*1.0 /float(N); return round(ans,2); ",MBPP_850 851,Write a python function to remove negative numbers from a list.,"def remove_negs(num_list): for item in num_list: if item < 0: num_list.remove(item) return num_list",MBPP_851 852,Write a python function to find sum of odd factors of a number.,"import math def sum_of_odd_Factors(n): res = 1 while n % 2 == 0: n = n // 2 for i in range(3,int(math.sqrt(n) + 1)): count = 0 curr_sum = 1 curr_term = 1 while n % i == 0: count+=1 n = n // i curr_term *= i curr_sum += curr_term res *= curr_sum if n >= 2: res *= (1 + n) return res ",MBPP_852 853,Write a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm.,"import heapq as hq def raw_heap(rawheap): hq.heapify(rawheap) return rawheap",MBPP_853 854,Write a python function to check for even parity of a given number.,"def check_Even_Parity(x): parity = 0 while (x != 0): x = x & (x - 1) parity += 1 if (parity % 2 == 0): return True else: return False",MBPP_854 855,Write a python function to find minimum adjacent swaps required to sort binary array.,"def find_Min_Swaps(arr,n) : noOfZeroes = [0] * n count = 0 noOfZeroes[n - 1] = 1 - arr[n - 1] for i in range(n-2,-1,-1) : noOfZeroes[i] = noOfZeroes[i + 1] if (arr[i] == 0) : noOfZeroes[i] = noOfZeroes[i] + 1 for i in range(0,n) : if (arr[i] == 1) : count = count + noOfZeroes[i] return count ",MBPP_855 856,Write a function to list out the list of given strings individually using map function.,"def listify_list(list1): result = list(map(list,list1)) return result ",MBPP_856 857,Write a function to count number of lists in a given list of lists and square the count.,"def count_list(input_list): return (len(input_list))**2",MBPP_857 858,Write a function to generate all sublists of a given list.,"from itertools import combinations def sub_lists(my_list): subs = [] for i in range(0, len(my_list)+1): temp = [list(x) for x in combinations(my_list, i)] if len(temp)>0: subs.extend(temp) return subs",MBPP_858 859,Write a function to check whether the given string is ending with only alphanumeric characters or not using regex.,"import re regex = '[a-zA-z0-9]$' def check_alphanumeric(string): if(re.search(regex, string)): return (""Accept"") else: return (""Discard"") ",MBPP_859 860,Write a function to find all anagrams of a string in a given list of strings using lambda function.,"from collections import Counter def anagram_lambda(texts,str): result = list(filter(lambda x: (Counter(str) == Counter(x)), texts)) return result",MBPP_860 861,Write a function to find the occurrences of n most common words in a given text.,"from collections import Counter import re def n_common_words(text,n): words = re.findall('\w+',text) n_common_words= Counter(words).most_common(n) return list(n_common_words)",MBPP_861 862,Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.,"def find_longest_conseq_subseq(arr, n): ans = 0 count = 0 arr.sort() v = [] v.append(arr[0]) for i in range(1, n): if (arr[i] != arr[i - 1]): v.append(arr[i]) for i in range(len(v)): if (i > 0 and v[i] == v[i - 1] + 1): count += 1 else: count = 1 ans = max(ans, count) return ans ",MBPP_862 863,Write a function to find palindromes in a given list of strings using lambda function.,"def palindrome_lambda(texts): result = list(filter(lambda x: (x == """".join(reversed(x))), texts)) return result",MBPP_863 864,Write a function to print n-times a list using map function.,"def ntimes_list(nums,n): result = map(lambda x:n*x, nums) return list(result)",MBPP_864 865,Write a function to check whether the given month name contains 31 days or not.,"def check_monthnumb(monthname2): if(monthname2==""January"" or monthname2==""March""or monthname2==""May"" or monthname2==""July"" or monthname2==""Augest"" or monthname2==""October"" or monthname2==""December""): return True else: return False",MBPP_865 866,Write a python function to add a minimum number such that the sum of array becomes even.,"def min_Num(arr,n): odd = 0 for i in range(n): if (arr[i] % 2): odd += 1 if (odd % 2): return 1 return 2",MBPP_866 867,Write a python function to find the length of the last word in a given string.,"def length_Of_Last_Word(a): l = 0 x = a.strip() for i in range(len(x)): if x[i] == "" "": l = 0 else: l += 1 return l ",MBPP_867 868,"Write a function to remove sublists from a given list of lists, which are outside a given range.","def remove_list_range(list1, leftrange, rigthrange): result = [i for i in list1 if (min(i)>=leftrange and max(i)<=rigthrange)] return result",MBPP_868 869,Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.,"def sum_positivenum(nums): sum_positivenum = list(filter(lambda nums:nums>0,nums)) return sum(sum_positivenum)",MBPP_869 870,Write a python function to check whether the given strings are rotations of each other or not.,"def are_Rotations(string1,string2): size1 = len(string1) size2 = len(string2) temp = '' if size1 != size2: return False temp = string1 + string1 if (temp.count(string2)> 0): return True else: return False",MBPP_870 871,Write a function to check if a nested list is a subset of another nested list.,"def check_subset(list1,list2): return all(map(list1.__contains__,list2)) ",MBPP_871 872,Write a function to solve the fibonacci sequence using recursion.,"def fibonacci(n): if n == 1 or n == 2: return 1 else: return (fibonacci(n - 1) + (fibonacci(n - 2)))",MBPP_872 873,Write a python function to check if the string is a concatenation of another string.,"def check_Concat(str1,str2): N = len(str1) M = len(str2) if (N % M != 0): return False for i in range(N): if (str1[i] != str2[i % M]): return False return True",MBPP_873 874,Write a function to find the minimum difference in the tuple pairs of given tuples.,"def min_difference(test_list): temp = [abs(b - a) for a, b in test_list] res = min(temp) return (res) ",MBPP_874 875,Write a python function to find lcm of two positive integers.,"def lcm(x, y): if x > y: z = x else: z = y while(True): if((z % x == 0) and (z % y == 0)): lcm = z break z += 1 return lcm",MBPP_875 876,Write a python function to sort the given string.,"def sort_String(str) : str = ''.join(sorted(str)) return (str) ",MBPP_876 877,Write a function to check if the given tuple contains only k elements.,"def check_tuples(test_tuple, K): res = all(ele in K for ele in test_tuple) return (res) ",MBPP_877 878,"Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex.","import re def text_match(text): patterns = 'a.*?b$' if re.search(patterns, text): return ('Found a match!') else: return ('Not matched!')",MBPP_878 879,Write a python function to find number of solutions in quadratic equation.,"def Check_Solution(a,b,c) : if ((b*b) - (4*a*c)) > 0 : return (""2 solutions"") elif ((b*b) - (4*a*c)) == 0 : return (""1 solution"") else : return (""No solutions"") ",MBPP_879 880,Write a function to find the sum of first even and odd number of a given list.,"def sum_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el for el in list1 if el%2!=0),-1) return (first_even+first_odd)",MBPP_880 881,Write a function to caluclate perimeter of a parallelogram.,"def parallelogram_perimeter(b,h): perimeter=2*(b*h) return perimeter",MBPP_881 882,Write a function to find numbers divisible by m and n from a list of numbers using lambda function.,"def div_of_nums(nums,m,n): result = list(filter(lambda x: (x % m == 0 and x % n == 0), nums)) return result",MBPP_882 883,Write a python function to check whether all the bits are within a given range or not.,"def all_Bits_Set_In_The_Given_Range(n,l,r): num = ((1 << r) - 1) ^ ((1 << (l - 1)) - 1) new_num = n & num if (num == new_num): return True return False",MBPP_883 884,Write a python function to check whether the two given strings are isomorphic to each other or not.,"def is_Isomorphic(str1,str2): dict_str1 = {} dict_str2 = {} for i, value in enumerate(str1): dict_str1[value] = dict_str1.get(value,[]) + [i] for j, value in enumerate(str2): dict_str2[value] = dict_str2.get(value,[]) + [j] if sorted(dict_str1.values()) == sorted(dict_str2.values()): return True else: return False",MBPP_884 885,Write a function to add all the numbers in a list and divide it with the length of the list.,"def sum_num(numbers): total = 0 for x in numbers: total += x return total/len(numbers) ",MBPP_885 886,Write a python function to check whether the given number is odd or not using bitwise operator.,"def is_odd(n) : if (n^1 == n-1) : return True; else : return False; ",MBPP_886 887,Write a function to substract the elements of the given nested tuples.,"def substract_elements(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) ",MBPP_887 888,Write a function to reverse each list in a given list of lists.,"def reverse_list_lists(lists): for l in lists: l.sort(reverse = True) return lists ",MBPP_888 889,Write a python function to find the index of an extra element present in one sorted array.,"def find_Extra(arr1,arr2,n) : for i in range(0, n) : if (arr1[i] != arr2[i]) : return i return n ",MBPP_889 890,Write a python function to check whether the given two numbers have same number of digits or not.,"def same_Length(A,B): while (A > 0 and B > 0): A = A / 10; B = B / 10; if (A == 0 and B == 0): return True; return False; ",MBPP_890 891,Write a function to remove multiple spaces in a string.,"import re def remove_spaces(text): return (re.sub(' +',' ',text))",MBPP_891 892,Write a python function to get the last element of each sublist.,"def Extract(lst): return [item[-1] for item in lst] ",MBPP_892 893,Write a function to convert the given string of float type into tuple.,"def float_to_tuple(test_str): res = tuple(map(float, test_str.split(', '))) return (res) ",MBPP_893 894,Write a function to find the maximum sum of subsequences of given array with no adjacent elements.,"def max_sum_subseq(A): n = len(A) if n == 1: return A[0] look_up = [None] * n look_up[0] = A[0] look_up[1] = max(A[0], A[1]) for i in range(2, n): look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i]) look_up[i] = max(look_up[i], A[i]) return look_up[n - 1]",MBPP_894 895,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.,"def last(n): return n[-1] def sort_list_last(tuples): return sorted(tuples, key=last)",MBPP_895 896,Write a python function to check whether the word is present in a given sentence or not.,"def is_Word_Present(sentence,word): s = sentence.split("" "") for i in s: if (i == word): return True return False",MBPP_896 897,"Write a function to extract specified number of elements from a given list, which follow each other continuously.","from itertools import groupby def extract_elements(numbers, n): result = [i for i, j in groupby(numbers) if len(list(j)) == n] return result",MBPP_897 898,Write a python function to check whether an array can be sorted or not by picking only the corner elements.,"def check(arr,n): g = 0 for i in range(1,n): if (arr[i] - arr[i - 1] > 0 and g == 1): return False if (arr[i] - arr[i] < 0): g = 1 return True",MBPP_898 899,Write a function where a string will start with a specific number.,"import re def match_num(string): text = re.compile(r""^5"") if text.match(string): return True else: return False",MBPP_899 900,Write a function to find the smallest multiple of the first n numbers.,"def smallest_multiple(n): if (n<=2): return n i = n * 2 factors = [number for number in range(n, 1, -1) if number * 2 > n] while True: for a in factors: if i % a != 0: i += n break if (a == factors[-1] and i % a == 0): return i",MBPP_900 901,Write a function to combine two dictionaries by adding values for common keys.,"from collections import Counter def add_dict(d1,d2): add_dict = Counter(d1) + Counter(d2) return add_dict",MBPP_901 902,Write a python function to count the total unset bits from 1 to n.,"def count_Unset_Bits(n) : cnt = 0; for i in range(1,n + 1) : temp = i; while (temp) : if (temp % 2 == 0) : cnt += 1; temp = temp // 2; return cnt; ",MBPP_902 903,Write a function to return true if the given number is even else return false.,"def even_num(x): if x%2==0: return True else: return False",MBPP_903 904,Write a python function to find the sum of squares of binomial co-efficients.,"def factorial(start,end): res = 1 for i in range(start,end + 1): res *= i return res def sum_of_square(n): return int(factorial(n + 1, 2 * n) /factorial(1, n)) ",MBPP_904 905,"Write a function to extract year, month and date from a url by using regex.","import re def extract_date(url): return re.findall(r'/(\d{4})/(\d{1,2})/(\d{1,2})/', url)",MBPP_905 906,Write a function to print the first n lucky numbers.,"def lucky_num(n): List=range(-1,n*n+9,2) i=2 while List[i:]:List=sorted(set(List)-set(List[List[i]::List[i]]));i+=1 return List[1:n+1]",MBPP_906 907,Write a function to find the fixed point in the given array.,"def find_fixed_point(arr, n): for i in range(n): if arr[i] is i: return i return -1",MBPP_907 908,Write a function to find the previous palindrome of a specified number.,"def previous_palindrome(num): for x in range(num-1,0,-1): if str(x) == str(x)[::-1]: return x",MBPP_908 909,Write a function to validate a gregorian date.,"import datetime def check_date(m, d, y): try: m, d, y = map(int, (m, d, y)) datetime.date(y, m, d) return True except ValueError: return False",MBPP_909 910,Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm.,"def maximum_product(nums): import heapq a, b = heapq.nlargest(3, nums), heapq.nsmallest(2, nums) return max(a[0] * a[1] * a[2], a[0] * b[0] * b[1])",MBPP_910 911,"Write a function to find ln, m lobb number.","def binomial_coeff(n, k): C = [[0 for j in range(k + 1)] for i in range(n + 1)] for i in range(0, n + 1): for j in range(0, min(i, k) + 1): if (j == 0 or j == i): C[i][j] = 1 else: C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) return C[n][k] def lobb_num(n, m): return (((2 * m + 1) * binomial_coeff(2 * n, m + n)) / (m + n + 1))",MBPP_911 912,Write a function to check for a number at the end of a string.,"import re def end_num(string): text = re.compile(r"".*[0-9]$"") if text.match(string): return True else: return False",MBPP_912 913,Write a python function to check whether the given string is made up of two alternating characters or not.,"def is_Two_Alter(s): for i in range (len( s) - 2) : if (s[i] != s[i + 2]) : return False if (s[0] == s[1]): return False return True",MBPP_913 914,Write a function to rearrange positive and negative numbers in a given array using lambda function.,"def rearrange_numbs(array_nums): result = sorted(array_nums, key = lambda i: 0 if i == 0 else -1 / i) return result ",MBPP_914 915,Write a function to find if there is a triplet in the array whose sum is equal to a given value.,"def find_triplet_array(A, arr_size, sum): for i in range( 0, arr_size-2): for j in range(i + 1, arr_size-1): for k in range(j + 1, arr_size): if A[i] + A[j] + A[k] == sum: return A[i],A[j],A[k] return True return False",MBPP_915 916,Write a function to find the sequences of one upper case letter followed by lower case letters.,"import re def text_uppercase_lowercase(text): patterns = '[A-Z]+[a-z]+$' if re.search(patterns, text): return 'Found a match!' else: return ('Not matched!')",MBPP_916 917,Write a function to count coin change.,"def coin_change(S, m, n): table = [[0 for x in range(m)] for x in range(n+1)] for i in range(m): table[0][i] = 1 for i in range(1, n+1): for j in range(m): x = table[i - S[j]][j] if i-S[j] >= 0 else 0 y = table[i][j-1] if j >= 1 else 0 table[i][j] = x + y return table[n][m-1] ",MBPP_917 918,Write a python function to multiply all items in the list.,"def multiply_list(items): tot = 1 for x in items: tot *= x return tot",MBPP_918 919,Write a function to remove all tuples with all none values in the given tuple list.,"def remove_tuple(test_list): res = [sub for sub in test_list if not all(ele == None for ele in sub)] return (str(res)) ",MBPP_919 920,Write a function to perform chunking of tuples each of size n.,"def chunk_tuples(test_tup, N): res = [test_tup[i : i + N] for i in range(0, len(test_tup), N)] return (res) ",MBPP_920 921,Write a function to find a pair with the highest product from a given array of integers.,"def max_product(arr): arr_len = len(arr) if (arr_len < 2): return None x = arr[0]; y = arr[1] for i in range(0, arr_len): for j in range(i + 1, arr_len): if (arr[i] * arr[j] > x * y): x = arr[i]; y = arr[j] return x,y ",MBPP_921 922,Write a function to find the length of the shortest string that has both str1 and str2 as subsequences.,"def super_seq(X, Y, m, n): if (not m): return n if (not n): return m if (X[m - 1] == Y[n - 1]): return 1 + super_seq(X, Y, m - 1, n - 1) return 1 + min(super_seq(X, Y, m - 1, n), super_seq(X, Y, m, n - 1))",MBPP_922 923,Write a function to find maximum of two numbers.,"def max_of_two( x, y ): if x > y: return x return y",MBPP_923 924,Write a python function to calculate the product of all the numbers of a given tuple.,"def mutiple_tuple(nums): temp = list(nums) product = 1 for x in temp: product *= x return product",MBPP_924 925,Write a function to find n-th rencontres number.,"def binomial_coeffi(n, k): if (k == 0 or k == n): return 1 return (binomial_coeffi(n - 1, k - 1) + binomial_coeffi(n - 1, k)) def rencontres_number(n, m): if (n == 0 and m == 0): return 1 if (n == 1 and m == 0): return 0 if (m == 0): return ((n - 1) * (rencontres_number(n - 1, 0)+ rencontres_number(n - 2, 0))) return (binomial_coeffi(n, m) * rencontres_number(n - m, 0))",MBPP_925 926,Write a function to calculate the height of the given binary tree.,"class Node: def __init__(self, data): self.data = data self.left = None self.right = None def max_height(node): if node is None: return 0 ; else : left_height = max_height(node.left) right_height = max_height(node.right) if (left_height > right_height): return left_height+1 else: return right_height+1",MBPP_926 927,Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.,"import re def change_date_format(dt): return re.sub(r'(\d{4})-(\d{1,2})-(\d{1,2})', '\\3-\\2-\\1', dt) return change_date_format(dt)",MBPP_927 928,Write a function to count repeated items of a tuple.,"def count_tuplex(tuplex,value): count = tuplex.count(value) return count",MBPP_928 929,Write a function that matches a string that has an a followed by zero or more b's by using regex.,"import re def text_match(text): patterns = 'ab*?' if re.search(patterns, text): return ('Found a match!') else: return ('Not matched!')",MBPP_929 930,Write a function to calculate the sum of series 1³+2³+3³+….+n³.,"import math def sum_series(number): total = 0 total = math.pow((number * (number + 1)) /2, 2) return total",MBPP_930 931,Write a function to remove duplicate words from a given list of strings.,"def remove_duplic_list(l): temp = [] for x in l: if x not in temp: temp.append(x) return temp",MBPP_931 932,Write a function to convert camel case string to snake case string by using regex.,"import re def camel_to_snake(text): str1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', text) return re.sub('([a-z0-9])([A-Z])', r'\1_\2', str1).lower()",MBPP_932 933,Write a function to find the nth delannoy number.,"def dealnnoy_num(n, m): if (m == 0 or n == 0) : return 1 return dealnnoy_num(m - 1, n) + dealnnoy_num(m - 1, n - 1) + dealnnoy_num(m, n - 1)",MBPP_933 934,Write a function to calculate the sum of series 1²+2²+3²+….+n².,"def series_sum(number): total = 0 total = (number * (number + 1) * (2 * number + 1)) / 6 return total",MBPP_934 935,Write a function to re-arrange the given tuples based on the given ordered list.,"def re_arrange_tuples(test_list, ord_list): temp = dict(test_list) res = [(key, temp[key]) for key in ord_list] return (res) ",MBPP_935 936,Write a function to count the most common character in a given string.,"from collections import Counter def max_char(str1): temp = Counter(str1) max_char = max(temp, key = temp.get) return max_char",MBPP_936 937,Write a function to find three closest elements from three sorted arrays.,"import sys def find_closet(A, B, C, p, q, r): diff = sys.maxsize res_i = 0 res_j = 0 res_k = 0 i = 0 j = 0 k = 0 while(i < p and j < q and k < r): minimum = min(A[i], min(B[j], C[k])) maximum = max(A[i], max(B[j], C[k])); if maximum-minimum < diff: res_i = i res_j = j res_k = k diff = maximum - minimum; if diff == 0: break if A[i] == minimum: i = i+1 elif B[j] == minimum: j = j+1 else: k = k+1 return A[res_i],B[res_j],C[res_k]",MBPP_937 938,Write a function to sort a list of dictionaries using lambda function.,"def sorted_models(models): sorted_models = sorted(models, key = lambda x: x['color']) return sorted_models",MBPP_938 939,Write a function to sort the given array by using heap sort.,"def heap_sort(arr): heapify(arr) end = len(arr) - 1 while end > 0: arr[end], arr[0] = arr[0], arr[end] shift_down(arr, 0, end - 1) end -= 1 return arr def heapify(arr): start = len(arr) // 2 while start >= 0: shift_down(arr, start, len(arr) - 1) start -= 1 def shift_down(arr, start, end): root = start while root * 2 + 1 <= end: child = root * 2 + 1 if child + 1 <= end and arr[child] < arr[child + 1]: child += 1 if child <= end and arr[root] < arr[child]: arr[root], arr[child] = arr[child], arr[root] root = child else: return ",MBPP_939 940,Write a function to count the elements in a list until an element is a tuple.,"def count_elim(num): count_elim = 0 for n in num: if isinstance(n, tuple): break count_elim += 1 return count_elim",MBPP_940 941,Write a function to check if any list element is present in the given list.,"def check_element(test_tup, check_list): res = False for ele in check_list: if ele in test_tup: res = True break return (res) ",MBPP_941 942,Write a function to combine two given sorted lists using heapq module.,"from heapq import merge def combine_lists(num1,num2): combine_lists=list(merge(num1, num2)) return combine_lists",MBPP_942 943,Write a function to separate and print the numbers and their position of a given string.,"import re def num_position(text): for m in re.finditer(""\d+"", text): return m.start()",MBPP_943 944,Write a function to convert the given tuples into set.,"def tuple_to_set(t): s = set(t) return (s) ",MBPP_944 945,Write a function to find the most common elements and their counts of a specified text.,"from collections import Counter def most_common_elem(s,a): most_common_elem=Counter(s).most_common(a) return most_common_elem",MBPP_945 946,Write a python function to find the length of the shortest word.,"def len_log(list1): min=len(list1[0]) for i in list1: if len(i) n- r): r = n - r 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] ",MBPP_951 952,Write a python function to find the minimun number of subsets with distinct elements.,"def subset(ar, n): res = 0 ar.sort() for i in range(0, n) : count = 1 for i in range(n - 1): if ar[i] == ar[i + 1]: count+=1 else: break res = max(res, count) return res ",MBPP_952 953,Write a function that gives profit amount if the given amount has profit else return none.,"def profit_amount(actual_cost,sale_amount): if(actual_cost > sale_amount): amount = actual_cost - sale_amount return amount else: return None",MBPP_953 954,"Write a function to find out, if the given number is abundant.","def is_abundant(n): fctrsum = sum([fctr for fctr in range(1, n) if n % fctr == 0]) return fctrsum > n",MBPP_954 955,Write a function to split the given string at uppercase letters by using regex.,"import re def split_list(text): return (re.findall('[A-Z][^A-Z]*', text))",MBPP_955 956,Write a python function to get the position of rightmost set bit.,"import math def get_First_Set_Bit_Pos(n): return math.log2(n&-n)+1",MBPP_956 957,Write a function to convert an integer into a roman numeral.,"def int_to_roman( num): val = [1000, 900, 500, 400,100, 90, 50, 40,10, 9, 5, 4,1] syb = [""M"", ""CM"", ""D"", ""CD"",""C"", ""XC"", ""L"", ""XL"",""X"", ""IX"", ""V"", ""IV"",""I""] roman_num = '' i = 0 while num > 0: for _ in range(num // val[i]): roman_num += syb[i] num -= val[i] i += 1 return roman_num",MBPP_957 958,Write a python function to find the average of a list.,"def Average(lst): return sum(lst) / len(lst) ",MBPP_958 959,Write a function to solve tiling problem.,"def get_noOfways(n): if (n == 0): return 0; if (n == 1): return 1; return get_noOfways(n - 1) + get_noOfways(n - 2);",MBPP_959 960,Write a function to convert a roman numeral to an integer.,"def roman_to_int(s): rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} int_val = 0 for i in range(len(s)): if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]: int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]] else: int_val += rom_val[s[i]] return int_val",MBPP_960 961,Write a python function to find the sum of all even natural numbers within the range l and r.,"def sum_Natural(n): sum = (n * (n + 1)) return int(sum) def sum_Even(l,r): return (sum_Natural(int(r / 2)) - sum_Natural(int((l - 1) / 2))) ",MBPP_961 962,Write a function to calculate the discriminant value.,"def discriminant_value(x,y,z): discriminant = (y**2) - (4*x*z) if discriminant > 0: return (""Two solutions"",discriminant) elif discriminant == 0: return (""one solution"",discriminant) elif discriminant < 0: return (""no real solution"",discriminant)",MBPP_962 963,Write a python function to check whether the length of the word is even or not.,"def word_len(s): s = s.split(' ') for word in s: if len(word)%2==0: return True else: return False",MBPP_963 964,Write a function to convert camel case string to snake case string.,"def camel_to_snake(text): import re str1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', text) return re.sub('([a-z0-9])([A-Z])', r'\1_\2', str1).lower()",MBPP_964 965,Write a function to remove an empty tuple from a list of tuples.,"def remove_empty(tuple1): #L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')] tuple1 = [t for t in tuple1 if t] return tuple1",MBPP_965 966,Write a python function to accept the strings which contains all vowels.,"def check(string): if len(set(string).intersection(""AEIOUaeiou""))>=5: return ('accepted') else: return (""not accepted"") ",MBPP_966 967,Write a python function to find maximum possible value for the given periodic function.,"def floor_Max(A,B,N): x = min(B - 1,N) return (A*x) // B",MBPP_967 968,Write a function to join the tuples if they have similar initial elements.,"def join_tuples(test_list): res = [] for sub in test_list: if res and res[-1][0] == sub[0]: res[-1].extend(sub[1:]) else: res.append([ele for ele in sub]) res = list(map(tuple, res)) return (res) ",MBPP_968 969,Write a function to find minimum of two numbers.,"def min_of_two( x, y ): if x < y: return x return y",MBPP_969 970,"Write a function to find the maximum number of segments of lengths a, b and c that can be formed from n.","def maximum_segments(n, a, b, c) : dp = [-1] * (n + 10) dp[0] = 0 for i in range(0, n) : if (dp[i] != -1) : if(i + a <= n ): dp[i + a] = max(dp[i] + 1, dp[i + a]) if(i + b <= n ): dp[i + b] = max(dp[i] + 1, dp[i + b]) if(i + c <= n ): dp[i + c] = max(dp[i] + 1, dp[i + c]) return dp[n]",MBPP_970 971,Write a function to concatenate the given two tuples to a nested tuple.,"def concatenate_nested(test_tup1, test_tup2): res = test_tup1 + test_tup2 return (res) ",MBPP_971 972,Write a python function to left rotate the string.,"def left_rotate(s,d): tmp = s[d : ] + s[0 : d] return tmp ",MBPP_972 973,Write a function to find the minimum total path sum in the given triangle.,"def min_sum_path(A): memo = [None] * len(A) n = len(A) - 1 for i in range(len(A[n])): memo[i] = A[n][i] for i in range(len(A) - 2, -1,-1): for j in range( len(A[i])): memo[j] = A[i][j] + min(memo[j], memo[j + 1]) return memo[0]",MBPP_973