id stringlengths 11 13 | content stringlengths 165 5.63k |
|---|---|
mbpp_data_901 | Write a function to find the smallest multiple of the first n numbers.
assert smallest_multiple(13)==360360
assert smallest_multiple(2)==2
assert smallest_multiple(1)==1
def smallest_multiple(n):
if (n<=2):
return n
i = n * 2
factors = [number for number in range(n, 1, -1) if number * 2 > n]
... |
mbpp_data_902 | Write a function to combine two dictionaries by adding values for common keys.
assert add_dict({'a': 100, 'b': 200, 'c':300},{'a': 300, 'b': 200, 'd':400})==({'b': 400, 'd': 400, 'a': 400, 'c': 300})
assert add_dict({'a': 500, 'b': 700, 'c':900},{'a': 500, 'b': 600, 'd':900})==({'b': 1300, 'd': 900, 'a': 1000, 'c': 90... |
mbpp_data_903 | Write a python function to count the total unset bits from 1 to n.
assert count_Unset_Bits(2) == 1
assert count_Unset_Bits(5) == 4
assert count_Unset_Bits(14) == 17
def count_Unset_Bits(n) :
cnt = 0;
for i in range(1,n + 1) :
temp = i;
while (temp) :
if (temp % 2 == 0) ... |
mbpp_data_904 | Write a function to return true if the given number is even else return false.
assert even_num(13.5)==False
assert even_num(0)==True
assert even_num(-9)==False
def even_num(x):
if x%2==0:
return True
else:
return False |
mbpp_data_905 | Write a python function to find the sum of squares of binomial co-efficients.
assert sum_of_square(4) == 70
assert sum_of_square(5) == 252
assert sum_of_square(2) == 6
def factorial(start,end):
res = 1
for i in range(start,end + 1):
res *= i
return res
def sum_of_square(n):
retur... |
mbpp_data_906 | Write a function to extract year, month and date from a url by using regex.
assert extract_date("https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-norman-tells-author/") == [('2016', '09', '02')]
assert extract_date("https://www.indiatoday.in/mov... |
mbpp_data_907 | Write a function to print the first n lucky numbers.
assert lucky_num(10)==[1, 3, 7, 9, 13, 15, 21, 25, 31, 33]
assert lucky_num(5)==[1, 3, 7, 9, 13]
assert lucky_num(8)==[1, 3, 7, 9, 13, 15, 21, 25]
def lucky_num(n):
List=range(-1,n*n+9,2)
i=2
while List[i:]:List=sorted(set(List)-set(List[List[i]::List[i]]));i+... |
mbpp_data_908 | Write a function to find the fixed point in the given array.
assert find_fixed_point([-10, -1, 0, 3, 10, 11, 30, 50, 100],9) == 3
assert find_fixed_point([1, 2, 3, 4, 5, 6, 7, 8],8) == -1
assert find_fixed_point([0, 2, 5, 8, 17],5) == 0
def find_fixed_point(arr, n):
for i in range(n):
if arr[i] is i:
return... |
mbpp_data_909 | Write a function to find the previous palindrome of a specified number.
assert previous_palindrome(99)==88
assert previous_palindrome(1221)==1111
assert previous_palindrome(120)==111
def previous_palindrome(num):
for x in range(num-1,0,-1):
if str(x) == str(x)[::-1]:
return x |
mbpp_data_910 | Write a function to validate a gregorian date.
assert check_date(11,11,2002)==True
assert check_date(13,11,2002)==False
assert check_date('11','11','2002')==True
import datetime
def check_date(m, d, y):
try:
m, d, y = map(int, (m, d, y))
datetime.date(y, m, d)
return True
except Va... |
mbpp_data_911 | Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm.
assert maximum_product( [12, 74, 9, 50, 61, 41])==225700
assert maximum_product([25, 35, 22, 85, 14, 65, 75, 25, 58])==414375
assert maximum_product([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1])==2520
def maxim... |
mbpp_data_912 | Write a function to find ln, m lobb number.
assert int(lobb_num(5, 3)) == 35
assert int(lobb_num(3, 2)) == 5
assert int(lobb_num(4, 2)) == 20
def binomial_coeff(n, k):
C = [[0 for j in range(k + 1)]
for i in range(n + 1)]
for i in range(0, n + 1):
for j in range(0, min(i, k) + 1):
if (j == 0 or j ==... |
mbpp_data_913 | Write a function to check for a number at the end of a string.
assert end_num('abcdef')==False
assert end_num('abcdef7')==True
assert end_num('abc')==False
import re
def end_num(string):
text = re.compile(r".*[0-9]$")
if text.match(string):
return True
else:
return False |
mbpp_data_914 | Write a python function to check whether the given string is made up of two alternating characters or not.
assert is_Two_Alter("abab") == True
assert is_Two_Alter("aaaa") == False
assert is_Two_Alter("xyz") == False
def is_Two_Alter(s):
for i in range (len( s) - 2) :
if (s[i] != s[i + 2]) :
... |
mbpp_data_915 | Write a function to rearrange positive and negative numbers in a given array using lambda function.
assert rearrange_numbs([-1, 2, -3, 5, 7, 8, 9, -10])==[2, 5, 7, 8, 9, -10, -3, -1]
assert rearrange_numbs([10,15,14,13,-18,12,-20])==[10, 12, 13, 14, 15, -20, -18]
assert rearrange_numbs([-20,20,-10,10,-30,30])==[10, 20,... |
mbpp_data_916 | Write a function to find if there is a triplet in the array whose sum is equal to a given value.
assert find_triplet_array([1, 4, 45, 6, 10, 8], 6, 22) == (4, 10, 8)
assert find_triplet_array([12, 3, 5, 2, 6, 9], 6, 24) == (12, 3, 9)
assert find_triplet_array([1, 2, 3, 4, 5], 5, 9) == (1, 3, 5)
def find_triplet_array(A... |
mbpp_data_917 | Write a function to find the sequences of one upper case letter followed by lower case letters.
assert text_uppercase_lowercase("AaBbGg")==('Found a match!')
assert text_uppercase_lowercase("aA")==('Not matched!')
assert text_uppercase_lowercase("PYTHON")==('Not matched!')
import re
def text_uppercase_lowercase(text):... |
mbpp_data_918 | Write a function to count coin change.
assert coin_change([1, 2, 3],3,4)==4
assert coin_change([4,5,6,7,8,9],6,9)==2
assert coin_change([4,5,6,7,8,9],6,4)==1
def coin_change(S, m, n):
table = [[0 for x in range(m)] for x in range(n+1)]
for i in range(m):
table[0][i] = 1
for i in range(1, n+1)... |
mbpp_data_919 | Write a python function to multiply all items in the list.
assert multiply_list([1,-2,3]) == -6
assert multiply_list([1,2,3,4]) == 24
assert multiply_list([3,1,2,3]) == 18
def multiply_list(items):
tot = 1
for x in items:
tot *= x
return tot |
mbpp_data_920 | Write a function to remove all tuples with all none values in the given tuple list.
assert remove_tuple([(None, 2), (None, None), (3, 4), (12, 3), (None, )] ) == '[(None, 2), (3, 4), (12, 3)]'
assert remove_tuple([(None, None), (None, None), (3, 6), (17, 3), (None,1 )] ) == '[(3, 6), (17, 3), (None, 1)]'
assert remove_... |
mbpp_data_921 | Write a function to perform chunking of tuples each of size n.
assert chunk_tuples((10, 4, 5, 6, 7, 6, 8, 3, 4), 3) == [(10, 4, 5), (6, 7, 6), (8, 3, 4)]
assert chunk_tuples((1, 2, 3, 4, 5, 6, 7, 8, 9), 2) == [(1, 2), (3, 4), (5, 6), (7, 8), (9,)]
assert chunk_tuples((11, 14, 16, 17, 19, 21, 22, 25), 4) == [(11, 14, 16... |
mbpp_data_922 | Write a function to find a pair with the highest product from a given array of integers.
assert max_product([1, 2, 3, 4, 7, 0, 8, 4])==(7, 8)
assert max_product([0, -1, -2, -4, 5, 0, -6])==(-4, -6)
assert max_product([1, 3, 5, 6, 8, 9])==(8,9)
def max_product(arr):
arr_len = len(arr)
if (arr_len < 2):
... |
mbpp_data_923 | Write a function to find the length of the shortest string that has both str1 and str2 as subsequences.
assert super_seq("AGGTAB", "GXTXAYB", 6, 7) == 9
assert super_seq("feek", "eke", 4, 3) == 5
assert super_seq("PARRT", "RTA", 5, 3) == 6
def super_seq(X, Y, m, n):
if (not m):
return n
if (not n):
return m
... |
mbpp_data_924 | Write a function to find maximum of two numbers.
assert max_of_two(10,20)==20
assert max_of_two(19,15)==19
assert max_of_two(-10,-20)==-10
def max_of_two( x, y ):
if x > y:
return x
return y |
mbpp_data_925 | Write a python function to calculate the product of all the numbers of a given tuple.
assert mutiple_tuple((4, 3, 2, 2, -1, 18)) == -864
assert mutiple_tuple((1,2,3)) == 6
assert mutiple_tuple((-2,-4,-6)) == -48
def mutiple_tuple(nums):
temp = list(nums)
product = 1
for x in temp:
product *= x
... |
mbpp_data_926 | Write a function to find n-th rencontres number.
assert rencontres_number(7, 2) == 924
assert rencontres_number(3, 0) == 2
assert rencontres_number(3, 1) == 3
def binomial_coeffi(n, k):
if (k == 0 or k == n):
return 1
return (binomial_coeffi(n - 1, k - 1)
+ binomial_coeffi(n - 1, k))
def rencontres_numbe... |
mbpp_data_927 | Write a function to calculate the height of the given binary tree.
assert (max_height(root)) == 3
assert (max_height(root1)) == 5
assert (max_height(root2)) == 4
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def max_height(node):
if node is None:
return... |
mbpp_data_928 | Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.
assert change_date_format('2026-01-02')=='02-01-2026'
assert change_date_format('2021-01-04')=='04-01-2021'
assert change_date_format('2030-06-06')=='06-06-2030'
import re
def change_date_format(dt):
return re.sub(r'(\d{4})-(\d{1,2}... |
mbpp_data_929 | Write a function to count repeated items of a tuple.
assert count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7),4)==3
assert count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7),2)==2
assert count_tuplex((2, 4, 7, 7, 7, 3, 4, 4, 7),7)==4
def count_tuplex(tuplex,value):
count = tuplex.count(value)
return count |
mbpp_data_930 | Write a function that matches a string that has an a followed by zero or more b's by using regex.
assert text_match("msb") == 'Not matched!'
assert text_match("a0c") == 'Found a match!'
assert text_match("abbc") == 'Found a match!'
import re
def text_match(text):
patterns = 'ab*?'
if re.search(patter... |
mbpp_data_931 | Write a function to calculate the sum of series 1³+2³+3³+….+n³.
assert sum_series(7)==784
assert sum_series(5)==225
assert sum_series(15)==14400
import math
def sum_series(number):
total = 0
total = math.pow((number * (number + 1)) /2, 2)
return total |
mbpp_data_932 | Write a function to remove duplicate words from a given list of strings.
assert remove_duplic_list(["Python", "Exercises", "Practice", "Solution", "Exercises"])==['Python', 'Exercises', 'Practice', 'Solution']
assert remove_duplic_list(["Python", "Exercises", "Practice", "Solution", "Exercises","Java"])==['Python', 'Ex... |
mbpp_data_933 | Write a function to convert camel case string to snake case string by using regex.
assert camel_to_snake('GoogleAssistant') == 'google_assistant'
assert camel_to_snake('ChromeCast') == 'chrome_cast'
assert camel_to_snake('QuadCore') == 'quad_core'
import re
def camel_to_snake(text):
str1 = re.sub('(.)([A-Z][a-z]+)'... |
mbpp_data_934 | Write a function to find the nth delannoy number.
assert dealnnoy_num(3, 4) == 129
assert dealnnoy_num(3, 3) == 63
assert dealnnoy_num(4, 5) == 681
def dealnnoy_num(n, m):
if (m == 0 or n == 0) :
return 1
return dealnnoy_num(m - 1, n) + dealnnoy_num(m - 1, n - 1) + dealnnoy_num(m, n - 1) |
mbpp_data_935 | Write a function to calculate the sum of series 1²+2²+3²+….+n².
assert series_sum(6)==91
assert series_sum(7)==140
assert series_sum(12)==650
def series_sum(number):
total = 0
total = (number * (number + 1) * (2 * number + 1)) / 6
return total |
mbpp_data_936 | Write a function to re-arrange the given tuples based on the given ordered list.
assert re_arrange_tuples([(4, 3), (1, 9), (2, 10), (3, 2)], [1, 4, 2, 3]) == [(1, 9), (4, 3), (2, 10), (3, 2)]
assert re_arrange_tuples([(5, 4), (2, 10), (3, 11), (4, 3)], [3, 4, 2, 3]) == [(3, 11), (4, 3), (2, 10), (3, 11)]
assert re_ar... |
mbpp_data_937 | Write a function to count the most common character in a given string.
assert max_char("hello world")==('l')
assert max_char("hello ")==('l')
assert max_char("python pr")==('p')
from collections import Counter
def max_char(str1):
temp = Counter(str1)
max_char = max(temp, key = temp.get)
return max_cha... |
mbpp_data_938 | Write a function to find three closest elements from three sorted arrays.
assert find_closet([1, 4, 10],[2, 15, 20],[10, 12],3,3,2) == (10, 15, 10)
assert find_closet([20, 24, 100],[2, 19, 22, 79, 800],[10, 12, 23, 24, 119],3,5,5) == (24, 22, 23)
assert find_closet([2, 5, 11],[3, 16, 21],[11, 13],3,3,2) == (11, 16, 11)... |
mbpp_data_939 | Write a function to sort a list of dictionaries using lambda function.
assert sorted_models([{'make':'Nokia', 'model':216, 'color':'Black'}, {'make':'Mi Max', 'model':2, 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color':'Blue'}])==[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7,... |
mbpp_data_940 | Write a function to sort the given array by using heap sort.
assert heap_sort([12, 2, 4, 5, 2, 3]) == [2, 2, 3, 4, 5, 12]
assert heap_sort([32, 14, 5, 6, 7, 19]) == [5, 6, 7, 14, 19, 32]
assert heap_sort([21, 15, 29, 78, 65]) == [15, 21, 29, 65, 78]
def heap_sort(arr):
heapify(arr)
end = len(arr) - 1
w... |
mbpp_data_941 | Write a function to count the elements in a list until an element is a tuple.
assert count_elim([10,20,30,(10,20),40])==3
assert count_elim([10,(20,30),(10,20),40])==1
assert count_elim([(10,(20,30,(10,20),40))])==0
def count_elim(num):
count_elim = 0
for n in num:
if isinstance(n, tuple):
break
... |
mbpp_data_942 | Write a function to check if any list element is present in the given list.
assert check_element((4, 5, 7, 9, 3), [6, 7, 10, 11]) == True
assert check_element((1, 2, 3, 4), [4, 6, 7, 8, 9]) == True
assert check_element((3, 2, 1, 4, 5), [9, 8, 7, 6]) == False
def check_element(test_tup, check_list):
res = False
... |
mbpp_data_943 | Write a function to combine two given sorted lists using heapq module.
assert combine_lists([1, 3, 5, 7, 9, 11],[0, 2, 4, 6, 8, 10])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
assert combine_lists([1, 3, 5, 6, 8, 9], [2, 5, 7, 11])==[1,2,3,5,5,6,7,8,9,11]
assert combine_lists([1,3,7],[2,4,6])==[1,2,3,4,6,7]
from heapq imp... |
mbpp_data_944 | Write a function to separate and print the numbers and their position of a given string.
assert num_position("there are 70 flats in this apartment")==10
assert num_position("every adult have 32 teeth")==17
assert num_position("isha has 79 chocolates in her bag")==9
import re
def num_position(text):
for m in re.findi... |
mbpp_data_945 | Write a function to convert the given tuples into set.
assert tuple_to_set(('x', 'y', 'z') ) == {'y', 'x', 'z'}
assert tuple_to_set(('a', 'b', 'c') ) == {'c', 'a', 'b'}
assert tuple_to_set(('z', 'd', 'e') ) == {'d', 'e', 'z'}
def tuple_to_set(t):
s = set(t)
return (s) |
mbpp_data_946 | Write a function to find the most common elements and their counts of a specified text.
assert most_common_elem('lkseropewdssafsdfafkpwe',3)==[('s', 4), ('e', 3), ('f', 3)]
assert most_common_elem('lkseropewdssafsdfafkpwe',2)==[('s', 4), ('e', 3)]
assert most_common_elem('lkseropewdssafsdfafkpwe',7)==[('s', 4), ('e', ... |
mbpp_data_947 | Write a python function to find the length of the shortest word.
assert len_log(["win","lose","great"]) == 3
assert len_log(["a","ab","abc"]) == 1
assert len_log(["12","12","1234"]) == 2
def len_log(list1):
min=len(list1[0])
for i in list1:
if len(i)<min:
min=len(i)
return min |
mbpp_data_948 | Write a function to get an item of a tuple.
assert get_item(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),3)==('e')
assert get_item(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),-4)==('u')
assert get_item(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),-3)==('r')
def get_item(tup1,index):
item = tup1[index]
... |
mbpp_data_949 | Write a function to sort the given tuple list basis the total digits in tuple.
assert sort_list([(3, 4, 6, 723), (1, 2), (12345,), (134, 234, 34)] ) == '[(1, 2), (12345,), (3, 4, 6, 723), (134, 234, 34)]'
assert sort_list([(3, 4, 8), (1, 2), (1234335,), (1345, 234, 334)] ) == '[(1, 2), (3, 4, 8), (1234335,), (1345, 234... |
mbpp_data_950 | Write a function to display sign of the chinese zodiac for given year.
assert chinese_zodiac(1997)==('Ox')
assert chinese_zodiac(1998)==('Tiger')
assert chinese_zodiac(1994)==('Dog')
def chinese_zodiac(year):
if (year - 2000) % 12 == 0:
sign = 'Dragon'
elif (year - 2000) % 12 == 1:
sign = 'Snake'
elif... |
mbpp_data_951 | Write a function to find the maximum of similar indices in two lists of tuples.
assert max_similar_indices([(2, 4), (6, 7), (5, 1)],[(5, 4), (8, 10), (8, 14)]) == [(5, 4), (8, 10), (8, 14)]
assert max_similar_indices([(3, 5), (7, 8), (6, 2)],[(6, 5), (9, 11), (9, 15)]) == [(6, 5), (9, 11), (9, 15)]
assert max_similar_i... |
mbpp_data_952 | Write a function to compute the value of ncr mod p.
assert nCr_mod_p(10, 2, 13) == 6
assert nCr_mod_p(11, 3, 14) == 11
assert nCr_mod_p(18, 14, 19) == 1
def nCr_mod_p(n, r, p):
if (r > n- r):
r = n - r
C = [0 for i in range(r + 1)]
C[0] = 1
for i in range(1, n + 1):
for j in range(min(i, r), 0, -1):... |
mbpp_data_953 | Write a python function to find the minimun number of subsets with distinct elements.
assert subset([1, 2, 3, 4],4) == 1
assert subset([5, 6, 9, 3, 4, 3, 4],7) == 2
assert subset([1, 2, 3 ],3) == 1
def subset(ar, n):
res = 0
ar.sort()
for i in range(0, n) :
count = 1
for i in range(n... |
mbpp_data_954 | Write a function that gives profit amount if the given amount has profit else return none.
assert profit_amount(1500,1200)==300
assert profit_amount(100,200)==None
assert profit_amount(2000,5000)==None
def profit_amount(actual_cost,sale_amount):
if(actual_cost > sale_amount):
amount = actual_cost - sale_amount
... |
mbpp_data_955 | Write a function to find out, if the given number is abundant.
assert is_abundant(12)==True
assert is_abundant(13)==False
assert is_abundant(9)==False
def is_abundant(n):
fctrsum = sum([fctr for fctr in range(1, n) if n % fctr == 0])
return fctrsum > n |
mbpp_data_956 | Write a function to split the given string at uppercase letters by using regex.
assert split_list("LearnToBuildAnythingWithGoogle") == ['Learn', 'To', 'Build', 'Anything', 'With', 'Google']
assert split_list("ApmlifyingTheBlack+DeveloperCommunity") == ['Apmlifying', 'The', 'Black+', 'Developer', 'Community']
assert spl... |
mbpp_data_957 | Write a python function to get the position of rightmost set bit.
assert get_First_Set_Bit_Pos(12) == 3
assert get_First_Set_Bit_Pos(18) == 2
assert get_First_Set_Bit_Pos(16) == 5
import math
def get_First_Set_Bit_Pos(n):
return math.log2(n&-n)+1 |
mbpp_data_958 | Write a function to convert an integer into a roman numeral.
assert int_to_roman(1)==("I")
assert int_to_roman(50)==("L")
assert int_to_roman(4)==("IV")
def int_to_roman( num):
val = [1000, 900, 500, 400,100, 90, 50, 40,10, 9, 5, 4,1]
syb = ["M", "CM", "D", "CD","C", "XC", "L", "XL","X", "IX", "V", "I... |
mbpp_data_959 | Write a python function to find the average of a list.
assert Average([15, 9, 55, 41, 35, 20, 62, 49]) == 35.75
assert Average([4, 5, 1, 2, 9, 7, 10, 8]) == 5.75
assert Average([1,2,3]) == 2
def Average(lst):
return sum(lst) / len(lst) |
mbpp_data_960 | Write a function to solve tiling problem.
assert get_noOfways(4)==3
assert get_noOfways(3)==2
assert get_noOfways(5)==5
def get_noOfways(n):
if (n == 0):
return 0;
if (n == 1):
return 1;
return get_noOfways(n - 1) + get_noOfways(n - 2); |
mbpp_data_961 | Write a function to convert a roman numeral to an integer.
assert roman_to_int('MMMCMLXXXVI')==3986
assert roman_to_int('MMMM')==4000
assert roman_to_int('C')==100
def roman_to_int(s):
rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
int_val = 0
for i in range(len(s... |
mbpp_data_962 | Write a python function to find the sum of all even natural numbers within the range l and r.
assert sum_Even(2,5) == 6
assert sum_Even(3,8) == 18
assert sum_Even(4,6) == 10
def sum_Natural(n):
sum = (n * (n + 1))
return int(sum)
def sum_Even(l,r):
return (sum_Natural(int(r / 2)) - sum_Natural(int((... |
mbpp_data_963 | Write a function to calculate the discriminant value.
assert discriminant_value(4,8,2)==("Two solutions",32)
assert discriminant_value(5,7,9)==("no real solution",-131)
assert discriminant_value(0,0,9)==("one solution",0)
def discriminant_value(x,y,z):
discriminant = (y**2) - (4*x*z)
if discriminant > 0:
... |
mbpp_data_964 | Write a python function to check whether the length of the word is even or not.
assert word_len("program") == False
assert word_len("solution") == True
assert word_len("data") == True
def word_len(s):
s = s.split(' ')
for word in s:
if len(word)%2==0:
return True
else... |
mbpp_data_965 | Write a function to convert camel case string to snake case string.
assert camel_to_snake('PythonProgram')==('python_program')
assert camel_to_snake('pythonLanguage')==('python_language')
assert camel_to_snake('ProgrammingLanguage')==('programming_language')
def camel_to_snake(text):
import re
str1 = ... |
mbpp_data_966 | Write a function to remove an empty tuple from a list of tuples.
assert remove_empty([(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')])==[('',), ('a', 'b'), ('a', 'b', 'c'), 'd']
assert remove_empty([(), (), ('',), ("python"), ("program")])==[('',), ("python"), ("program")]
assert remove_empty([(), (), ('',), ("j... |
mbpp_data_967 | Write a python function to accept the strings which contains all vowels.
assert check("SEEquoiaL") == 'accepted'
assert check('program') == "not accepted"
assert check('fine') == "not accepted"
def check(string):
if len(set(string).intersection("AEIOUaeiou"))>=5:
return ('accepted')
else:
return ("n... |
mbpp_data_968 | Write a python function to find maximum possible value for the given periodic function.
assert floor_Max(11,10,9) == 9
assert floor_Max(5,7,4) == 2
assert floor_Max(2,2,1) == 1
def floor_Max(A,B,N):
x = min(B - 1,N)
return (A*x) // B |
mbpp_data_969 | Write a function to join the tuples if they have similar initial elements.
assert join_tuples([(5, 6), (5, 7), (6, 8), (6, 10), (7, 13)] ) == [(5, 6, 7), (6, 8, 10), (7, 13)]
assert join_tuples([(6, 7), (6, 8), (7, 9), (7, 11), (8, 14)] ) == [(6, 7, 8), (7, 9, 11), (8, 14)]
assert join_tuples([(7, 8), (7, 9), (8, 10), ... |
mbpp_data_970 | Write a function to find minimum of two numbers.
assert min_of_two(10,20)==10
assert min_of_two(19,15)==15
assert min_of_two(-10,-20)==-20
def min_of_two( x, y ):
if x < y:
return x
return y |
mbpp_data_971 | Write a function to find the maximum number of segments of lengths a, b and c that can be formed from n.
assert maximum_segments(7, 5, 2, 5) == 2
assert maximum_segments(17, 2, 1, 3) == 17
assert maximum_segments(18, 16, 3, 6) == 6
def maximum_segments(n, a, b, c) :
dp = [-1] * (n + 10)
dp[0] = 0
for i in range... |
mbpp_data_972 | Write a function to concatenate the given two tuples to a nested tuple.
assert concatenate_nested((3, 4), (5, 6)) == (3, 4, 5, 6)
assert concatenate_nested((1, 2), (3, 4)) == (1, 2, 3, 4)
assert concatenate_nested((4, 5), (6, 8)) == (4, 5, 6, 8)
def concatenate_nested(test_tup1, test_tup2):
res = test_tup1 + test_tu... |
mbpp_data_973 | Write a python function to left rotate the string.
assert left_rotate("python",2) == "thonpy"
assert left_rotate("bigdata",3 ) == "databig"
assert left_rotate("hadoop",1 ) == "adooph"
def left_rotate(s,d):
tmp = s[d : ] + s[0 : d]
return tmp |
mbpp_data_974 | Write a function to find the minimum total path sum in the given triangle.
assert min_sum_path([[ 2 ], [3, 9 ], [1, 6, 7 ]]) == 6
assert min_sum_path([[ 2 ], [3, 7 ], [8, 5, 6 ]]) == 10
assert min_sum_path([[ 3 ], [6, 4 ], [5, 2, 7 ]]) == 9
def min_sum_path(A):
memo = [None] * len(A)
n = len(A) - 1
for i in ra... |
mbpp_data_11 | Write a python function to remove first and last occurrence of a given character from the string.
assert remove_Occ("hello","l") == "heo"
assert remove_Occ("abcda","a") == "bcd"
assert remove_Occ("PHP","P") == "H"
def remove_Occ(s,ch):
for i in range(len(s)):
if (s[i] == ch):
s = s[0 : i] ... |
mbpp_data_12 | Write a function to sort a given matrix in ascending order according to the sum of its rows.
assert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]]
assert sort_matrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])==[[-2, 4, -5], [1, -1, 1], [1, 2, 3]]
assert sort_matrix([[5,8,9],[6,4,3],[2,1,4]... |
mbpp_data_13 | Write a function to count the most common words in a dictionary.
assert count_common(['red','green','black','pink','black','white','black','eyes','white','black','orange','pink','pink','red','red','white','orange','white',"black",'pink','green','green','pink','green','pink','white','orange',"orange",'red']) == [('pink'... |
mbpp_data_14 | Write a python function to find the volume of a triangular prism.
assert find_Volume(10,8,6) == 240
assert find_Volume(3,2,2) == 6
assert find_Volume(1,2,1) == 1
def find_Volume(l,b,h) :
return ((l * b * h) / 2) |
mbpp_data_15 | Write a function to split a string at lowercase letters.
assert split_lowerstring("AbCd")==['bC','d']
assert split_lowerstring("Python")==['y', 't', 'h', 'o', 'n']
assert split_lowerstring("Programming")==['r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g']
import re
def split_lowerstring(text):
return (re.findall('[a... |
mbpp_data_16 | Write a function to find sequences of lowercase letters joined with an underscore.
assert text_lowercase_underscore("aab_cbbbc")==('Found a match!')
assert text_lowercase_underscore("aab_Abbbc")==('Not matched!')
assert text_lowercase_underscore("Aaab_abbbc")==('Not matched!')
import re
def text_lowercase_underscore(t... |
mbpp_data_17 | Write a function to find the perimeter of a square.
assert square_perimeter(10)==40
assert square_perimeter(5)==20
assert square_perimeter(4)==16
def square_perimeter(a):
perimeter=4*a
return perimeter |
mbpp_data_18 | Write a function to remove characters from the first string which are present in the second string.
assert remove_dirty_chars("probasscurve", "pros") == 'bacuve'
assert remove_dirty_chars("digitalindia", "talent") == 'digiidi'
assert remove_dirty_chars("exoticmiles", "toxic") == 'emles'
NO_OF_CHARS = 256
def str_to_l... |
mbpp_data_19 | Write a function to find whether a given array of integers contains any duplicate element.
assert test_duplicate(([1,2,3,4,5]))==False
assert test_duplicate(([1,2,3,4, 4]))==True
assert test_duplicate([1,1,2,2,3,3,4,4,5])==True
def test_duplicate(arraynums):
nums_set = set(arraynums)
return len(arraynums)... |
mbpp_data_20 | Write a function to check if the given number is woodball or not.
assert is_woodall(383) == True
assert is_woodall(254) == False
assert is_woodall(200) == False
def is_woodall(x):
if (x % 2 == 0):
return False
if (x == 1):
return True
x = x + 1
p = 0
while (x % 2 == 0):
x = x/2
p = p + 1
i... |
mbpp_data_21 | Write a function to find m number of multiples of n.
assert multiples_of_num(4,3)== [3,6,9,12]
assert multiples_of_num(2,5)== [5,10]
assert multiples_of_num(9,2)== [2,4,6,8,10,12,14,16,18]
def multiples_of_num(m,n):
multiples_of_num= list(range(n,(m+1)*n, n))
return list(multiples_of_num) |
mbpp_data_22 | Write a function to find the first duplicate element in a given array of integers.
assert find_first_duplicate(([1, 2, 3, 4, 4, 5]))==4
assert find_first_duplicate([1, 2, 3, 4])==-1
assert find_first_duplicate([1, 1, 2, 3, 3, 2, 2])==1
def find_first_duplicate(nums):
num_set = set()
no_duplicate = -1
f... |
mbpp_data_23 | Write a python function to find the maximum sum of elements of list in a list of lists.
assert maximum_Sum([[1,2,3],[4,5,6],[10,11,12],[7,8,9]]) == 33
assert maximum_Sum([[0,1,1],[1,1,2],[3,2,1]]) == 6
assert maximum_Sum([[0,1,3],[1,2,1],[9,8,2],[0,1,0],[6,4,8]]) == 19
def maximum_Sum(list1):
maxi = -100000
... |
mbpp_data_24 | Write a function to convert the given binary number to its decimal equivalent.
assert binary_to_decimal(100) == 4
assert binary_to_decimal(1011) == 11
assert binary_to_decimal(1101101) == 109
def binary_to_decimal(binary):
binary1 = binary
decimal, i, n = 0, 0, 0
while(binary != 0):
dec = bin... |
mbpp_data_25 | Write a python function to find the product of non-repeated elements in a given array.
assert find_Product([1,1,2,3],4) == 6
assert find_Product([1,2,3,1,1],5) == 6
assert find_Product([1,1,4,5,6],5) == 120
def find_Product(arr,n):
arr.sort()
prod = 1
for i in range(0,n,1):
if (arr[i - 1] != ... |
mbpp_data_26 | Write a function to check if the given tuple list has all k elements.
assert check_k_elements([(4, 4), (4, 4, 4), (4, 4), (4, 4, 4, 4), (4, )], 4) == True
assert check_k_elements([(7, 7, 7), (7, 7)], 7) == True
assert check_k_elements([(9, 9), (9, 9, 9, 9)], 7) == False
def check_k_elements(test_list, K):
res = True... |
mbpp_data_27 | Write a python function to remove all digits from a list of strings.
assert remove(['4words', '3letters', '4digits']) == ['words', 'letters', 'digits']
assert remove(['28Jan','12Jan','11Jan']) == ['Jan','Jan','Jan']
assert remove(['wonder1','wonder2','wonder3']) == ['wonder','wonder','wonder']
import re
def remove(l... |
mbpp_data_28 | Write a python function to find binomial co-efficient.
assert binomial_Coeff(5,2) == 10
assert binomial_Coeff(4,3) == 4
assert binomial_Coeff(3,2) == 3
def binomial_Coeff(n,k):
if k > n :
return 0
if k==0 or k ==n :
return 1
return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k) |
mbpp_data_29 | Write a python function to find the element occurring odd number of times.
assert get_Odd_Occurrence([1,2,3,1,2,3,1],7) == 1
assert get_Odd_Occurrence([1,2,3,2,3,1,3],7) == 3
assert get_Odd_Occurrence([2,3,5,4,5,2,4,3,5,2,4,4,2],13) == 5
def get_Odd_Occurrence(arr,arr_size):
for i in range(0,arr_size):
... |
mbpp_data_30 | Write a python function to count all the substrings starting and ending with same characters.
assert count_Substring_With_Equal_Ends("abc") == 3
assert count_Substring_With_Equal_Ends("abcda") == 6
assert count_Substring_With_Equal_Ends("ab") == 2
def check_Equality(s):
return (ord(s[0]) == ord(s[len(s) - 1]));
... |
mbpp_data_31 | Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm.
assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],3)==[5, 7, 1]
assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9... |
mbpp_data_32 | Write a python function to find the largest prime factor of a given number.
assert max_Prime_Factors(15) == 5
assert max_Prime_Factors(6) == 3
assert max_Prime_Factors(2) == 2
import math
def max_Prime_Factors (n):
maxPrime = -1
while n%2 == 0:
maxPrime = 2
n >>= 1
for i in ran... |
mbpp_data_33 | Write a python function to convert a decimal number to binary number.
assert decimal_To_Binary(10) == 1010
assert decimal_To_Binary(1) == 1
assert decimal_To_Binary(20) == 10100
def decimal_To_Binary(N):
B_Number = 0
cnt = 0
while (N != 0):
rem = N % 2
c = pow(10,cnt)
B_Num... |
mbpp_data_34 | Write a python function to find the missing number in a sorted array.
assert find_missing([1,2,3,5],4) == 4
assert find_missing([1,3,4,5],4) == 2
assert find_missing([1,2,3,5,6,7],5) == 4
def find_missing(ar,N):
l = 0
r = N - 1
while (l <= r):
mid = (l + r) / 2
mid= int (mid)
... |
mbpp_data_35 | Write a function to find the n-th rectangular number.
assert find_rect_num(4) == 20
assert find_rect_num(5) == 30
assert find_rect_num(6) == 42
def find_rect_num(n):
return n*(n + 1) |
mbpp_data_36 | Write a python function to find the nth digit in the proper fraction of two given numbers.
assert find_Nth_Digit(1,2,1) == 5
assert find_Nth_Digit(3,5,1) == 6
assert find_Nth_Digit(5,6,5) == 3
def find_Nth_Digit(p,q,N) :
while (N > 0) :
N -= 1;
p *= 10;
res = p // q;
p ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.