id
stringlengths
11
13
content
stringlengths
165
5.63k
mbpp_data_37
Write a function to sort a given mixed list of integers and strings. assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white'] assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green',...
mbpp_data_38
Write a function to find the division of first even and odd number of a given list. assert div_even_odd([1,3,5,7,4,1,6,8])==4 assert div_even_odd([1,2,3,4,5,6,7,8,9,10])==2 assert div_even_odd([1,5,7,9,10])==10 def div_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el...
mbpp_data_39
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. assert rearange_string("aab")==('aba') assert rearange_string("aabb")==('abab') assert rearange_string("abccdd")==('cdabcd') import heapq from collections import Counter d...
mbpp_data_40
Write a function to find frequency of the elements in a given list of lists using collections module. assert freq_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]])==({2: 3, 1: 2, 5: 2, 3: 1, 4: 1, 6: 1, 7: 1, 9: 1}) assert freq_element([[1,2,3,4],[5,6,7,8],[9,10,11,12]])==({1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8...
mbpp_data_41
Write a function to filter even numbers using lambda function. assert filter_evennumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[2, 4, 6, 8, 10] assert filter_evennumbers([10,20,45,67,84,93])==[10,20,84] assert filter_evennumbers([5,7,9,8,6,4,3])==[8,6,4] def filter_evennumbers(nums): even_nums = list(filter(lambda x: x%2...
mbpp_data_42
Write a python function to find the sum of repeated elements in a given array. assert find_Sum([1,2,3,1,1,4,5,6],8) == 3 assert find_Sum([1,2,3,1,1],5) == 3 assert find_Sum([1,1,2],3) == 2 def find_Sum(arr,n): return sum([x for x in arr if arr.count(x) > 1])
mbpp_data_43
Write a function to find sequences of lowercase letters joined with an underscore using regex. assert text_match("aab_cbbbc") == 'Found a match!' assert text_match("aab_Abbbc") == 'Not matched!' assert text_match("Aaab_abbbc") == 'Not matched!' import re def text_match(text): patterns = '^[a-z]+_[a-z]+$' if re.s...
mbpp_data_44
Write a function that matches a word at the beginning of a string. assert text_match_string(" python")==('Not matched!') assert text_match_string("python")==('Found a match!') assert text_match_string(" lang")==('Not matched!') import re def text_match_string(text): patterns = '^\w+' if re.search(pa...
mbpp_data_45
Write a function to find the gcd of the given array elements. assert get_gcd([2, 4, 6, 8, 16]) == 2 assert get_gcd([1, 2, 3]) == 1 assert get_gcd([2, 4, 6, 8]) == 2 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...
mbpp_data_46
Write a python function to determine whether all the numbers are different from each other are not. assert test_distinct([1,5,7,9]) == True assert test_distinct([2,4,5,5,7,9]) == False assert test_distinct([1,2,3]) == True def test_distinct(data): if len(data) == len(set(data)): return True else: return...
mbpp_data_47
Write a python function to find the last digit when factorial of a divides factorial of b. assert compute_Last_Digit(2,4) == 2 assert compute_Last_Digit(6,8) == 6 assert compute_Last_Digit(1,2) == 2 def compute_Last_Digit(A,B): variable = 1 if (A == B): return 1 elif ((B - A) >= 5): ...
mbpp_data_48
Write a python function to set all odd bits of a given number. assert odd_bit_set_number(10) == 15 assert odd_bit_set_number(20) == 21 assert odd_bit_set_number(30) == 31 def odd_bit_set_number(n): count = 0;res = 0;temp = n while temp > 0: if count % 2 == 0: res |= (1 << count) ...
mbpp_data_49
Write a function to extract every first or specified element from a given two-dimensional list. assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],0)==[1, 4, 7] assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],2)==[3, 6, 9] assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1,...
mbpp_data_50
Write a function to find the list with minimum length using lambda function. assert min_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(1, [0]) assert min_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(1,[1]) assert min_length_list([[3,4,5],[6,7,8,9],[10,11,12],[1,2]])==(2,[1,2]) def min_length_li...
mbpp_data_51
Write a function to print check if the triangle is equilateral or not. assert check_equilateral(6,8,12)==False assert check_equilateral(6,6,12)==False assert check_equilateral(6,6,6)==True def check_equilateral(x,y,z): if x == y == z: return True else: return False
mbpp_data_52
Write a function to caluclate area of a parallelogram. assert parallelogram_area(10,20)==200 assert parallelogram_area(15,20)==300 assert parallelogram_area(8,9)==72 def parallelogram_area(b,h): area=b*h return area
mbpp_data_53
Write a python function to check whether the first and last characters of a given string are equal or not. assert check_Equality("abcda") == "Equal" assert check_Equality("ab") == "Not Equal" assert check_Equality("mad") == "Not Equal" def check_Equality(str): if (str[0] == str[-1]): return ("Equal") else...
mbpp_data_54
Write a function to sort the given array by using counting sort. assert counting_sort([1,23,4,5,6,7,8]) == [1, 4, 5, 6, 7, 8, 23] assert counting_sort([12, 9, 28, 33, 69, 45]) == [9, 12, 28, 33, 45, 69] assert counting_sort([8, 4, 14, 3, 2, 1]) == [1, 2, 3, 4, 8, 14] def counting_sort(my_list): max_value = 0 ...
mbpp_data_55
Write a function to find t-nth term of geometric series. assert tn_gp(1,5,2)==16 assert tn_gp(1,5,4)==256 assert tn_gp(2,6,3)==486 import math def tn_gp(a,n,r): tn = a * (math.pow(r, n - 1)) return tn
mbpp_data_56
Write a python function to check if a given number is one less than twice its reverse. assert check(70) == False assert check(23) == False assert check(73) == True def rev(num): rev_num = 0 while (num > 0): rev_num = (rev_num * 10 + num % 10) num = num // 10 return rev_num d...
mbpp_data_57
Write a python function to find the largest number that can be formed with the given digits. assert find_Max_Num([1,2,3],3) == 321 assert find_Max_Num([4,5,6,1],4) == 6541 assert find_Max_Num([1,2,3,9],4) == 9321 def find_Max_Num(arr,n) : arr.sort(reverse = True) num = arr[0] for i in range(1,n) : ...
mbpp_data_58
Write a python function to check whether the given two integers have opposite sign or not. assert opposite_Signs(1,-2) == True assert opposite_Signs(3,2) == False assert opposite_Signs(-10,-10) == False def opposite_Signs(x,y): return ((x ^ y) < 0);
mbpp_data_59
Write a function to find the nth octagonal number. assert is_octagonal(5) == 65 assert is_octagonal(10) == 280 assert is_octagonal(15) == 645 def is_octagonal(n): return 3 * n * n - 2 * n
mbpp_data_60
Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array. assert max_len_sub([2, 5, 6, 3, 7, 6, 5, 8], 8) == 5 assert max_len_sub([-2, -1, 5, -1, 4, 0, 3], 7) == 4 assert max_len_sub([9, 11, 13, 15, 18], 5) == 1 def max_len_sub( arr, n): mls=[] m...
mbpp_data_61
Write a python function to count number of substrings with the sum of digits equal to their length. assert count_Substrings('112112',6) == 6 assert count_Substrings('111',3) == 6 assert count_Substrings('1101112',7) == 12 from collections import defaultdict def count_Substrings(s,n): count,sum = 0,0 mp = def...
mbpp_data_62
Write a python function to find smallest number in a list. assert smallest_num([10, 20, 1, 45, 99]) == 1 assert smallest_num([1, 2, 3]) == 1 assert smallest_num([45, 46, 50, 60]) == 45 def smallest_num(xs): return min(xs)
mbpp_data_63
Write a function to find the maximum difference between available pairs in the given tuple list. assert max_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 7 assert max_difference([(4, 6), (2, 17), (9, 13), (11, 12)]) == 15 assert max_difference([(12, 35), (21, 27), (13, 23), (41, 22)]) == 23 def max_difference(test_l...
mbpp_data_64
Write a function to sort a list of tuples using lambda. assert subject_marks([('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])==[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)] assert subject_marks([('Telugu',49),('Hindhi',54),('Social',33)])==([('Social',33),('Telugu...
mbpp_data_65
Write a function of recursion list sum. assert recursive_list_sum(([1, 2, [3,4],[5,6]]))==21 assert recursive_list_sum(([7, 10, [15,14],[19,41]]))==106 assert recursive_list_sum(([10, 20, [30,40],[50,60]]))==210 def recursive_list_sum(data_list): total = 0 for element in data_list: if type(element) == type([]): ...
mbpp_data_66
Write a python function to count positive numbers in a list. assert pos_count([1,-2,3,-4]) == 2 assert pos_count([3,4,5,-1]) == 3 assert pos_count([1,2,3,4]) == 4 def pos_count(list): pos_count= 0 for num in list: if num >= 0: pos_count += 1 return pos_count
mbpp_data_67
Write a function to find the number of ways to partition a set of bell numbers. assert bell_number(2)==2 assert bell_number(10)==115975 assert bell_number(56)==6775685320645824322581483068371419745979053216268760300 def bell_number(n): bell = [[0 for i in range(n+1)] for j in range(n+1)] bell[0][0] = 1 ...
mbpp_data_68
Write a python function to check whether the given array is monotonic or not. assert is_Monotonic([6, 5, 4, 4]) == True assert is_Monotonic([1, 2, 2, 3]) == True assert is_Monotonic([1, 3, 2]) == False def is_Monotonic(A): return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or all(A[i] >= A[i + ...
mbpp_data_69
Write a function to check whether a list contains the given sublist or not. assert is_sublist([2,4,3,5,7],[3,7])==False assert is_sublist([2,4,3,5,7],[4,3])==True assert is_sublist([2,4,3,5,7],[1,6])==False def is_sublist(l, s): sub_set = False if s == []: sub_set = True elif s == l: sub_set = True elif l...
mbpp_data_70
Write a function to find whether all the given tuples have equal length or not. assert get_equal([(11, 22, 33), (44, 55, 66)], 3) == 'All tuples have same length' assert get_equal([(1, 2, 3), (4, 5, 6, 7)], 3) == 'All tuples do not have same length' assert get_equal([(1, 2), (3, 4)], 2) == 'All tuples have same length'...
mbpp_data_71
Write a function to sort a list of elements using comb sort. assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79] assert comb_sort([41, 32, 15, 19, 22]) == [15, 19, 22, 32, 41] assert comb_sort([99, 15, 13, 47]) == [13, 15, 47, 99] def comb_sort(nums): shrink_fact = 1.3 gaps = len(nums) swapped =...
mbpp_data_72
Write a python function to check whether the given number can be represented as difference of two squares or not. assert dif_Square(5) == True assert dif_Square(10) == False assert dif_Square(15) == True def dif_Square(n): if (n % 4 != 2): return True return False
mbpp_data_73
Write a function to split the given string with multiple delimiters by using regex. assert multiple_split('Forces of the \ndarkness*are coming into the play.') == ['Forces of the ', 'darkness', 'are coming into the play.'] assert multiple_split('Mi Box runs on the \n Latest android*which has google assistance and chrom...
mbpp_data_74
Write a function to check whether it follows the sequence given in the patterns array. assert is_samepatterns(["red","green","green"], ["a", "b", "b"])==True assert is_samepatterns(["red","green","greenn"], ["a","b","b"])==False assert is_samepatterns(["red","green","greenn"], ["a","b"])==False def is_samepatterns(c...
mbpp_data_75
Write a function to find tuples which have all elements divisible by k from the given list of tuples. assert find_tuples([(6, 24, 12), (7, 9, 6), (12, 18, 21)], 6) == '[(6, 24, 12)]' assert find_tuples([(5, 25, 30), (4, 2, 3), (7, 8, 9)], 5) == '[(5, 25, 30)]' assert find_tuples([(7, 9, 16), (8, 16, 4), (19, 17, 18)], ...
mbpp_data_76
Write a python function to count the number of squares in a rectangle. assert count_Squares(4,3) == 20 assert count_Squares(2,2) == 5 assert count_Squares(1,1) == 1 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 +...
mbpp_data_77
Write a python function to find the difference between sum of even and odd digits. assert is_Diff (12345) == False assert is_Diff(1212112) == True assert is_Diff(1212) == False def is_Diff(n): return (n % 11 == 0)
mbpp_data_78
Write a python function to find number of integers with odd number of set bits. assert count_With_Odd_SetBits(5) == 3 assert count_With_Odd_SetBits(10) == 5 assert count_With_Odd_SetBits(15) == 8 def count_With_Odd_SetBits(n): if (n % 2 != 0): return (n + 1) / 2 count = bin(n).count('1') ans ...
mbpp_data_79
Write a python function to check whether the length of the word is odd or not. assert word_len("Hadoop") == False assert word_len("great") == True assert word_len("structure") == True def word_len(s): s = s.split(' ') for word in s: if len(word)%2!=0: return True else...
mbpp_data_80
Write a function to find the nth tetrahedral number. assert tetrahedral_number(5) == 35.0 assert tetrahedral_number(6) == 56.0 assert tetrahedral_number(7) == 84.0 def tetrahedral_number(n): return (n * (n + 1) * (n + 2)) / 6
mbpp_data_81
Write a function to zip the two given tuples. assert zip_tuples((7, 8, 4, 5, 9, 10),(1, 5, 6) ) == [(7, 1), (8, 5), (4, 6), (5, 1), (9, 5), (10, 6)] assert zip_tuples((8, 9, 5, 6, 10, 11),(2, 6, 7) ) == [(8, 2), (9, 6), (5, 7), (6, 2), (10, 6), (11, 7)] assert zip_tuples((9, 10, 6, 7, 11, 12),(3, 7, 8) ) == [(9, 3), (1...
mbpp_data_82
Write a function to find the volume of a sphere. assert volume_sphere(10)==4188.790204786391 assert volume_sphere(25)==65449.84694978735 assert volume_sphere(20)==33510.32163829113 import math def volume_sphere(r): volume=(4/3)*math.pi*r*r*r return volume
mbpp_data_83
Write a python function to find the character made by adding all the characters of the given string. assert get_Char("abc") == "f" assert get_Char("gfg") == "t" assert get_Char("ab") == "c" def get_Char(strr): summ = 0 for i in range(len(strr)): summ += (ord(strr[i]) - ord('a') + 1) if (sum...
mbpp_data_84
Write a function to find the n-th number in newman conway sequence. assert sequence(10) == 6 assert sequence(2) == 1 assert sequence(3) == 2 def sequence(n): if n == 1 or n == 2: return 1 else: return sequence(sequence(n-1)) + sequence(n-sequence(n-1))
mbpp_data_85
Write a function to find the surface area of a sphere. assert surfacearea_sphere(10)==1256.6370614359173 assert surfacearea_sphere(15)==2827.4333882308138 assert surfacearea_sphere(20)==5026.548245743669 import math def surfacearea_sphere(r): surfacearea=4*math.pi*r*r return surfacearea
mbpp_data_86
Write a function to find nth centered hexagonal number. assert centered_hexagonal_number(10) == 271 assert centered_hexagonal_number(2) == 7 assert centered_hexagonal_number(9) == 217 def centered_hexagonal_number(n): return 3 * n * (n - 1) + 1
mbpp_data_87
Write a function to merge three dictionaries into a single expression. assert merge_dictionaries_three({ "R": "Red", "B": "Black", "P": "Pink" }, { "G": "Green", "W": "White" },{ "O": "Orange", "W": "White", "B": "Black" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White', 'O': 'Orange'} assert merge...
mbpp_data_88
Write a function to get the frequency of the elements in a list. assert freq_count([10,10,10,10,20,20,20,20,40,40,50,50,30])==({10: 4, 20: 4, 40: 2, 50: 2, 30: 1}) assert freq_count([1,2,3,4,3,2,4,1,3,1,4])==({1:3, 2:2,3:3,4:3}) assert freq_count([5,6,7,4,9,10,4,5,6,7,9,5])==({10:1,5:3,6:2,7:2,4:2,9:2}) import colle...
mbpp_data_89
Write a function to find the closest smaller number than n. assert closest_num(11) == 10 assert closest_num(7) == 6 assert closest_num(12) == 11 def closest_num(N): return (N - 1)
mbpp_data_90
Write a python function to find the length of the longest word. assert len_log(["python","PHP","bigdata"]) == 7 assert len_log(["a","ab","abc"]) == 3 assert len_log(["small","big","tall"]) == 5 def len_log(list1): max=len(list1[0]) for i in list1: if len(i)>max: max=len(i) return ma...
mbpp_data_91
Write a function to check if a substring is present in a given list of string values. assert find_substring(["red", "black", "white", "green", "orange"],"ack")==True assert find_substring(["red", "black", "white", "green", "orange"],"abc")==False assert find_substring(["red", "black", "white", "green", "orange"],"ange"...
mbpp_data_92
Write a function to check whether the given number is undulating or not. assert is_undulating("1212121") == True assert is_undulating("1991") == False assert is_undulating("121") == True 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...
mbpp_data_93
Write a function to calculate the value of 'a' to the power 'b'. assert power(3,4) == 81 assert power(2,3) == 8 assert power(5,5) == 3125 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_data_94
Write a function to extract the index minimum value record from the given tuples. assert index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]) == 'Varsha' assert index_minimum([('Yash', 185), ('Dawood', 125), ('Sanya', 175)]) == 'Dawood' assert index_minimum([('Sai', 345), ('Salman', 145), ('Ayesha', 96)]) ...
mbpp_data_95
Write a python function to find the minimum length of sublist. assert Find_Min_Length([[1],[1,2]]) == 1 assert Find_Min_Length([[1,2],[1,2,3],[1,2,3,4]]) == 2 assert Find_Min_Length([[3,3,3],[4,4,4,4]]) == 3 def Find_Min_Length(lst): minLength = min(len(x) for x in lst ) return minLength
mbpp_data_96
Write a python function to find the number of divisors of a given integer. assert divisor(15) == 4 assert divisor(12) == 6 assert divisor(9) == 3 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_data_97
Write a function to find frequency count of list of lists. assert frequency_lists([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]])=={1: 1, 2: 3, 3: 1, 4: 1, 5: 2, 6: 1, 7: 1, 8: 1, 9: 1} assert frequency_lists([[1,2,3,4],[5,6,7,8],[9,10,11,12]])=={1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1,10:1,11:1,12:1} assert f...
mbpp_data_98
Write a function to multiply all the numbers in a list and divide with the length of the list. assert multiply_num((8, 2, 3, -1, 7))==-67.2 assert multiply_num((-10,-20,-30))==-2000.0 assert multiply_num((19,15,18))==1710.0 def multiply_num(numbers): total = 1 for x in numbers: total *= x re...
mbpp_data_99
Write a function to convert the given decimal number to its binary equivalent. assert decimal_to_binary(8) == '1000' assert decimal_to_binary(18) == '10010' assert decimal_to_binary(7) == '111' def decimal_to_binary(n): return bin(n).replace("0b","")
mbpp_data_100
Write a function to find the next smallest palindrome of a specified number. assert next_smallest_palindrome(99)==101 assert next_smallest_palindrome(1221)==1331 assert next_smallest_palindrome(120)==121 import sys def next_smallest_palindrome(num): numstr = str(num) for i in range(num+1,sys.maxsize): ...
mbpp_data_101
Write a function to find the kth element in the given array. assert kth_element([12,3,5,7,19], 5, 2) == 3 assert kth_element([17,24,8,23], 4, 3) == 8 assert kth_element([16,21,25,36,4], 5, 4) == 36 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...
mbpp_data_102
Write a function to convert snake case string to camel case string. assert snake_to_camel('python_program')=='PythonProgram' assert snake_to_camel('python_language')==('PythonLanguage') assert snake_to_camel('programming_language')==('ProgrammingLanguage') def snake_to_camel(word): import re return ''...
mbpp_data_103
Write a function to find eulerian number a(n, m). assert eulerian_num(3, 1) == 4 assert eulerian_num(4, 1) == 11 assert eulerian_num(5, 3) == 26 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_data_104
Write a function to sort each sublist of strings in a given list of lists using lambda function. assert sort_sublists((["green", "orange"], ["black", "white"], ["white", "black", "orange"]))==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']] assert sort_sublists(([" red ","green" ],["blue "," blac...
mbpp_data_105
Write a python function to count true booleans in the given list. assert count([True,False,True]) == 2 assert count([False,False]) == 0 assert count([True,True,True]) == 3 def count(lst): return sum(lst)
mbpp_data_106
Write a function to add the given list to the given tuples. assert add_lists([5, 6, 7], (9, 10)) == (9, 10, 5, 6, 7) assert add_lists([6, 7, 8], (10, 11)) == (10, 11, 6, 7, 8) assert add_lists([7, 8, 9], (11, 12)) == (11, 12, 7, 8, 9) def add_lists(test_list, test_tup): res = tuple(list(test_tup) + test_list) ret...
mbpp_data_107
Write a python function to count hexadecimal numbers for a given range. assert count_Hexadecimal(10,15) == 6 assert count_Hexadecimal(2,4) == 0 assert count_Hexadecimal(15,16) == 1 def count_Hexadecimal(L,R) : count = 0; for i in range(L,R + 1) : if (i >= 10 and i <= 15) : count +=...
mbpp_data_108
Write a function to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm. assert merge_sorted_list([25, 24, 15, 4, 5, 29, 110],[19, 20, 11, 56, 25, 233, 154],[24, 26, 54, 48])==[4, 5, 11, 15, 19, 20, 24, 24, 25, 25, 26, 29, 48, 54, 56, 110, 154, 233] assert merge_sorted_list([1, 3, 5, 6...
mbpp_data_109
Write a python function to find the count of rotations of a binary string with odd value. assert odd_Equivalent("011001",6) == 3 assert odd_Equivalent("11011",5) == 4 assert odd_Equivalent("1010",4) == 2 def odd_Equivalent(s,n): count=0 for i in range(0,n): if (s[i] == '1'): count = c...
mbpp_data_110
Write a function to extract the ranges that are missing from the given list with the given start range and end range values. assert extract_missing([(6, 9), (15, 34), (48, 70)], 2, 100) == [(2, 6), (9, 100), (9, 15), (34, 100), (34, 48), (70, 100)] assert extract_missing([(7, 2), (15, 19), (38, 50)], 5, 60) == [(5, 7),...
mbpp_data_111
Write a function to find common elements in given nested lists. * list item * list item * list item * list item assert common_in_nested_lists([[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]])==[18, 12] assert common_in_nested_lists([[12, 5, 23, 25, 45], [7, 11, 5, 23, 28], [1, 5, 8, 18, 23, 16]])=...
mbpp_data_112
Write a python function to find the perimeter of a cylinder. assert perimeter(2,4) == 12 assert perimeter(1,2) == 6 assert perimeter(3,1) == 8 def perimeter(diameter,height) : return 2*(diameter+height)
mbpp_data_113
Write a function to check if a string represents an integer or not. assert check_integer("python")==False assert check_integer("1")==True assert check_integer("12345")==True def check_integer(text): text = text.strip() if len(text) < 1: return None else: if all(text[i] in "0123456789" for i in range(le...
mbpp_data_114
Write a function to assign frequency to each tuple in the given tuple list. assert assign_freq([(6, 5, 8), (2, 7), (6, 5, 8), (6, 5, 8), (9, ), (2, 7)] ) == '[(6, 5, 8, 3), (2, 7, 2), (9, 1)]' assert assign_freq([(4, 2, 4), (7, 1), (4, 8), (4, 2, 4), (9, 2), (7, 1)] ) == '[(4, 2, 4, 2), (7, 1, 2), (4, 8, 1), (9, 2, 1)]...
mbpp_data_115
Write a function to check whether all dictionaries in a list are empty or not. assert empty_dit([{},{},{}])==True assert empty_dit([{1,2},{},{}])==False assert empty_dit({})==True def empty_dit(list1): empty_dit=all(not d for d in list1) return empty_dit
mbpp_data_116
Write a function to convert a given tuple of positive integers into an integer. assert tuple_to_int((1,2,3))==123 assert tuple_to_int((4,5,6))==456 assert tuple_to_int((5,6,7))==567 def tuple_to_int(nums): result = int(''.join(map(str,nums))) return result
mbpp_data_117
Write a function to convert all possible convertible elements in the list to float. assert list_to_float( [("3", "4"), ("1", "26.45"), ("7.32", "8"), ("4", "8")] ) == '[(3.0, 4.0), (1.0, 26.45), (7.32, 8.0), (4.0, 8.0)]' assert list_to_float( [("4", "4"), ("2", "27"), ("4.12", "9"), ("7", "11")] ) == '[(4.0, 4.0), (2.0...
mbpp_data_118
[link text](https:// [link text](https:// [link text](https://)))write a function to convert a string to a list. assert string_to_list("python programming")==['python','programming'] assert string_to_list("lists tuples strings")==['lists','tuples','strings'] assert string_to_list("write a program")==['write','a','progr...
mbpp_data_119
Write a python function to find the element that appears only once in a sorted array. assert search([1,1,2,2,3],5) == 3 assert search([1,1,3,3,4,4,5,5,7,7,8],11) == 8 assert search([1,2,2,3,3,4,4],7) == 1 def search(arr,n) : XOR = 0 for i in range(n) : XOR = XOR ^ arr[i] return (XOR)
mbpp_data_120
Write a function to find the maximum product from the pairs of tuples within a given list. assert max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==36 assert max_product_tuple([(10,20), (15,2), (5,10)] )==200 assert max_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==484 def max_product_tuple(list1): resu...
mbpp_data_121
Write a function to find the triplet with sum of the given array assert check_triplet([2, 7, 4, 0, 9, 5, 1, 3], 8, 6, 0) == True assert check_triplet([1, 4, 5, 6, 7, 8, 5, 9], 8, 6, 0) == False assert check_triplet([10, 4, 2, 3, 5], 5, 15, 0) == True def check_triplet(A, n, sum, count): if count == 3 and sum == 0:...
mbpp_data_122
Write a function to find n’th smart number. assert smartNumber(1) == 30 assert smartNumber(50) == 273 assert smartNumber(1000) == 2664 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): p...
mbpp_data_123
Write a function to sum all amicable numbers from 1 to a specified number. assert amicable_numbers_sum(999)==504 assert amicable_numbers_sum(9999)==31626 assert amicable_numbers_sum(99)==0 def amicable_numbers_sum(limit): if not isinstance(limit, int): return "Input is not an integer!" if limit < 1: ...
mbpp_data_124
Write a function to get the angle of a complex number. assert angle_complex(0,1j)==1.5707963267948966 assert angle_complex(2,1j)==0.4636476090008061 assert angle_complex(0,2j)==1.5707963267948966 import cmath def angle_complex(a,b): cn=complex(a,b) angle=cmath.phase(a+b) return angle
mbpp_data_125
Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string. assert find_length("11000010001", 11) == 6 assert find_length("10111", 5) == 1 assert find_length("11011101100101", 14) == 2 def find_length(string, n): current_sum = 0 max_sum =...
mbpp_data_126
Write a python function to find the sum of common divisors of two given numbers. assert sum(10,15) == 6 assert sum(100,150) == 93 assert sum(4,6) == 3 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_data_127
Write a function to multiply two integers without using the * operator in python. assert multiply_int(10,20)==200 assert multiply_int(5,10)==50 assert multiply_int(4,8)==32 def multiply_int(x, y): if y < 0: return -multiply_int(x, -y) elif y == 0: return 0 elif y == 1: return x...
mbpp_data_128
Write a function to shortlist words that are longer than n from a given list of words. assert long_words(3,"python is a programming language")==['python','programming','language'] assert long_words(2,"writing a program")==['writing','program'] assert long_words(5,"sorting list")==['sorting'] def long_words(n, str): ...
mbpp_data_129
Write a function to calculate magic square. assert magic_square_test([[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]])==True assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 8]])==True assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 7]])==False def magic_square_test(my_matrix): iSize = ...
mbpp_data_130
Write a function to find the item with maximum frequency in a given list. assert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2])==(2, 5) assert max_occurrences([2,3,8,4,7,9,8,7,9,15,14,10,12,13,16,16,18])==(8, 2) assert max_occurrences([10,20,20,30,40,90,80,50,30,20,50,10])==(20, 3) from collections import...
mbpp_data_131
Write a python function to reverse only the vowels of a given string. assert reverse_vowels("Python") == "Python" assert reverse_vowels("USA") == "ASU" assert reverse_vowels("ab") == "ab" def reverse_vowels(str1): vowels = "" for char in str1: if char in "aeiouAEIOU": vowels += char result_string = "" fo...
mbpp_data_132
Write a function to convert tuple to a string. assert tup_string(('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's'))==("exercises") assert tup_string(('p','y','t','h','o','n'))==("python") assert tup_string(('p','r','o','g','r','a','m'))==("program") def tup_string(tup1): str = ''.join(tup1) return str
mbpp_data_133
Write a function to calculate the sum of the negative numbers of a given list of numbers using lambda function. assert sum_negativenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==-32 assert sum_negativenum([10,15,-14,13,-18,12,-20])==-52 assert sum_negativenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==-894 def sum_neg...
mbpp_data_134
Write a python function to check whether the last element of given array is even or odd after performing an operation p times. assert check_last([5,7,10],3,1) == "ODD" assert check_last([2,3],2,3) == "EVEN" assert check_last([1,2,3],3,1) == "ODD" def check_last (arr,n,p): _sum = 0 for i in range(n): ...
mbpp_data_135
Write a function to find the nth hexagonal number. assert hexagonal_num(10) == 190 assert hexagonal_num(5) == 45 assert hexagonal_num(7) == 91 def hexagonal_num(n): return n*(2*n - 1)
mbpp_data_136
Write a function to calculate electricity bill. assert cal_electbill(75)==246.25 assert cal_electbill(265)==1442.75 assert cal_electbill(100)==327.5 def cal_electbill(units): if(units < 50): amount = units * 2.60 surcharge = 25 elif(units <= 100): amount = 130 + ((units - 50) * 3.25) surcharge =...