id
stringlengths
11
13
content
stringlengths
165
5.63k
mbpp_data_801
Write a python function to count the number of equal numbers from three given integers. assert test_three_equal(1,1,1) == 3 assert test_three_equal(-1,-2,-3) == 0 assert test_three_equal(1,2,2) == 2 def test_three_equal(x,y,z): result= set([x,y,z]) if len(result)==3: return 0 else: return (4-len(resu...
mbpp_data_802
Write a python function to count the number of rotations required to generate a sorted array. assert count_Rotation([3,2,1],3) == 1 assert count_Rotation([4,5,1,2,3],5) == 2 assert count_Rotation([7,8,9,1,2,3],6) == 3 def count_Rotation(arr,n): for i in range (1,n): if (arr[i] < arr[i - 1]): ...
mbpp_data_803
Write a python function to check whether the given number is a perfect square or not. assert is_Perfect_Square(10) == False assert is_Perfect_Square(36) == True assert is_Perfect_Square(14) == False def is_Perfect_Square(n) : i = 1 while (i * i<= n): if ((n % i == 0) and (n / i == i)): r...
mbpp_data_804
Write a python function to check whether the product of numbers is even or not. assert is_Product_Even([1,2,3],3) == True assert is_Product_Even([1,2,1,4],4) == True assert is_Product_Even([1,1],2) == False def is_Product_Even(arr,n): for i in range(0,n): if ((arr[i] & 1) == 0): return Tru...
mbpp_data_805
Write a function to find the list in a list of lists whose sum of elements is the highest. assert max_sum_list([[1,2,3], [4,5,6], [10,11,12], [7,8,9]])==[10, 11, 12] assert max_sum_list([[3,2,1], [6,5,4], [12,11,10]])==[12,11,10] assert max_sum_list([[2,3,1]])==[2,3,1] def max_sum_list(lists): return max(lists, ke...
mbpp_data_806
Write a function to find maximum run of uppercase characters in the given string. assert max_run_uppercase('GeMKSForGERksISBESt') == 5 assert max_run_uppercase('PrECIOusMOVemENTSYT') == 6 assert max_run_uppercase('GooGLEFluTTER') == 4 def max_run_uppercase(test_str): cnt = 0 res = 0 for idx in range(0, len(tes...
mbpp_data_807
Write a python function to find the first odd number in a given list of numbers. assert first_odd([1,3,5]) == 1 assert first_odd([2,4,1,3]) == 1 assert first_odd ([8,9,1]) == 9 def first_odd(nums): first_odd = next((el for el in nums if el%2!=0),-1) return first_odd
mbpp_data_808
Write a function to check if the given tuples contain the k or not. assert check_K((10, 4, 5, 6, 8), 6) == True assert check_K((1, 2, 3, 4, 5, 6), 7) == False assert check_K((7, 8, 9, 44, 11, 12), 11) == True def check_K(test_tup, K): res = False for ele in test_tup: if ele == K: res = True bre...
mbpp_data_809
Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple. assert check_smaller((1, 2, 3), (2, 3, 4)) == False assert check_smaller((4, 5, 6), (3, 4, 5)) == True assert check_smaller((11, 12, 13), (10, 11, 12)) == True def check_smaller(test_tup1, test_tup2): re...
mbpp_data_810
Write a function to iterate over elements repeating each as many times as its count. assert count_variable(4,2,0,-2)==['p', 'p', 'p', 'p', 'q', 'q'] assert count_variable(0,1,2,3)==['q', 'r', 'r', 's', 's', 's'] assert count_variable(11,15,12,23)==['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'q', 'q', 'q',...
mbpp_data_811
Write a function to check if two lists of tuples are identical or not. assert check_identical([(10, 4), (2, 5)], [(10, 4), (2, 5)]) == True assert check_identical([(1, 2), (3, 7)], [(12, 14), (12, 45)]) == False assert check_identical([(2, 14), (12, 25)], [(2, 14), (12, 25)]) == True def check_identical(test_list1, tes...
mbpp_data_812
Write a function to abbreviate 'road' as 'rd.' in a given string. assert road_rd("ravipadu Road")==('ravipadu Rd.') assert road_rd("palnadu Road")==('palnadu Rd.') assert road_rd("eshwar enclave Road")==('eshwar enclave Rd.') import re def road_rd(street): return (re.sub('Road$', 'Rd.', street))
mbpp_data_813
Write a function to find length of the string. assert string_length('python')==6 assert string_length('program')==7 assert string_length('language')==8 def string_length(str1): count = 0 for char in str1: count += 1 return count
mbpp_data_814
Write a function to find the area of a rombus. assert rombus_area(10,20)==100 assert rombus_area(10,5)==25 assert rombus_area(4,2)==4 def rombus_area(p,q): area=(p*q)/2 return area
mbpp_data_815
Write a function to sort the given array without using any sorting algorithm. the given array consists of only 0, 1, and 2. assert sort_by_dnf([1,2,0,1,0,1,2,1,1], 9) == [0, 0, 1, 1, 1, 1, 1, 2, 2] assert sort_by_dnf([1,0,0,1,2,1,2,2,1,0], 10) == [0, 0, 0, 1, 1, 1, 1, 2, 2, 2] assert sort_by_dnf([2,2,1,0,0,0,1,1,2,1], ...
mbpp_data_816
Write a function to clear the values of the given tuples. assert clear_tuple((1, 5, 3, 6, 8)) == () assert clear_tuple((2, 1, 4 ,5 ,6)) == () assert clear_tuple((3, 2, 5, 6, 8)) == () def clear_tuple(test_tup): temp = list(test_tup) temp.clear() test_tup = tuple(temp) return (test_tup)
mbpp_data_817
Write a function to find numbers divisible by m or n from a list of numbers using lambda function. assert div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190],19,13)==[19, 65, 57, 39, 152, 190] assert div_of_nums([1, 2, 3, 5, 7, 8, 10],2,5)==[2, 5, 8, 10] assert div_of_nums([10,15,14,13,18,12,20],10,5)==[10, 15, 20...
mbpp_data_818
Write a python function to count lower case letters in a given string. assert lower_ctr('abc') == 3 assert lower_ctr('string') == 6 assert lower_ctr('Python') == 5 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 l...
mbpp_data_819
Write a function to count the frequency of consecutive duplicate elements in a given list of numbers. assert count_duplic([1,2,2,2,4,4,4,5,5,5,5])==([1, 2, 4, 5], [1, 3, 3, 4]) assert count_duplic([2,2,3,1,2,6,7,9])==([2, 3, 1, 2, 6, 7, 9], [2, 1, 1, 1, 1, 1, 1]) assert count_duplic([2,1,5,6,8,3,4,9,10,11,8,12])==([2, ...
mbpp_data_820
Write a function to check whether the given month number contains 28 days or not. assert check_monthnum_number(2)==True assert check_monthnum_number(1)==False assert check_monthnum_number(3)==False def check_monthnum_number(monthnum1): if monthnum1 == 2: return True else: return False
mbpp_data_821
Write a function to merge two dictionaries into a single expression. assert merge_dictionaries({ "R": "Red", "B": "Black", "P": "Pink" }, { "G": "Green", "W": "White" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White'} assert merge_dictionaries({ "R": "Red", "B": "Black", "P": "Pink" },{ "O": "Orang...
mbpp_data_822
Write a function to return true if the password is valid. assert pass_validity("password")==False assert pass_validity("Password@10")==True assert pass_validity("password@10")==False 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]",...
mbpp_data_823
Write a function to check if the given string starts with a substring using regex. assert check_substring("dreams for dreams makes life fun", "makes") == 'string doesnt start with the given substring' assert check_substring("Hi there how are you Hi alex", "Hi") == 'string starts with the given substring' assert check_s...
mbpp_data_824
Write a python function to remove even numbers from a given list. assert remove_even([1,3,5,2]) == [1,3,5] assert remove_even([5,6,7]) == [5,7] assert remove_even([1,2,3,4]) == [1,3] def remove_even(l): for i in l: if i % 2 == 0: l.remove(i) return l
mbpp_data_825
Write a python function to access multiple elements of specified index from a given list. assert access_elements([2,3,8,4,7,9],[0,3,5]) == [2, 4, 9] assert access_elements([1, 2, 3, 4, 5],[1,2]) == [2,3] assert access_elements([1,0,2,3],[0,1]) == [1,0] def access_elements(nums, list_index): result = [nums[i] for i...
mbpp_data_826
Write a python function to find the type of triangle from the given sides. assert check_Type_Of_Triangle(1,2,3) == "Obtuse-angled Triangle" assert check_Type_Of_Triangle(2,2,2) == "Acute-angled Triangle" assert check_Type_Of_Triangle(1,0,1) == "Right-angled Triangle" def check_Type_Of_Triangle(a,b,c): sqa = pow(a...
mbpp_data_827
Write a function to sum a specific column of a list in a given list of lists. assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],0)==12 assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],1)==15 assert sum_column( [[1,2,3,2],[4,5,6,2],[7,8,9,5],],3)==9 def sum_column(list1, C): result = sum(row[C] for row in list...
mbpp_data_828
Write a function to count alphabets,digits and special charactes in a given string. assert count_alpha_dig_spl("abc!@#123")==(3,3,3) assert count_alpha_dig_spl("dgsuy@#$%&1255")==(5,4,5) assert count_alpha_dig_spl("fjdsif627348#%$^&")==(6,6,5) def count_alpha_dig_spl(string): alphabets=digits = special = 0 for i ...
mbpp_data_829
Write a function to find out the second most repeated (or frequent) string in the given sequence. assert second_frequent(['aaa','bbb','ccc','bbb','aaa','aaa']) == 'bbb' assert second_frequent(['abc','bcd','abc','bcd','bcd','bcd']) == 'abc' assert second_frequent(['cdma','gsm','hspa','gsm','cdma','cdma']) == 'gsm' from ...
mbpp_data_830
Write a function to round up a number to specific digits. assert round_up(123.01247,0)==124 assert round_up(123.01247,1)==123.1 assert round_up(123.01247,2)==123.02 import math def round_up(a, digits): n = 10**-digits return round(math.ceil(a / n) * n, digits)
mbpp_data_831
Write a python function to count equal element pairs from the given array. assert count_Pairs([1,1,1,1],4) == 6 assert count_Pairs([1,5,1],3) == 1 assert count_Pairs([3,2,1,7,8,9],6) == 0 def count_Pairs(arr,n): cnt = 0; for i in range(n): for j in range(i + 1,n): if (arr[i] == arr[j...
mbpp_data_832
Write a function to extract the maximum numeric value from a string by using regex. assert extract_max('100klh564abc365bg') == 564 assert extract_max('hello300how546mer231') == 546 assert extract_max('its233beenalong343journey234') == 343 import re def extract_max(input): numbers = re.findall('\d+',input) numbe...
mbpp_data_833
Write a function to get dictionary keys as a list. assert get_key({1:'python',2:'java'})==[1,2] assert get_key({10:'red',20:'blue',30:'black'})==[10,20,30] assert get_key({27:'language',39:'java',44:'little'})==[27,39,44] def get_key(dict): list = [] for key in dict.keys(): list.append(key) ...
mbpp_data_834
Write a function to generate a square matrix filled with elements from 1 to n raised to the power of 2 in spiral order. assert generate_matrix(3)==[[1, 2, 3], [8, 9, 4], [7, 6, 5]] assert generate_matrix(2)==[[1,2],[4,3]] assert generate_matrix(7)==[[1, 2, 3, 4, 5, 6, 7], [24, 25, 26, 27, 28, 29, 8], [23, 40, 41, 42, ...
mbpp_data_835
Write a python function to find the slope of a line. assert slope(4,2,2,5) == -1.5 assert slope(2,4,4,6) == 1 assert slope(1,2,4,2) == 0 def slope(x1,y1,x2,y2): return (float)(y2-y1)/(x2-x1)
mbpp_data_836
Write a function to find length of the subarray having maximum sum. assert max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3],8) == 5 assert max_sub_array_sum([1, -2, 1, 1, -2, 1],6) == 2 assert max_sub_array_sum([-1, -2, 3, 4, 5],5) == 3 from sys import maxsize def max_sub_array_sum(a,size): max_so_far = -maxsize - ...
mbpp_data_837
Write a python function to find the cube sum of first n odd natural numbers. assert cube_Sum(2) == 28 assert cube_Sum(3) == 153 assert cube_Sum(4) == 496 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_data_838
Write a python function to find minimum number swaps required to make two binary strings equal. assert min_Swaps("0011","1111") == 1 assert min_Swaps("00011","01001") == 2 assert min_Swaps("111","111") == 0 def min_Swaps(s1,s2) : c0 = 0; c1 = 0; for i in range(len(s1)) : if (s1[i] == '0' and s2...
mbpp_data_839
Write a function to sort the tuples alphabetically by the first item of each tuple. assert sort_tuple([("Amana", 28), ("Zenat", 30), ("Abhishek", 29),("Nikhil", 21), ("B", "C")]) == [('Abhishek', 29), ('Amana', 28), ('B', 'C'), ('Nikhil', 21), ('Zenat', 30)] assert sort_tuple([("aaaa", 28), ("aa", 30), ("bab", 29), ("b...
mbpp_data_840
Write a python function to check whether the roots of a quadratic equation are numerically equal but opposite in sign or not. assert Check_Solution(2,0,-1) == "Yes" assert Check_Solution(1,-5,6) == "No" assert Check_Solution(2,0,2) == "Yes" def Check_Solution(a,b,c): if b == 0: return ("Yes") e...
mbpp_data_841
Write a function to count the number of inversions in the given array. assert get_inv_count([1, 20, 6, 4, 5], 5) == 5 assert get_inv_count([8, 4, 2, 1], 4) == 6 assert get_inv_count([3, 1, 2], 3) == 2 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]...
mbpp_data_842
Write a function to find the number which occurs for odd number of times in the given array. assert get_odd_occurence([2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2], 13) == 5 assert get_odd_occurence([1, 2, 3, 2, 3, 1, 3], 7) == 3 assert get_odd_occurence([5, 7, 2, 7, 5, 2, 5], 7) == 5 def get_odd_occurence(arr, arr_size): ...
mbpp_data_843
Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm. assert nth_super_ugly_number(12,[2,7,13,19])==32 assert nth_super_ugly_number(10,[2,7,13,19])==26 assert nth_super_ugly_number(100,[2,7,13,19])==5408 import heapq def nth_super_ugly_number(n, primes): ...
mbpp_data_844
Write a python function to find the kth element in an array containing odd elements first and then even elements. assert get_Number(8,5) == 2 assert get_Number(7,2) == 3 assert get_Number(5,2) == 3 def get_Number(n, k): arr = [0] * n; i = 0; odd = 1; while (odd <= n): arr[i] = odd; ...
mbpp_data_845
Write a python function to count the number of digits in factorial of a given number. assert find_Digits(7) == 4 assert find_Digits(5) == 3 assert find_Digits(4) == 2 import math def find_Digits(n): if (n < 0): return 0; if (n <= 1): return 1; x = ((n * math.log10(n / math.e) + ma...
mbpp_data_846
Write a function to find the minimum number of platforms required for a railway/bus station. assert find_platform([900, 940, 950, 1100, 1500, 1800],[910, 1200, 1120, 1130, 1900, 2000],6)==3 assert find_platform([100,200,300,400],[700,800,900,1000],4)==4 assert find_platform([5,6,7,8],[4,3,2,1],4)==1 def find_platform(a...
mbpp_data_847
Write a python function to copy a list from a singleton tuple. assert lcopy([1, 2, 3]) == [1, 2, 3] assert lcopy([4, 8, 2, 10, 15, 18]) == [4, 8, 2, 10, 15, 18] assert lcopy([4, 5, 6]) == [4, 5, 6] def lcopy(xs): return xs[:]
mbpp_data_848
Write a function to find the area of a trapezium. assert area_trapezium(6,9,4)==30 assert area_trapezium(10,20,30)==450 assert area_trapezium(15,25,35)==700 def area_trapezium(base1,base2,height): area = 0.5 * (base1 + base2) * height return area
mbpp_data_849
Write a python function to find sum of all prime divisors of a given number. assert Sum(60) == 10 assert Sum(39) == 16 assert Sum(40) == 7 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) : ...
mbpp_data_850
Write a function to check if a triangle of positive area is possible with the given angles. assert is_triangleexists(50,60,70)==True assert is_triangleexists(90,45,45)==True assert is_triangleexists(150,30,70)==False def is_triangleexists(a,b,c): if(a != 0 and b != 0 and c != 0 and (a + b + c)== 180): i...
mbpp_data_851
Write a python function to find sum of inverse of divisors. assert Sum_of_Inverse_Divisors(6,12) == 2 assert Sum_of_Inverse_Divisors(9,13) == 1.44 assert Sum_of_Inverse_Divisors(1,4) == 4 def Sum_of_Inverse_Divisors(N,Sum): ans = float(Sum)*1.0 /float(N); return round(ans,2);
mbpp_data_852
Write a python function to remove negative numbers from a list. assert remove_negs([1,-2,3,-4]) == [1,3] assert remove_negs([1,2,3,-4]) == [1,2,3] assert remove_negs([4,5,-6,7,-8]) == [4,5,7] def remove_negs(num_list): for item in num_list: if item < 0: num_list.remove(item) return nu...
mbpp_data_853
Write a python function to find sum of odd factors of a number. assert sum_of_odd_Factors(30) == 24 assert sum_of_odd_Factors(18) == 13 assert sum_of_odd_Factors(2) == 1 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)): ...
mbpp_data_854
Write a function which accepts an arbitrary list and converts it to a heap using heap queue algorithm. assert raw_heap([25, 44, 68, 21, 39, 23, 89])==[21, 25, 23, 44, 39, 68, 89] assert raw_heap([25, 35, 22, 85, 14, 65, 75, 25, 58])== [14, 25, 22, 25, 35, 65, 75, 85, 58] assert raw_heap([4, 5, 6, 2])==[2, 4, 6, 5] impo...
mbpp_data_855
Write a python function to check for even parity of a given number. assert check_Even_Parity(10) == True assert check_Even_Parity(11) == False assert check_Even_Parity(18) == True def check_Even_Parity(x): parity = 0 while (x != 0): x = x & (x - 1) parity += 1 if (parity % 2 == 0): ...
mbpp_data_856
Write a python function to find minimum adjacent swaps required to sort binary array. assert find_Min_Swaps([1,0,1,0],4) == 3 assert find_Min_Swaps([0,1,0],3) == 1 assert find_Min_Swaps([0,0,1,1,0],5) == 2 def find_Min_Swaps(arr,n) : noOfZeroes = [0] * n count = 0 noOfZeroes[n - 1] = 1 - arr[n - 1] ...
mbpp_data_857
Write a function to list out the list of given strings individually using map function. assert listify_list(['Red', 'Blue', 'Black', 'White', 'Pink'])==[['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e'], ['P', 'i', 'n', 'k']] assert listify_list(['python'])==[['p', 'y', 't', 'h...
mbpp_data_858
Write a function to count number of lists in a given list of lists and square the count. assert count_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==25 assert count_list([[1, 3], [5, 7], [9, 11], [13, 15, 17]] )==16 assert count_list([[2, 4], [[6,8], [4,5,8]], [10, 12, 14]])==9 def count_list(input_list): re...
mbpp_data_859
Write a function to generate all sublists of a given list. assert sub_lists([10, 20, 30, 40])==[[], [10], [20], [30], [40], [10, 20], [10, 30], [10, 40], [20, 30], [20, 40], [30, 40], [10, 20, 30], [10, 20, 40], [10, 30, 40], [20, 30, 40], [10, 20, 30, 40]] assert sub_lists(['X', 'Y', 'Z'])==[[], ['X'], ['Y'], ['Z'], [...
mbpp_data_860
Write a function to check whether the given string is ending with only alphanumeric characters or not using regex. assert check_alphanumeric("dawood@") == 'Discard' assert check_alphanumeric("skdmsam326") == 'Accept' assert check_alphanumeric("cooltricks@") == 'Discard' import re regex = '[a-zA-z0-9]$' def check_alp...
mbpp_data_861
Write a function to find all anagrams of a string in a given list of strings using lambda function. assert anagram_lambda(["bcda", "abce", "cbda", "cbea", "adcb"],"abcd")==['bcda', 'cbda', 'adcb'] assert anagram_lambda(["recitals"," python"], "articles" )==["recitals"] assert anagram_lambda([" keep"," abcdef"," xyz"],"...
mbpp_data_862
Write a function to find the occurrences of n most common words in a given text. assert n_common_words("python is a programming language",1)==[('python', 1)] assert n_common_words("python is a programming language",1)==[('python', 1)] assert n_common_words("python is a programming language",5)==[('python', 1),('is', 1)...
mbpp_data_863
Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers. assert find_longest_conseq_subseq([1, 2, 2, 3], 4) == 3 assert find_longest_conseq_subseq([1, 9, 3, 10, 4, 20, 2], 7) == 4 assert find_longest_conseq_subseq([36, 41, 56, 35, 44, 33, 34, 92, 4...
mbpp_data_864
Write a function to find palindromes in a given list of strings using lambda function. assert palindrome_lambda(["php", "res", "Python", "abcd", "Java", "aaa"])==['php', 'aaa'] assert palindrome_lambda(["abcd", "Python", "abba", "aba"])==['abba', 'aba'] assert palindrome_lambda(["abcd", "abbccbba", "abba", "aba"])==['a...
mbpp_data_865
Write a function to print n-times a list using map function. assert ntimes_list([1, 2, 3, 4, 5, 6, 7],3)==[3, 6, 9, 12, 15, 18, 21] assert ntimes_list([1, 2, 3, 4, 5, 6, 7],4)==[4, 8, 12, 16, 20, 24, 28] assert ntimes_list([1, 2, 3, 4, 5, 6, 7],10)==[10, 20, 30, 40, 50, 60, 70] def ntimes_list(nums,n): result = ma...
mbpp_data_866
Write a function to check whether the given month name contains 31 days or not. assert check_monthnumb("February")==False assert check_monthnumb("January")==True assert check_monthnumb("March")==True def check_monthnumb(monthname2): if(monthname2=="January" or monthname2=="March"or monthname2=="May" or monthname2=="...
mbpp_data_867
Write a python function to add a minimum number such that the sum of array becomes even. assert min_Num([1,2,3,4,5,6,7,8,9],9) == 1 assert min_Num([1,2,3,4,5,6,7,8],8) == 2 assert min_Num([1,2,3],3) == 2 def min_Num(arr,n): odd = 0 for i in range(n): if (arr[i] % 2): odd += 1 i...
mbpp_data_868
Write a python function to find the length of the last word in a given string. assert length_Of_Last_Word("python language") == 8 assert length_Of_Last_Word("PHP") == 3 assert length_Of_Last_Word("") == 0 def length_Of_Last_Word(a): l = 0 x = a.strip() for i in range(len(x)): if x[i] == " ": ...
mbpp_data_869
Write a function to remove sublists from a given list of lists, which are outside a given range. assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],13,17)==[[13, 14, 15, 17]] assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],1,3)==[[...
mbpp_data_870
Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function. assert sum_positivenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==48 assert sum_positivenum([10,15,-14,13,-18,12,-20])==50 assert sum_positivenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==522 def sum_positi...
mbpp_data_871
Write a python function to check whether the given strings are rotations of each other or not. assert are_Rotations("abc","cba") == False assert are_Rotations("abcd","cdba") == False assert are_Rotations("abacd","cdaba") == True def are_Rotations(string1,string2): size1 = len(string1) size2 = len(string2) ...
mbpp_data_872
Write a function to check if a nested list is a subset of another nested list. assert check_subset([[1, 3], [5, 7], [9, 11], [13, 15, 17]] ,[[1, 3],[13,15,17]])==True assert check_subset([[1, 2], [2, 3], [3, 4], [5, 6]],[[3, 4], [5, 6]])==True assert check_subset([[[1, 2], [2, 3]], [[3, 4], [5, 7]]],[[[3, 4], [5, 6]]])...
mbpp_data_873
Write a function to solve the fibonacci sequence using recursion. assert fibonacci(7) == 13 assert fibonacci(8) == 21 assert fibonacci(9) == 34 def fibonacci(n): if n == 1 or n == 2: return 1 else: return (fibonacci(n - 1) + (fibonacci(n - 2)))
mbpp_data_874
Write a python function to check if the string is a concatenation of another string. assert check_Concat("abcabcabc","abc") == True assert check_Concat("abcab","abc") == False assert check_Concat("aba","ab") == False def check_Concat(str1,str2): N = len(str1) M = len(str2) if (N % M != 0): retur...
mbpp_data_875
Write a function to find the minimum difference in the tuple pairs of given tuples. assert min_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 1 assert min_difference([(4, 6), (12, 8), (11, 4), (2, 13)]) == 2 assert min_difference([(5, 17), (3, 9), (12, 5), (3, 24)]) == 6 def min_difference(test_list): temp = [abs(...
mbpp_data_876
Write a python function to find lcm of two positive integers. assert lcm(4,6) == 12 assert lcm(15,17) == 255 assert lcm(2,6) == 6 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...
mbpp_data_877
Write a python function to sort the given string. assert sort_String("cba") == "abc" assert sort_String("data") == "aadt" assert sort_String("zxy") == "xyz" def sort_String(str) : str = ''.join(sorted(str)) return (str)
mbpp_data_878
Write a function to check if the given tuple contains only k elements. assert check_tuples((3, 5, 6, 5, 3, 6),[3, 6, 5]) == True assert check_tuples((4, 5, 6, 4, 6, 5),[4, 5, 6]) == True assert check_tuples((9, 8, 7, 6, 8, 9),[9, 8, 1]) == False def check_tuples(test_tuple, K): res = all(ele in K for ele in test_tup...
mbpp_data_879
Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex. assert text_match("aabbbbd") == 'Not matched!' assert text_match("aabAbbbc") == 'Not matched!' assert text_match("accddbbjjjb") == 'Found a match!' import re def text_match(text): patterns = 'a.*?b$' if re....
mbpp_data_880
Write a python function to find number of solutions in quadratic equation. assert Check_Solution(2,5,2) == "2 solutions" assert Check_Solution(1,1,1) == "No solutions" assert Check_Solution(1,2,1) == "1 solution" def Check_Solution(a,b,c) : if ((b*b) - (4*a*c)) > 0 : return ("2 solutions") elif ((...
mbpp_data_881
Write a function to find the sum of first even and odd number of a given list. assert sum_even_odd([1,3,5,7,4,1,6,8])==5 assert sum_even_odd([1,2,3,4,5,6,7,8,9,10])==3 assert sum_even_odd([1,5,7,9,10])==11 def sum_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el for ...
mbpp_data_882
Write a function to caluclate perimeter of a parallelogram. assert parallelogram_perimeter(10,20)==400 assert parallelogram_perimeter(15,20)==600 assert parallelogram_perimeter(8,9)==144 def parallelogram_perimeter(b,h): perimeter=2*(b*h) return perimeter
mbpp_data_883
Write a function to find numbers divisible by m and n from a list of numbers using lambda function. assert div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190],2,4)==[ 152,44] assert div_of_nums([1, 2, 3, 5, 7, 8, 10],2,5)==[10] assert div_of_nums([10,15,14,13,18,12,20],10,5)==[10,20] def div_of_nums(nums,m,n): r...
mbpp_data_884
Write a python function to check whether all the bits are within a given range or not. assert all_Bits_Set_In_The_Given_Range(10,2,1) == True assert all_Bits_Set_In_The_Given_Range(5,2,4) == False assert all_Bits_Set_In_The_Given_Range(22,2,3) == True def all_Bits_Set_In_The_Given_Range(n,l,r): num = ((1 << r) ...
mbpp_data_885
Write a python function to check whether the two given strings are isomorphic to each other or not. assert is_Isomorphic("paper","title") == True assert is_Isomorphic("ab","ba") == True assert is_Isomorphic("ab","aa") == False def is_Isomorphic(str1,str2): dict_str1 = {} dict_str2 = {} for i, v...
mbpp_data_886
Write a function to add all the numbers in a list and divide it with the length of the list. assert sum_num((8, 2, 3, 0, 7))==4.0 assert sum_num((-10,-20,-30))==-20.0 assert sum_num((19,15,18))==17.333333333333332 def sum_num(numbers): total = 0 for x in numbers: total += x return total/len(numb...
mbpp_data_887
Write a python function to check whether the given number is odd or not using bitwise operator. assert is_odd(5) == True assert is_odd(6) == False assert is_odd(7) == True def is_odd(n) : if (n^1 == n-1) : return True; else : return False;
mbpp_data_888
Write a function to substract the elements of the given nested tuples. assert substract_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((-5, -4), (1, -4), (1, 8), (-6, 7)) assert substract_elements(((13, 4), (14, 6), (13, 10), (12, 11)), ((19, 8), (14, 10), (12, 2), (18, 4))) == ((-6, ...
mbpp_data_889
Write a function to reverse each list in a given list of lists. assert reverse_list_lists([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])==[[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9], [16, 15, 14, 13]] assert reverse_list_lists([[1,2],[2,3],[3,4]])==[[2,1],[3,2],[4,3]] assert reverse_list_lists([[10,2...
mbpp_data_890
Write a python function to find the index of an extra element present in one sorted array. assert find_Extra([1,2,3,4],[1,2,3],3) == 3 assert find_Extra([2,4,6,8,10],[2,4,6,8],4) == 4 assert find_Extra([1,3,5,7,9,11],[1,3,5,7,9],5) == 5 def find_Extra(arr1,arr2,n) : for i in range(0, n) : if (arr1[i] !=...
mbpp_data_891
Write a python function to check whether the given two numbers have same number of digits or not. assert same_Length(12,1) == False assert same_Length(2,2) == True assert same_Length(10,20) == True def same_Length(A,B): while (A > 0 and B > 0): A = A / 10; B = B / 10; if (A == 0 and B ==...
mbpp_data_892
Write a function to remove multiple spaces in a string. assert remove_spaces('python program')==('python program') assert remove_spaces('python programming language')==('python programming language') assert remove_spaces('python program')==('python program') import re def remove_spaces(text):...
mbpp_data_893
Write a python function to get the last element of each sublist. assert Extract([[1, 2, 3], [4, 5], [6, 7, 8, 9]]) == [3, 5, 9] assert Extract([['x', 'y', 'z'], ['m'], ['a', 'b'], ['u', 'v']]) == ['z', 'm', 'b', 'v'] assert Extract([[1, 2, 3], [4, 5]]) == [3, 5] def Extract(lst): return [item[-1] for item in lst]...
mbpp_data_894
Write a function to convert the given string of float type into tuple. assert float_to_tuple("1.2, 1.3, 2.3, 2.4, 6.5") == (1.2, 1.3, 2.3, 2.4, 6.5) assert float_to_tuple("2.3, 2.4, 5.6, 5.4, 8.9") == (2.3, 2.4, 5.6, 5.4, 8.9) assert float_to_tuple("0.3, 0.5, 7.8, 9.4") == (0.3, 0.5, 7.8, 9.4) def float_to_tuple(test_s...
mbpp_data_895
Write a function to find the maximum sum of subsequences of given array with no adjacent elements. assert max_sum_subseq([1, 2, 9, 4, 5, 0, 4, 11, 6]) == 26 assert max_sum_subseq([1, 2, 9, 5, 6, 0, 5, 12, 7]) == 28 assert max_sum_subseq([1, 3, 10, 5, 6, 0, 6, 14, 21]) == 44 def max_sum_subseq(A): n = len(A) i...
mbpp_data_896
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. assert sort_list_last([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)])==[(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)] assert sort_list_last([(9,8), (4, 7), (3,5), (7,9), (1,2)])==[(1,2), (3,5), (4,7), (9,8)...
mbpp_data_897
Write a python function to check whether the word is present in a given sentence or not. assert is_Word_Present("machine learning","machine") == True assert is_Word_Present("easy","fun") == False assert is_Word_Present("python language","code") == False def is_Word_Present(sentence,word): s = sentence.split(" ") ...
mbpp_data_898
Write a function to extract specified number of elements from a given list, which follow each other continuously. assert extract_elements([1, 1, 3, 4, 4, 5, 6, 7],2)==[1, 4] assert extract_elements([0, 1, 2, 3, 4, 4, 4, 4, 5, 7],4)==[4] assert extract_elements([0,0,0,0,0],5)==[0] from itertools import groupby def ext...
mbpp_data_899
Write a python function to check whether an array can be sorted or not by picking only the corner elements. assert check([3,2,1,2,3,4],6) == True assert check([2,1,4,5,1],5) == True assert check([1,2,2,1,2,3],6) == True def check(arr,n): g = 0 for i in range(1,n): if (arr[i] - arr[i - 1] > 0 and g...
mbpp_data_900
Write a function where a string will start with a specific number. assert match_num('5-2345861')==True assert match_num('6-2345861')==False assert match_num('78910')==False import re def match_num(string): text = re.compile(r"^5") if text.match(string): return True else: return False