id
stringlengths
11
13
content
stringlengths
165
5.63k
mbpp_data_437
Write a function to remove odd characters in a string. assert remove_odd("python")==("yhn") assert remove_odd("program")==("rga") assert remove_odd("language")==("agae") 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_data_438
Write a function to count bidirectional tuple pairs. assert count_bidirectional([(5, 6), (1, 2), (6, 5), (9, 1), (6, 5), (2, 1)] ) == '3' assert count_bidirectional([(5, 6), (1, 3), (6, 5), (9, 1), (6, 5), (2, 1)] ) == '2' assert count_bidirectional([(5, 6), (1, 2), (6, 5), (9, 2), (6, 5), (2, 1)] ) == '4' def count_bi...
mbpp_data_439
Write a function to convert a list of multiple integers into a single integer. assert multiple_to_single([11, 33, 50])==113350 assert multiple_to_single([-1,2,3,4,5,6])==-123456 assert multiple_to_single([10,15,20,25])==10152025 def multiple_to_single(L): x = int("".join(map(str, L))) return x
mbpp_data_440
Write a function to find all adverbs and their positions in a given sentence. assert find_adverb_position("clearly!! we can see the sky")==(0, 7, 'clearly') assert find_adverb_position("seriously!! there are many roses")==(0, 9, 'seriously') assert find_adverb_position("unfortunately!! sita is going to home")==(0, 13, ...
mbpp_data_441
Write a function to find the surface area of a cube. assert surfacearea_cube(5)==150 assert surfacearea_cube(3)==54 assert surfacearea_cube(10)==600 def surfacearea_cube(l): surfacearea= 6*l*l return surfacearea
mbpp_data_442
Write a function to find the ration of positive numbers in an array of integers. assert positive_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8])==0.54 assert positive_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==0.69 assert positive_count([2, 4, -6, -9, 11, -12, 14, -5, 17])==0.56 from array import array def...
mbpp_data_443
Write a python function to find the largest negative number from the given list. assert largest_neg([1,2,3,-4,-6]) == -6 assert largest_neg([1,2,3,-8,-9]) == -9 assert largest_neg([1,2,3,4,-1]) == -1 def largest_neg(list1): max = list1[0] for x in list1: if x < max : max = x ...
mbpp_data_444
Write a function to trim each tuple by k in the given tuple list. assert trim_tuple([(5, 3, 2, 1, 4), (3, 4, 9, 2, 1),(9, 1, 2, 3, 5), (4, 8, 2, 1, 7)], 2) == '[(2,), (9,), (2,), (2,)]' assert trim_tuple([(5, 3, 2, 1, 4), (3, 4, 9, 2, 1), (9, 1, 2, 3, 5), (4, 8, 2, 1, 7)], 1) == '[(3, 2, 1), (4, 9, 2), (1, 2, 3), (8, 2...
mbpp_data_445
Write a function to perform index wise multiplication of tuple elements in the given two tuples. assert index_multiplication(((1, 3), (4, 5), (2, 9), (1, 10)),((6, 7), (3, 9), (1, 1), (7, 3)) ) == ((6, 21), (12, 45), (2, 9), (7, 30)) assert index_multiplication(((2, 4), (5, 6), (3, 10), (2, 11)),((7, 8), (4, 10), (2, 2...
mbpp_data_446
Write a python function to count the occurence of all elements of list in a tuple. assert count_Occurrence(('a', 'a', 'c', 'b', 'd'),['a', 'b'] ) == 3 assert count_Occurrence((1, 2, 3, 1, 4, 6, 7, 1, 4),[1, 4, 7]) == 6 assert count_Occurrence((1,2,3,4,5,6),[1,2]) == 2 from collections import Counter def count_Occurre...
mbpp_data_447
Write a function to find cubes of individual elements in a list using lambda function. assert cube_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000] assert cube_nums([10,20,30])==([1000, 8000, 27000]) assert cube_nums([12,15])==([1728, 3375]) def cube_nums(nums): cube_nums = list(ma...
mbpp_data_448
Write a function to calculate the sum of perrin numbers. assert cal_sum(9) == 49 assert cal_sum(10) == 66 assert cal_sum(11) == 88 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...
mbpp_data_449
Write a python function to check whether the triangle is valid or not if 3 points are given. assert check_Triangle(1,5,2,5,4,6) == 'Yes' assert check_Triangle(1,1,1,4,1,5) == 'No' assert check_Triangle(1,1,1,1,1,1) == 'No' def check_Triangle(x1,y1,x2,y2,x3,y3): a = (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)) if a ...
mbpp_data_450
Write a function to extract specified size of strings from a give list of string values. assert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,8)==['practice', 'solution'] assert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,6)==['Python'] assert extract_string(['Pytho...
mbpp_data_451
Write a function to remove all whitespaces from the given string using regex. assert remove_whitespaces(' Google Flutter ') == 'GoogleFlutter' assert remove_whitespaces(' Google Dart ') == 'GoogleDart' assert remove_whitespaces(' iOS Swift ') == 'iOSSwift' import re def remove_whitespaces(text1): return (r...
mbpp_data_452
Write a function that gives loss amount if the given amount has loss else return none. assert loss_amount(1500,1200)==None assert loss_amount(100,200)==100 assert loss_amount(2000,5000)==3000 def loss_amount(actual_cost,sale_amount): if(sale_amount > actual_cost): amount = sale_amount - actual_cost return...
mbpp_data_453
Write a python function to find the sum of even factors of a number. assert sumofFactors(18) == 26 assert sumofFactors(30) == 48 assert sumofFactors(6) == 8 import math def sumofFactors(n) : if (n % 2 != 0) : return 0 res = 1 for i in range(2, (int)(math.sqrt(n)) + 1) : count = ...
mbpp_data_454
Write a function that matches a word containing 'z'. assert text_match_wordz("pythonz.")==('Found a match!') assert text_match_wordz("xyz.")==('Found a match!') assert text_match_wordz(" lang .")==('Not matched!') import re def text_match_wordz(text): patterns = '\w*z.\w*' if re.search(patterns, t...
mbpp_data_455
Write a function to check whether the given month number contains 31 days or not. assert check_monthnumb_number(5)==True assert check_monthnumb_number(2)==False assert check_monthnumb_number(6)==False def check_monthnumb_number(monthnum2): if(monthnum2==1 or monthnum2==3 or monthnum2==5 or monthnum2==7 or monthnum2=...
mbpp_data_456
Write a function to reverse strings in a given list of string values. assert reverse_string_list(['Red', 'Green', 'Blue', 'White', 'Black'])==['deR', 'neerG', 'eulB', 'etihW', 'kcalB'] assert reverse_string_list(['john','amal','joel','george'])==['nhoj','lama','leoj','egroeg'] assert reverse_string_list(['jack','john',...
mbpp_data_457
Write a python function to find the sublist having minimum length. assert Find_Min([[1],[1,2],[1,2,3]]) == [1] assert Find_Min([[1,1],[1,1,1],[1,2,7,8]]) == [1,1] assert Find_Min([['x'],['x','y'],['x','y','z']]) == ['x'] def Find_Min(lst): minList = min((x) for x in lst) return minList
mbpp_data_458
Write a function to find the area of a rectangle. assert rectangle_area(10,20)==200 assert rectangle_area(10,5)==50 assert rectangle_area(4,2)==8 def rectangle_area(l,b): area=l*b return area
mbpp_data_459
Write a function to remove uppercase substrings from a given string by using regex. assert remove_uppercase('cAstyoUrFavoRitETVshoWs') == 'cstyoravoitshos' assert remove_uppercase('wAtchTheinTernEtrAdIo') == 'wtchheinerntrdo' assert remove_uppercase('VoicESeaRchAndreComMendaTionS') == 'oiceachndreomendaion' import re ...
mbpp_data_460
Write a python function to get the first element of each sublist. assert Extract([[1, 2], [3, 4, 5], [6, 7, 8, 9]]) == [1, 3, 6] assert Extract([[1,2,3],[4, 5]]) == [1,4] assert Extract([[9,8,1],[1,2]]) == [9,1] def Extract(lst): return [item[0] for item in lst]
mbpp_data_461
Write a python function to count the upper case characters in a given string. assert upper_ctr('PYthon') == 1 assert upper_ctr('BigData') == 1 assert upper_ctr('program') == 0 def upper_ctr(str): upper_ctr = 0 for i in range(len(str)): if str[i] >= 'A' and str[i] <= 'Z': upper_ctr += 1 r...
mbpp_data_462
Write a function to find all possible combinations of the elements of a given list. assert combinations_list(['orange', 'red', 'green', 'blue'])==[[], ['orange'], ['red'], ['red', 'orange'], ['green'], ['green', 'orange'], ['green', 'red'], ['green', 'red', 'orange'], ['blue'], ['blue', 'orange'], ['blue', 'red'], ['bl...
mbpp_data_463
Write a function to find the maximum product subarray of the given array. assert max_subarray_product([1, -2, -3, 0, 7, -8, -2]) == 112 assert max_subarray_product([6, -3, -10, 0, 2]) == 180 assert max_subarray_product([-2, -40, 0, -2, -3]) == 80 def max_subarray_product(arr): n = len(arr) max_ending_here = 1 mi...
mbpp_data_464
Write a function to check if all values are same in a dictionary. assert check_value({'Cierra Vega': 12, 'Alden Cantrell': 12, 'Kierra Gentry': 12, 'Pierre Cox': 12},10)==False assert check_value({'Cierra Vega': 12, 'Alden Cantrell': 12, 'Kierra Gentry': 12, 'Pierre Cox': 12},12)==True assert check_value({'Cierra Vega'...
mbpp_data_465
Write a function to drop empty items from a given dictionary. assert drop_empty({'c1': 'Red', 'c2': 'Green', 'c3':None})=={'c1': 'Red', 'c2': 'Green'} assert drop_empty({'c1': 'Red', 'c2': None, 'c3':None})=={'c1': 'Red'} assert drop_empty({'c1': None, 'c2': 'Green', 'c3':None})=={ 'c2': 'Green'} def drop_empty(dict1):...
mbpp_data_466
Write a function to find the peak element in the given array. assert find_peak([1, 3, 20, 4, 1, 0], 6) == 2 assert find_peak([2, 3, 4, 5, 6], 5) == 4 assert find_peak([8, 9, 11, 12, 14, 15], 6) == 5 def find_peak_util(arr, low, high, n): mid = low + (high - low)/2 mid = int(mid) if ((mid == 0 or arr[mid - 1] <...
mbpp_data_467
Write a python function to convert decimal number to octal number. assert decimal_to_Octal(10) == 12 assert decimal_to_Octal(2) == 2 assert decimal_to_Octal(33) == 41 def decimal_to_Octal(deciNum): octalNum = 0 countval = 1; dNo = deciNum; while (deciNum!= 0): remainder= deciNum % 8; ...
mbpp_data_468
Write a function to find the maximum product formed by multiplying numbers of an increasing subsequence of that array. assert max_product([3, 100, 4, 5, 150, 6], 6) == 45000 assert max_product([4, 42, 55, 68, 80], 5) == 50265600 assert max_product([10, 22, 9, 33, 21, 50, 41, 60], 8) == 21780000 def max_product(arr, n...
mbpp_data_469
Write a function to find the maximum profit earned from a maximum of k stock transactions assert max_profit([1, 5, 2, 3, 7, 6, 4, 5], 3) == 10 assert max_profit([2, 4, 7, 5, 4, 3, 5], 2) == 7 assert max_profit([10, 6, 8, 4, 2], 2) == 2 def max_profit(price, k): n = len(price) final_profit = [[None for x in ra...
mbpp_data_470
Write a function to find the pairwise addition of the elements of the given tuples. assert add_pairwise((1, 5, 7, 8, 10)) == (6, 12, 15, 18) assert add_pairwise((2, 6, 8, 9, 11)) == (8, 14, 17, 20) assert add_pairwise((3, 7, 9, 10, 12)) == (10, 16, 19, 22) def add_pairwise(test_tup): res = tuple(i + j for i, j in zi...
mbpp_data_471
Write a python function to find remainder of array multiplication divided by n. assert find_remainder([ 100, 10, 5, 25, 35, 14 ],6,11) ==9 assert find_remainder([1,1,1],3,1) == 0 assert find_remainder([1,2,1],3,2) == 0 def find_remainder(arr, lens, n): mul = 1 for i in range(lens): mul = (mul * (a...
mbpp_data_472
Write a python function to check whether the given list contains consecutive numbers or not. assert check_Consecutive([1,2,3,4,5]) == True assert check_Consecutive([1,2,3,5,6]) == False assert check_Consecutive([1,2,1]) == False def check_Consecutive(l): return sorted(l) == list(range(min(l),max(l)+1))
mbpp_data_473
Write a function to find the tuple intersection of elements in the given tuple list irrespective of their order. assert tuple_intersection([(3, 4), (5, 6), (9, 10), (4, 5)] , [(5, 4), (3, 4), (6, 5), (9, 11)]) == {(4, 5), (3, 4), (5, 6)} assert tuple_intersection([(4, 1), (7, 4), (11, 13), (17, 14)] , [(1, 4), (7, 4), ...
mbpp_data_474
Write a function to replace characters in a string. assert replace_char("polygon",'y','l')==("pollgon") assert replace_char("character",'c','a')==("aharaater") assert replace_char("python",'l','a')==("python") def replace_char(str1,ch,newch): str2 = str1.replace(ch, newch) return str2
mbpp_data_475
Write a function to sort counter by value. assert sort_counter({'Math':81, 'Physics':83, 'Chemistry':87})==[('Chemistry', 87), ('Physics', 83), ('Math', 81)] assert sort_counter({'Math':400, 'Physics':300, 'Chemistry':250})==[('Math', 400), ('Physics', 300), ('Chemistry', 250)] assert sort_counter({'Math':900, 'Physics...
mbpp_data_476
Write a python function to find the sum of the largest and smallest value in a given array. assert big_sum([1,2,3]) == 4 assert big_sum([-1,2,3,4]) == 3 assert big_sum([2,3,6]) == 8 def big_sum(nums): sum= max(nums)+min(nums) return sum
mbpp_data_477
Write a python function to convert the given string to lower case. assert is_lower("InValid") == "invalid" assert is_lower("TruE") == "true" assert is_lower("SenTenCE") == "sentence" def is_lower(string): return (string.lower())
mbpp_data_478
Write a function to remove lowercase substrings from a given string. assert remove_lowercase("PYTHon")==('PYTH') assert remove_lowercase("FInD")==('FID') assert remove_lowercase("STRinG")==('STRG') import re def remove_lowercase(str1): remove_lower = lambda text: re.sub('[a-z]', '', text) result = remove_lower(st...
mbpp_data_479
Write a python function to find the first digit of a given number. assert first_Digit(123) == 1 assert first_Digit(456) == 4 assert first_Digit(12) == 1 def first_Digit(n) : while n >= 10: n = n / 10; return int(n)
mbpp_data_480
Write a python function to find the maximum occurring character in a given string. assert get_max_occuring_char("data") == "a" assert get_max_occuring_char("create") == "e" assert get_max_occuring_char("brilliant girl") == "i" def get_max_occuring_char(str1): ASCII_SIZE = 256 ctr = [0] * ASCII_SIZE max = -1 ...
mbpp_data_481
Write a function to determine if there is a subset of the given set with sum equal to the given sum. assert is_subset_sum([3, 34, 4, 12, 5, 2], 6, 9) == True assert is_subset_sum([3, 34, 4, 12, 5, 2], 6, 30) == False assert is_subset_sum([3, 34, 4, 12, 5, 2], 6, 15) == True def is_subset_sum(set, n, sum): if (sum == ...
mbpp_data_482
Write a function to find sequences of one upper case letter followed by lower case letters in the given string by using regex. assert match("Geeks") == 'Yes' assert match("geeksforGeeks") == 'Yes' assert match("geeks") == 'No' import re def match(text): pattern = '[A-Z]+[a-z]+$' if re.search(pattern, text): ...
mbpp_data_483
Write a python function to find the first natural number whose factorial is divisible by x. assert first_Factorial_Divisible_Number(10) == 5 assert first_Factorial_Divisible_Number(15) == 5 assert first_Factorial_Divisible_Number(5) == 4 def first_Factorial_Divisible_Number(x): i = 1; fact = 1; for i i...
mbpp_data_484
Write a function to remove the matching tuples from the given two tuples. assert remove_matching_tuple([('Hello', 'dude'), ('How', 'are'), ('you', '?')], [('Hello', 'dude'), ('How', 'are')]) == [('you', '?')] assert remove_matching_tuple([('Part', 'of'), ('the', 'journey'), ('is ', 'end')], [('Journey', 'the'), ('is', ...
mbpp_data_485
Write a function to find the largest palindromic number in the given array. assert largest_palindrome([1, 232, 54545, 999991], 4) == 54545 assert largest_palindrome([1, 2, 3, 4, 5, 50], 6) == 5 assert largest_palindrome([1, 3, 7, 9, 45], 5) == 9 def is_palindrome(n) : divisor = 1 while (n / divisor >= 10) : d...
mbpp_data_486
Write a function to compute binomial probability for the given number. assert binomial_probability(10, 5, 1.0/3) == 0.13656454808718185 assert binomial_probability(11, 6, 2.0/4) == 0.2255859375 assert binomial_probability(12, 7, 3.0/5) == 0.227030335488 def nCr(n, r): if (r > n / 2): r = n - r answer = 1 f...
mbpp_data_487
Write a function to sort a list of tuples in increasing order by the last element in each tuple. assert sort_tuple([(1, 3), (3, 2), (2, 1)] ) == [(2, 1), (3, 2), (1, 3)] assert sort_tuple([(2, 4), (3, 3), (1, 1)] ) == [(1, 1), (3, 3), (2, 4)] assert sort_tuple([(3, 9), (6, 7), (4, 3)] ) == [(4, 3), (6, 7), (3, 9)] def ...
mbpp_data_488
Write a function to find the area of a pentagon. assert area_pentagon(5)==43.01193501472417 assert area_pentagon(10)==172.0477400588967 assert area_pentagon(15)==387.10741513251753 import math def area_pentagon(a): area=(math.sqrt(5*(5+2*math.sqrt(5)))*pow(a,2))/4.0 return area
mbpp_data_489
Write a python function to find the frequency of the largest value in a given array. assert frequency_Of_Largest(5,[1,2,3,4,4]) == 2 assert frequency_Of_Largest(3,[5,6,5]) == 1 assert frequency_Of_Largest(4,[2,7,7,7]) == 3 def frequency_Of_Largest(n,arr): mn = arr[0] freq = 1 for i in range(1,n): ...
mbpp_data_490
Write a function to extract all the pairs which are symmetric in the given tuple list. assert extract_symmetric([(6, 7), (2, 3), (7, 6), (9, 8), (10, 2), (8, 9)] ) == {(8, 9), (6, 7)} assert extract_symmetric([(7, 8), (3, 4), (8, 7), (10, 9), (11, 3), (9, 10)] ) == {(9, 10), (7, 8)} assert extract_symmetric([(8, 9), (4...
mbpp_data_491
Write a function to find the sum of geometric progression series. assert sum_gp(1,5,2)==31 assert sum_gp(1,5,4)==341 assert sum_gp(2,6,3)==728 import math def sum_gp(a,n,r): total = (a * (1 - math.pow(r, n ))) / (1- r) return total
mbpp_data_492
Write a function to search an element in the given array by using binary search. assert binary_search([1,2,3,5,8], 6) == False assert binary_search([7, 8, 9, 10, 13], 10) == True assert binary_search([11, 13, 14, 19, 22, 36], 23) == False def binary_search(item_list,item): first = 0 last = len(item_list)-1 found ...
mbpp_data_493
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. assert calculate_polygons(1,1, 4, 4, 3)==[[(-5.0, -4.196152422706632), (-5.0, -0.7320508075688767), (-2.0, 1.0), (1.0, -0.7320508075688767), (1.0, -4.196152422706632), (-2.0,...
mbpp_data_494
Write a function to convert the given binary tuple to integer. assert binary_to_integer((1, 1, 0, 1, 0, 0, 1)) == '105' assert binary_to_integer((0, 1, 1, 0, 0, 1, 0, 1)) == '101' assert binary_to_integer((1, 1, 0, 1, 0, 1)) == '53' def binary_to_integer(test_tup): res = int("".join(str(ele) for ele in test_tup), 2)...
mbpp_data_495
Write a function to remove lowercase substrings from a given string by using regex. assert remove_lowercase('KDeoALOklOOHserfLoAJSIskdsf') == 'KDALOOOHLAJSI' assert remove_lowercase('ProducTnamEstreAmIngMediAplAYer') == 'PTEAIMAAY' assert remove_lowercase('maNufacTuredbYSheZenTechNolOGIes') == 'NTYSZTNOGI' import re d...
mbpp_data_496
Write a function to find the smallest integers from a given list of numbers using heap queue algorithm. assert heap_queue_smallest( [25, 35, 22, 85, 14, 65, 75, 25, 58],3)==[14, 22, 25] assert heap_queue_smallest( [25, 35, 22, 85, 14, 65, 75, 25, 58],2)==[14, 22] assert heap_queue_smallest( [25, 35, 22, 85, 14, 65, 75...
mbpp_data_497
Write a function to find the surface area of a cone. assert surfacearea_cone(5,12)==282.7433388230814 assert surfacearea_cone(10,15)==880.5179353159282 assert surfacearea_cone(19,17)==2655.923961165254 import math def surfacearea_cone(r,h): l = math.sqrt(r * r + h * h) SA = math.pi * r * (r + l) return SA
mbpp_data_498
Write a python function to find gcd of two positive integers. assert gcd(12, 17) == 1 assert gcd(4,6) == 2 assert gcd(2,9) == 1 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 ...
mbpp_data_499
Write a function to find the diameter of a circle. assert diameter_circle(10)==20 assert diameter_circle(40)==80 assert diameter_circle(15)==30 def diameter_circle(r): diameter=2*r return diameter
mbpp_data_500
Write a function to concatenate all elements of the given list into a string. assert concatenate_elements(['hello','there','have','a','rocky','day'] ) == ' hello there have a rocky day' assert concatenate_elements([ 'Hi', 'there', 'How','are', 'you'] ) == ' Hi there How are you' assert concatenate_elements([ 'Part', ...
mbpp_data_501
Write a python function to find common divisor between two numbers in a given pair. assert num_comm_div(2,4) == 2 assert num_comm_div(2,8) == 2 assert num_comm_div(12,24) == 6 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...
mbpp_data_502
Write a python function to find remainder of two numbers. assert find(3,3) == 0 assert find(10,3) == 1 assert find(16,5) == 1 def find(n,m): r = n%m return (r)
mbpp_data_503
Write a function to add consecutive numbers of a given list. assert add_consecutive_nums([1, 1, 3, 4, 4, 5, 6, 7])==[2, 4, 7, 8, 9, 11, 13] assert add_consecutive_nums([4, 5, 8, 9, 6, 10])==[9, 13, 17, 15, 16] assert add_consecutive_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[3, 5, 7, 9, 11, 13, 15, 17, 19] def add_consecu...
mbpp_data_504
Write a python function to find the cube sum of first n natural numbers. assert sum_Of_Series(5) == 225 assert sum_Of_Series(2) == 9 assert sum_Of_Series(3) == 36 def sum_Of_Series(n): sum = 0 for i in range(1,n + 1): sum += i * i*i return sum
mbpp_data_505
Write a function to move all zeroes to the end of the given array. assert re_order([6, 0, 8, 2, 3, 0, 4, 0, 1]) == [6, 8, 2, 3, 4, 1, 0, 0, 0] assert re_order([4, 0, 2, 7, 0, 9, 0, 12, 0]) == [4, 2, 7, 9, 12, 0, 0, 0, 0] assert re_order([3, 11, 0, 74, 14, 0, 1, 0, 2]) == [3, 11, 74, 14, 1, 2, 0, 0, 0] def re_order(A): ...
mbpp_data_506
Write a function to calculate the permutation coefficient of given p(n, k). assert permutation_coefficient(10, 2) == 90 assert permutation_coefficient(10, 3) == 720 assert permutation_coefficient(10, 1) == 10 def permutation_coefficient(n, k): P = [[0 for i in range(k + 1)] for j in range(n + 1)] for i in ra...
mbpp_data_507
Write a function to remove specific words from a given list. assert remove_words(['red', 'green', 'blue', 'white', 'black', 'orange'],['white', 'orange'])==['red', 'green', 'blue', 'black'] assert remove_words(['red', 'green', 'blue', 'white', 'black', 'orange'],['black', 'orange'])==['red', 'green', 'blue', 'white'] a...
mbpp_data_508
Write a function to check if the common elements between two given lists are in the same order or not. assert same_order(["red","green","black","orange"],["red","pink","green","white","black"])==True assert same_order(["red","pink","green","white","black"],["white","orange","pink","black"])==False assert same_order(["r...
mbpp_data_509
Write a python function to find the average of odd numbers till a given odd number. assert average_Odd(9) == 5 assert average_Odd(5) == 3 assert average_Odd(11) == 6 def average_Odd(n) : if (n%2==0) : return ("Invalid Input") return -1 sm =0 count =0 while (n>=1) : co...
mbpp_data_510
Write a function to find the number of subsequences having product smaller than k for the given non negative array. assert no_of_subsequences([1,2,3,4], 10) == 11 assert no_of_subsequences([4,8,7,2], 50) == 9 assert no_of_subsequences([5,6,7,8], 15) == 4 def no_of_subsequences(arr, k): n = len(arr) dp = [[0 for i...
mbpp_data_511
Write a python function to find minimum sum of factors of a given number. assert find_Min_Sum(12) == 7 assert find_Min_Sum(105) == 15 assert find_Min_Sum(2) == 2 def find_Min_Sum(num): sum = 0 i = 2 while(i * i <= num): while(num % i == 0): sum += i num /= i ...
mbpp_data_512
Write a function to count the element frequency in the mixed nested tuple. assert count_element_freq((5, 6, (5, 6), 7, (8, 9), 9) ) == {5: 2, 6: 2, 7: 1, 8: 1, 9: 2} assert count_element_freq((6, 7, (6, 7), 8, (9, 10), 10) ) == {6: 2, 7: 2, 8: 1, 9: 1, 10: 2} assert count_element_freq((7, 8, (7, 8), 9, (10, 11), 11) ) ...
mbpp_data_513
Write a function to convert tuple into list by adding the given string after every element. assert add_str((5, 6, 7, 4, 9) , "FDF") == [5, 'FDF', 6, 'FDF', 7, 'FDF', 4, 'FDF', 9, 'FDF'] assert add_str((7, 8, 9, 10) , "PF") == [7, 'PF', 8, 'PF', 9, 'PF', 10, 'PF'] assert add_str((11, 14, 12, 1, 4) , "JH") == [11, 'JH', ...
mbpp_data_514
Write a function to find the summation of tuple elements in the given tuple list. assert sum_elements((7, 8, 9, 1, 10, 7)) == 42 assert sum_elements((1, 2, 3, 4, 5, 6)) == 21 assert sum_elements((11, 12 ,13 ,45, 14)) == 95 def sum_elements(test_tup): res = sum(list(test_tup)) return (res)
mbpp_data_515
Write a function to check if there is a subset with sum divisible by m. assert modular_sum([3, 1, 7, 5], 4, 6) == True assert modular_sum([1, 7], 2, 5) == False assert modular_sum([1, 6], 2, 5) == False def modular_sum(arr, n, m): if (n > m): return True DP = [False for i in range(m)] for i in range(n): ...
mbpp_data_516
Write a function to sort a list of elements using radix sort. assert radix_sort([15, 79, 25, 68, 37]) == [15, 25, 37, 68, 79] assert radix_sort([9, 11, 8, 7, 3, 2]) == [2, 3, 7, 8, 9, 11] assert radix_sort([36, 12, 24, 26, 29]) == [12, 24, 26, 29, 36] def radix_sort(nums): RADIX = 10 placement = 1 max_di...
mbpp_data_517
Write a python function to find the largest postive number from the given list. assert largest_pos([1,2,3,4,-1]) == 4 assert largest_pos([0,1,2,-5,-1,6]) == 6 assert largest_pos([0,0,1,0]) == 1 def largest_pos(list1): max = list1[0] for x in list1: if x > max : max = x return...
mbpp_data_518
Write a function to find the square root of a perfect number. assert sqrt_root(4)==2 assert sqrt_root(16)==4 assert sqrt_root(400)==20 import math def sqrt_root(num): sqrt_root = math.pow(num, 0.5) return sqrt_root
mbpp_data_519
Write a function to calculate volume of a tetrahedron. assert volume_tetrahedron(10)==117.85 assert volume_tetrahedron(15)==397.75 assert volume_tetrahedron(20)==942.81 import math def volume_tetrahedron(num): volume = (num ** 3 / (6 * math.sqrt(2))) return round(volume, 2)
mbpp_data_520
Write a function to find the lcm of the given array elements. assert get_lcm([2, 7, 3, 9, 4]) == 252 assert get_lcm([1, 2, 8, 3]) == 24 assert get_lcm([3, 8, 4, 10, 5]) == 120 def find_lcm(num1, num2): if(num1>num2): num = num1 den = num2 else: num = num2 den = num1 rem = num % den while (re...
mbpp_data_521
Write a function to print check if the triangle is scalene or not. assert check_isosceles(6,8,12)==True assert check_isosceles(6,6,12)==False assert check_isosceles(6,15,20)==True def check_isosceles(x,y,z): if x!=y & y!=z & z!=x: return True else: return False
mbpp_data_522
Write a function to find the longest bitonic subsequence for the given array. assert lbs([0 , 8 , 4, 12, 2, 10 , 6 , 14 , 1 , 9 , 5 , 13, 3, 11 , 7 , 15]) == 7 assert lbs([1, 11, 2, 10, 4, 5, 2, 1]) == 6 assert lbs([80, 60, 30, 40, 20, 10]) == 5 def lbs(arr): n = len(arr) lis = [1 for i in range(n+1)] for i in...
mbpp_data_523
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. assert check_string('python')==['String must have 1 upper case character.', 'String must have 1 number.', 'String length should be atleast 8.'] assert check_string('123python'...
mbpp_data_524
Write a function to find the sum of maximum increasing subsequence of the given array. assert max_sum_increasing_subsequence([1, 101, 2, 3, 100, 4, 5], 7) == 106 assert max_sum_increasing_subsequence([3, 4, 5, 10], 4) == 22 assert max_sum_increasing_subsequence([10, 5, 4, 3], 4) == 10 def max_sum_increasing_subsequence...
mbpp_data_525
Write a python function to check whether two given lines are parallel or not. assert parallel_lines([2,3,4], [2,3,8]) == True assert parallel_lines([2,3,4], [4,-3,8]) == False assert parallel_lines([3,3],[5,5]) == True def parallel_lines(line1, line2): return line1[0]/line1[1] == line2[0]/line2[1]
mbpp_data_526
Write a python function to capitalize first and last letters of each word of a given string. assert capitalize_first_last_letters("python") == "PythoN" assert capitalize_first_last_letters("bigdata") == "BigdatA" assert capitalize_first_last_letters("Hadoop") == "HadooP" def capitalize_first_last_letters(str1): s...
mbpp_data_527
Write a function to find all pairs in an integer array whose sum is equal to a given number. assert get_pairs_count([1, 5, 7, -1, 5], 5, 6) == 3 assert get_pairs_count([1, 5, 7, -1], 4, 6) == 2 assert get_pairs_count([1, 1, 1, 1], 4, 2) == 6 def get_pairs_count(arr, n, sum): count = 0 for i in range(0, n): ...
mbpp_data_528
Write a function to find the list of lists with minimum length. assert min_length([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(1, [0]) assert min_length([[1], [5, 7], [10, 12, 14,15]])==(1, [1]) assert min_length([[5], [15,20,25]])==(1, [5]) def min_length(list1): min_length = min(len(x) for x in list1 ) ...
mbpp_data_529
Write a function to find the nth jacobsthal-lucas number. assert jacobsthal_lucas(5) == 31 assert jacobsthal_lucas(2) == 5 assert jacobsthal_lucas(4) == 17 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_data_530
Write a function to find the ration of negative numbers in an array of integers. assert negative_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8])==0.31 assert negative_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==0.31 assert negative_count([2, 4, -6, -9, 11, -12, 14, -5, 17])==0.44 from array import array def...
mbpp_data_531
Write a function to find minimum number of coins that make a given value. assert min_coins([9, 6, 5, 1] ,4,11)==2 assert min_coins([4,5,6,7,8,9],6,9)==1 assert min_coins([1, 2, 3],3,4)==2 import sys def min_coins(coins, m, V): if (V == 0): return 0 res = sys.maxsize for i in range(0, m): ...
mbpp_data_532
Write a function to check if the two given strings are permutations of each other. assert check_permutation("abc", "cba") == True assert check_permutation("test", "ttew") == False assert check_permutation("xxyz", "yxzx") == True def check_permutation(str1, str2): n1=len(str1) n2=len(str2) if(n1!=n2): retu...
mbpp_data_533
Write a function to remove particular data type elements from the given tuple. assert remove_datatype((4, 5, 4, 7.7, 1.2), int) == [7.7, 1.2] assert remove_datatype((7, 8, 9, "SR"), str) == [7, 8, 9] assert remove_datatype((7, 1.1, 2, 2.2), float) == [7, 2] def remove_datatype(test_tuple, data_type): res = [] for...
mbpp_data_534
Write a function to search a literals string in a string and also find the location within the original string where the pattern occurs. assert search_literal('python','python programming language')==(0,6) assert search_literal('programming','python programming language')==(7,18) assert search_literal('language','pytho...
mbpp_data_535
Write a function to find the top or bottom surface area of a cylinder. assert topbottom_surfacearea(10)==314.15000000000003 assert topbottom_surfacearea(5)==78.53750000000001 assert topbottom_surfacearea(4)==50.264 def topbottom_surfacearea(r): toporbottomarea=3.1415*r*r return toporbottomarea
mbpp_data_536
Write a function to select the nth items of a list. assert nth_items([1, 2, 3, 4, 5, 6, 7, 8, 9],2)==[1, 3, 5, 7, 9] assert nth_items([10,15,19,17,16,18],3)==[10,17] assert nth_items([14,16,19,15,17],4)==[14,17] def nth_items(list,n): return list[::n]