id stringlengths 11 13 | content stringlengths 165 5.63k |
|---|---|
mbpp_data_337 | Write a function that matches a word at the end of a string, with optional punctuation.
assert text_match_word("python.")==('Found a match!')
assert text_match_word("python.")==('Found a match!')
assert text_match_word(" lang .")==('Not matched!')
import re
def text_match_word(text):
patterns = '\w+\S*$'
... |
mbpp_data_338 | Write a python function to count the number of substrings with same first and last characters.
assert count_Substring_With_Equal_Ends('aba') == 4
assert count_Substring_With_Equal_Ends('abcab') == 7
assert count_Substring_With_Equal_Ends('abc') == 3
def check_Equality(s):
return (ord(s[0]) == ord(s[len(s) - 1]));... |
mbpp_data_339 | Write a python function to find the maximum occuring divisor in an interval.
assert find_Divisor(2,2) == 2
assert find_Divisor(2,5) == 2
assert find_Divisor(5,10) == 2
def find_Divisor(x,y):
if (x==y):
return y
return 2 |
mbpp_data_340 | Write a python function to find the sum of the three lowest positive numbers from a given list of numbers.
assert sum_three_smallest_nums([10,20,30,40,50,60,7]) == 37
assert sum_three_smallest_nums([1,2,3,4,5]) == 6
assert sum_three_smallest_nums([0,1,2,3,4,5]) == 6
def sum_three_smallest_nums(lst):
return sum(sorted... |
mbpp_data_341 | Write a function to convert the given set into ordered tuples.
assert set_to_tuple({1, 2, 3, 4, 5}) == (1, 2, 3, 4, 5)
assert set_to_tuple({6, 7, 8, 9, 10, 11}) == (6, 7, 8, 9, 10, 11)
assert set_to_tuple({12, 13, 14, 15, 16}) == (12, 13, 14, 15, 16)
def set_to_tuple(s):
t = tuple(sorted(s))
return (t) |
mbpp_data_342 | Write a function to find the smallest range that includes at-least one element from each of the given arrays.
assert find_minimum_range([[3, 6, 8, 10, 15], [1, 5, 12], [4, 8, 15, 16], [2, 6]]) == (4, 6)
assert find_minimum_range([[ 2, 3, 4, 8, 10, 15 ], [1, 5, 12], [7, 8, 15, 16], [3, 6]]) == (4, 7)
assert find_minimum... |
mbpp_data_343 | Write a function to calculate the number of digits and letters in a string.
assert dig_let("python")==(6,0)
assert dig_let("program")==(7,0)
assert dig_let("python3.0")==(6,2)
def dig_let(s):
d=l=0
for c in s:
if c.isdigit():
d=d+1
elif c.isalpha():
l=l+1
else:
pass
retur... |
mbpp_data_344 | Write a python function to find number of elements with odd factors in a given range.
assert count_Odd_Squares(5,100) == 8
assert count_Odd_Squares(8,65) == 6
assert count_Odd_Squares(2,5) == 1
def count_Odd_Squares(n,m):
return int(m**0.5) - int((n-1)**0.5) |
mbpp_data_345 | Write a function to find the difference between two consecutive numbers in a given list.
assert diff_consecutivenums([1, 1, 3, 4, 4, 5, 6, 7])==[0, 2, 1, 0, 1, 1, 1]
assert diff_consecutivenums([4, 5, 8, 9, 6, 10])==[1, 3, 1, -3, 4]
assert diff_consecutivenums([0, 1, 2, 3, 4, 4, 4, 4, 5, 7])==[1, 1, 1, 1, 0, 0, 0, 1, 2... |
mbpp_data_346 | Write a function to find entringer number e(n, k).
assert zigzag(4, 3) == 5
assert zigzag(4, 2) == 4
assert zigzag(3, 1) == 1
def zigzag(n, k):
if (n == 0 and k == 0):
return 1
if (k == 0):
return 0
return zigzag(n, k - 1) + zigzag(n - 1, n - k) |
mbpp_data_347 | Write a python function to count the number of squares in a rectangle.
assert count_Squares(4,3) == 20
assert count_Squares(1,2) == 2
assert count_Squares(2,2) == 5
def count_Squares(m,n):
if (n < m):
temp = m
m = n
n = temp
return n * (n + 1) * (3 * m - n + 1) // 6 |
mbpp_data_348 | Write a function to count sequences of given length having non-negative prefix sums that can be generated by given values.
assert find_ways(4) == 2
assert find_ways(6) == 5
assert find_ways(8) == 14
def bin_coff(n, r):
val = 1
if (r > (n - r)):
r = (n - r)
for i in range(0, r):
val *= (n - i)
val //... |
mbpp_data_349 | Write a python function to check whether the given string is a binary string or not.
assert check("01010101010") == "Yes"
assert check("name0") == "No"
assert check("101") == "Yes"
def check(string) :
p = set(string)
s = {'0', '1'}
if s == p or p == {'0'} or p == {'1'}:
return ("Yes")
e... |
mbpp_data_350 | Write a python function to minimize the length of the string by removing occurrence of only one character.
assert minimum_Length("mnm") == 1
assert minimum_Length("abcda") == 3
assert minimum_Length("abcb") == 2
def minimum_Length(s) :
maxOcc = 0
n = len(s)
arr = [0]*26
for i in range(n) :
... |
mbpp_data_351 | Write a python function to find the first element occurring k times in a given array.
assert first_Element([0,1,2,3,4,5],6,1) == 0
assert first_Element([1,2,1,3,4],5,2) == 1
assert first_Element([2,3,4,3,5,7,1,2,3,5],10,2) == 2
def first_Element(arr,n,k):
count_map = {};
for i in range(0, n):
if(a... |
mbpp_data_352 | Write a python function to check whether all the characters in a given string are unique.
assert unique_Characters('aba') == False
assert unique_Characters('abc') == True
assert unique_Characters('abab') == False
def unique_Characters(str):
for i in range(len(str)):
for j in range(i + 1,len(str)):
... |
mbpp_data_353 | Write a function to remove a specified column from a given nested list.
assert remove_column([[1, 2, 3], [2, 4, 5], [1, 1, 1]],0)==[[2, 3], [4, 5], [1, 1]]
assert remove_column([[1, 2, 3], [-2, 4, -5], [1, -1, 1]],2)==[[1, 2], [-2, 4], [1, -1]]
assert remove_column([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]... |
mbpp_data_354 | Write a function to find t-nth term of arithemetic progression.
assert tn_ap(1,5,2)==9
assert tn_ap(2,6,4)==22
assert tn_ap(1,4,5)==16
def tn_ap(a,n,d):
tn = a + (n - 1) * d
return tn |
mbpp_data_355 | Write a python function to count the number of rectangles in a circle of radius r.
assert count_Rectangles(2) == 8
assert count_Rectangles(1) == 1
assert count_Rectangles(0) == 0
def count_Rectangles(radius):
rectangles = 0
diameter = 2 * radius
diameterSquare = diameter * diameter
for a in ran... |
mbpp_data_356 | Write a function to find the third angle of a triangle using two angles.
assert find_angle(47,89)==44
assert find_angle(45,95)==40
assert find_angle(50,40)==90
def find_angle(a,b):
c = 180 - (a + b)
return c
|
mbpp_data_357 | Write a function to find the maximum element of all the given tuple records.
assert find_max([(2, 4), (6, 7), (5, 1), (6, 10), (8, 7)]) == 10
assert find_max([(3, 5), (7, 8), (6, 2), (7, 11), (9, 8)]) == 11
assert find_max([(4, 6), (8, 9), (7, 3), (8, 12), (10, 9)]) == 12
def find_max(test_list):
res = max(int(j) fo... |
mbpp_data_358 | Write a function to find modulo division of two lists using map and lambda function.
assert moddiv_list([4,5,6],[1, 2, 3])==[0, 1, 0]
assert moddiv_list([3,2],[1,4])==[0, 2]
assert moddiv_list([90,120],[50,70])==[40, 50]
def moddiv_list(nums1,nums2):
result = map(lambda x, y: x % y, nums1, nums2)
return list(resu... |
mbpp_data_359 | Write a python function to check whether one root of the quadratic equation is twice of the other or not.
assert Check_Solution(1,3,2) == "Yes"
assert Check_Solution(1,2,3) == "No"
assert Check_Solution(1,-5,6) == "No"
def Check_Solution(a,b,c):
if (2*b*b == 9*a*c):
return ("Yes");
else:
... |
mbpp_data_360 | Write a function to find the n’th carol number.
assert get_carol(2) == 7
assert get_carol(4) == 223
assert get_carol(5) == 959
def get_carol(n):
result = (2**n) - 1
return result * result - 2 |
mbpp_data_361 | Write a function to remove empty lists from a given list of lists.
assert remove_empty([[], [], [], 'Red', 'Green', [1,2], 'Blue', [], []])==['Red', 'Green', [1, 2], 'Blue']
assert remove_empty([[], [], [],[],[], 'Green', [1,2], 'Blue', [], []])==[ 'Green', [1, 2], 'Blue']
assert remove_empty([[], [], [], 'Python',[],[... |
mbpp_data_362 | Write a python function to find the item with maximum occurrences in a given list.
assert max_occurrences([1,2,3,1,2,3,12,4,2]) == 2
assert max_occurrences([1,2,6,7,0,1,0,1,0]) == 1,0
assert max_occurrences([1,2,3,1,2,4,1]) == 1
def max_occurrences(nums):
max_val = 0
result = nums[0]
for i in nums:
... |
mbpp_data_363 | Write a function to add the k elements to each element in the tuple.
assert add_K_element([(1, 3, 4), (2, 4, 6), (3, 8, 1)], 4) == [(5, 7, 8), (6, 8, 10), (7, 12, 5)]
assert add_K_element([(1, 2, 3), (4, 5, 6), (7, 8, 9)], 8) == [(9, 10, 11), (12, 13, 14), (15, 16, 17)]
assert add_K_element([(11, 12, 13), (14, 15, 16),... |
mbpp_data_364 | Write a function to find the number of flips required to make the given binary string a sequence of alternate characters.
assert min_flip_to_make_string_alternate("0001010111") == 2
assert min_flip_to_make_string_alternate("001") == 1
assert min_flip_to_make_string_alternate("010111011") == 2
def make_flip(ch):
ret... |
mbpp_data_365 | Write a python function to count the number of digits of a given number.
assert count_Digit(12345) == 5
assert count_Digit(11223305) == 8
assert count_Digit(4123459) == 7
def count_Digit(n):
count = 0
while n != 0:
n //= 10
count += 1
return count |
mbpp_data_366 | Write a python function to find the largest product of the pair of adjacent elements from a given list of integers.
assert adjacent_num_product([1,2,3,4,5,6]) == 30
assert adjacent_num_product([1,2,3,4,5]) == 20
assert adjacent_num_product([2,3]) == 6
def adjacent_num_product(list_nums):
return max(a*b for a, b in... |
mbpp_data_367 | Write a function to check if a binary tree is balanced or not.
assert is_tree_balanced(root) == False
assert is_tree_balanced(root1) == True
assert is_tree_balanced(root2) == False
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def get_height(root):
if root ... |
mbpp_data_368 | Write a function to repeat the given tuple n times.
assert repeat_tuples((1, 3), 4) == ((1, 3), (1, 3), (1, 3), (1, 3))
assert repeat_tuples((1, 2), 3) == ((1, 2), (1, 2), (1, 2))
assert repeat_tuples((3, 4), 5) == ((3, 4), (3, 4), (3, 4), (3, 4), (3, 4))
def repeat_tuples(test_tup, N):
res = ((test_tup, ) * N)
r... |
mbpp_data_369 | Write a function to find the lateral surface area of cuboid
assert lateralsurface_cuboid(8,5,6)==156
assert lateralsurface_cuboid(7,9,10)==320
assert lateralsurface_cuboid(10,20,30)==1800
def lateralsurface_cuboid(l,w,h):
LSA = 2*h*(l+w)
return LSA |
mbpp_data_370 | Write a function to sort a tuple by its float element.
assert float_sort([('item1', '12.20'), ('item2', '15.10'), ('item3', '24.5')])==[('item3', '24.5'), ('item2', '15.10'), ('item1', '12.20')]
assert float_sort([('item1', '15'), ('item2', '10'), ('item3', '20')])==[('item3', '20'), ('item1', '15'), ('item2', '10')] ... |
mbpp_data_371 | Write a function to find the smallest missing element in a sorted array.
assert smallest_missing([0, 1, 2, 3, 4, 5, 6], 0, 6) == 7
assert smallest_missing([0, 1, 2, 6, 9, 11, 15], 0, 6) == 3
assert smallest_missing([1, 2, 3, 4, 6, 9, 11, 15], 0, 7) == 0
def smallest_missing(A, left_element, right_element):
if left... |
mbpp_data_372 | Write a function to sort a given list of elements in ascending order using heap queue algorithm.
assert heap_assending([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1])==[1, 2, 3, 4, 7, 8, 9, 9, 10, 14, 18]
assert heap_assending([25, 35, 22, 85, 14, 65, 75, 25, 58])==[14, 22, 25, 25, 35, 58, 65, 75, 85]
assert heap_assending([1, 3... |
mbpp_data_373 | Write a function to find the volume of a cuboid.
assert volume_cuboid(1,2,3)==6
assert volume_cuboid(5,7,9)==315
assert volume_cuboid(10,15,21)==3150
def volume_cuboid(l,w,h):
volume=l*w*h
return volume |
mbpp_data_374 | Write a function to print all permutations of a given string including duplicates.
assert permute_string('ab')==['ab', 'ba']
assert permute_string('abc')==['abc', 'bac', 'bca', 'acb', 'cab', 'cba']
assert permute_string('abcd')==['abcd', 'bacd', 'bcad', 'bcda', 'acbd', 'cabd', 'cbad', 'cbda', 'acdb', 'cadb', 'cdab', 'c... |
mbpp_data_375 | Write a function to round the given number to the nearest multiple of a specific number.
assert round_num(4722,10)==4720
assert round_num(1111,5)==1110
assert round_num(219,2)==218
def round_num(n,m):
a = (n //m) * m
b = a + m
return (b if n - a > b - n else a) |
mbpp_data_376 | Write a function to remove tuple elements that occur more than once and replace the duplicates with some custom value.
assert remove_replica((1, 1, 4, 4, 4, 5, 5, 6, 7, 7)) == (1, 'MSP', 4, 'MSP', 'MSP', 5, 'MSP', 6, 7, 'MSP')
assert remove_replica((2, 3, 4, 4, 5, 6, 6, 7, 8, 9, 9)) == (2, 3, 4, 'MSP', 5, 6, 'MSP', 7, ... |
mbpp_data_377 | Write a python function to remove all occurrences of a character in a given string.
assert remove_Char("aba",'a') == "b"
assert remove_Char("toggle",'g') == "tole"
assert remove_Char("aabbc",'b') == "aac"
def remove_Char(s,c) :
counts = s.count(c)
s = list(s)
while counts :
s.remove(c)
... |
mbpp_data_378 | Write a python function to shift last element to first position in the given list.
assert move_first([1,2,3,4]) == [4,1,2,3]
assert move_first([0,1,2,3]) == [3,0,1,2]
assert move_first([9,8,7,1]) == [1,9,8,7]
def move_first(test_list):
test_list = test_list[-1:] + test_list[:-1]
return test_list |
mbpp_data_379 | Write a function to find the surface area of a cuboid.
assert surfacearea_cuboid(1,2,3)==22
assert surfacearea_cuboid(5,7,9)==286
assert surfacearea_cuboid(10,15,21)==1350
def surfacearea_cuboid(l,w,h):
SA = 2*(l*w + l * h + w * h)
return SA |
mbpp_data_380 | Write a function to generate a two-dimensional array.
assert multi_list(3,4)==[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6]]
assert multi_list(5,7)==[[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6], [0, 2, 4, 6, 8, 10, 12], [0, 3, 6, 9, 12, 15, 18], [0, 4, 8, 12, 16, 20, 24]]
assert multi_list(10,15)==[[0, 0, 0, 0, 0, 0, 0, ... |
mbpp_data_381 | Write a function to sort a list of lists by a given index of the inner list.
assert index_on_inner_list([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,0)==[('Beau Turnbull', 94, 98), ('Brady Kent', 97, 96), ('Greyson Fulton', 98, 99), ('Wyatt Knott', 91, 94)]
a... |
mbpp_data_382 | Write a function to find the number of rotations in a circularly sorted array.
assert find_rotation_count([8, 9, 10, 1, 2, 3, 4, 5, 6, 7]) == 3
assert find_rotation_count([8, 9, 10,2, 5, 6]) == 3
assert find_rotation_count([2, 5, 6, 8, 9, 10]) == 0
def find_rotation_count(A):
(left, right) = (0, len(A) - 1)
w... |
mbpp_data_383 | Write a python function to toggle all odd bits of a given number.
assert even_bit_toggle_number(10) == 15
assert even_bit_toggle_number(20) == 1
assert even_bit_toggle_number(30) == 11
def even_bit_toggle_number(n) :
res = 0; count = 0; temp = n
while(temp > 0 ) :
if (count % 2 == 0) :
... |
mbpp_data_384 | Write a python function to find the frequency of the smallest value in a given array.
assert frequency_Of_Smallest(5,[1,2,3,4,3]) == 1
assert frequency_Of_Smallest(7,[3,1,2,5,6,2,3]) == 1
assert frequency_Of_Smallest(7,[3,3,6,3,7,4,9]) == 3
def frequency_Of_Smallest(n,arr):
mn = arr[0]
freq = 1
for i i... |
mbpp_data_385 | Write a function to find the n'th perrin number using recursion.
assert get_perrin(9) == 12
assert get_perrin(4) == 2
assert get_perrin(6) == 5
def get_perrin(n):
if (n == 0):
return 3
if (n == 1):
return 0
if (n == 2):
return 2
return get_perrin(n - 2) + get_perrin(n - 3) |
mbpp_data_386 | Write a function to find out the minimum no of swaps required for bracket balancing in the given string.
assert swap_count("[]][][") == 2
assert swap_count("[[][]]") == 0
assert swap_count("[[][]]][") == 1
def swap_count(s):
chars = s
count_left = 0
count_right = 0
swap = 0
imbalance = 0;
for i in range(le... |
mbpp_data_387 | Write a python function to check whether the hexadecimal number is even or odd.
assert even_or_odd("AB3454D") =="Odd"
assert even_or_odd("ABC") == "Even"
assert even_or_odd("AAD") == "Odd"
def even_or_odd(N):
l = len(N)
if (N[l-1] =='0'or N[l-1] =='2'or
N[l-1] =='4'or N[l-1] =='6'or
N[l-... |
mbpp_data_388 | Write a python function to find the highest power of 2 that is less than or equal to n.
assert highest_Power_of_2(10) == 8
assert highest_Power_of_2(19) == 16
assert highest_Power_of_2(32) == 32
def highest_Power_of_2(n):
res = 0;
for i in range(n, 0, -1):
if ((i & (i - 1)) == 0):
re... |
mbpp_data_389 | Write a function to find the n'th lucas number.
assert find_lucas(9) == 76
assert find_lucas(4) == 7
assert find_lucas(3) == 4
def find_lucas(n):
if (n == 0):
return 2
if (n == 1):
return 1
return find_lucas(n - 1) + find_lucas(n - 2) |
mbpp_data_390 | Write a function to insert a given string at the beginning of all items in a list.
assert add_string([1,2,3,4],'temp{0}')==['temp1', 'temp2', 'temp3', 'temp4']
assert add_string(['a','b','c','d'], 'python{0}')==[ 'pythona', 'pythonb', 'pythonc', 'pythond']
assert add_string([5,6,7,8],'string{0}')==['string5', 'string6'... |
mbpp_data_391 | Write a function to convert more than one list to nested dictionary.
assert convert_list_dictionary(["S001", "S002", "S003", "S004"],["Adina Park", "Leyton Marsh", "Duncan Boyle", "Saim Richards"] ,[85, 98, 89, 92])==[{'S001': {'Adina Park': 85}}, {'S002': {'Leyton Marsh': 98}}, {'S003': {'Duncan Boyle': 89}}, {'S004':... |
mbpp_data_392 | Write a function to find the maximum sum possible by using the given equation f(n) = max( (f(n/2) + f(n/3) + f(n/4) + f(n/5)), n).
assert get_max_sum(60) == 106
assert get_max_sum(10) == 12
assert get_max_sum(2) == 2
def get_max_sum (n):
res = list()
res.append(0)
res.append(1)
i = 2
while i<n + 1:
res.app... |
mbpp_data_393 | Write a function to find the list with maximum length using lambda function.
assert max_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])
assert max_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(5,[1,2,3,4,5])
assert max_length_list([[3,4,5],[6,7,8,9],[10,11,12]])==(4,[6,7,8,9])
de... |
mbpp_data_394 | Write a function to check if given tuple is distinct or not.
assert check_distinct((1, 4, 5, 6, 1, 4)) == False
assert check_distinct((1, 4, 5, 6)) == True
assert check_distinct((2, 3, 4, 5, 6)) == True
def check_distinct(test_tup):
res = True
temp = set()
for ele in test_tup:
if ele in temp:
res =... |
mbpp_data_395 | Write a python function to find the first non-repeated character in a given string.
assert first_non_repeating_character("abcabc") == None
assert first_non_repeating_character("abc") == "a"
assert first_non_repeating_character("ababc") == "c"
def first_non_repeating_character(str1):
char_order = []
ctr = {}
fo... |
mbpp_data_396 | Write a function to check whether the given string starts and ends with the same character or not using regex.
assert check_char("abba") == "Valid"
assert check_char("a") == "Valid"
assert check_char("abcd") == "Invalid"
import re
regex = r'^[a-z]$|^([a-z]).*\1$'
def check_char(string):
if(re.search(regex, strin... |
mbpp_data_397 | Write a function to find the median of three specific numbers.
assert median_numbers(25,55,65)==55.0
assert median_numbers(20,10,30)==20.0
assert median_numbers(15,45,75)==45.0
def median_numbers(a,b,c):
if a > b:
if a < c:
median = a
elif b > c:
median = b
else:
median = c
... |
mbpp_data_398 | Write a function to compute the sum of digits of each number of a given list.
assert sum_of_digits([10,2,56])==14
assert sum_of_digits([[10,20,4,5,'b',70,'a']])==19
assert sum_of_digits([10,20,-4,5,-70])==19
def sum_of_digits(nums):
return sum(int(el) for n in nums for el in str(n) if el.isdigit()) |
mbpp_data_399 | Write a function to perform the mathematical bitwise xor operation across the given tuples.
assert bitwise_xor((10, 4, 6, 9), (5, 2, 3, 3)) == (15, 6, 5, 10)
assert bitwise_xor((11, 5, 7, 10), (6, 3, 4, 4)) == (13, 6, 3, 14)
assert bitwise_xor((12, 6, 8, 11), (7, 4, 5, 6)) == (11, 2, 13, 13)
def bitwise_xor(test_tup1, ... |
mbpp_data_400 | Write a function to extract the frequency of unique tuples in the given list order irrespective.
assert extract_freq([(3, 4), (1, 2), (4, 3), (5, 6)] ) == 3
assert extract_freq([(4, 15), (2, 3), (5, 4), (6, 7)] ) == 4
assert extract_freq([(5, 16), (2, 3), (6, 5), (6, 9)] ) == 4
def extract_freq(test_list):
res = len... |
mbpp_data_401 | Write a function to perform index wise addition of tuple elements in the given two nested tuples.
assert add_nested_tuples(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((7, 10), (7, 14), (3, 10), (8, 13))
assert add_nested_tuples(((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (... |
mbpp_data_402 | Write a function to compute the value of ncr%p.
assert ncr_modp(10,2,13)==6
assert ncr_modp(15,12,43)==25
assert ncr_modp(17,9,18)==10
def ncr_modp(n, r, p):
C = [0 for i in range(r+1)]
C[0] = 1
for i in range(1, n+1):
for j in range(min(i, r), 0, -1):
C[j] = (C[j] + C[j-1]) %... |
mbpp_data_403 | Write a function to check if a url is valid or not using regex.
assert is_valid_URL("https://www.google.com") == True
assert is_valid_URL("https:/www.gmail.com") == False
assert is_valid_URL("https:// www.redit.com") == False
import re
def is_valid_URL(str):
regex = ("((http|https)://)(www.)?" +
"[a-zA-Z0-9@:%._... |
mbpp_data_404 | Write a python function to find the minimum of two numbers.
assert minimum(1,2) == 1
assert minimum(-5,-4) == -5
assert minimum(0,0) == 0
def minimum(a,b):
if a <= b:
return a
else:
return b |
mbpp_data_405 | Write a function to check whether an element exists within a tuple.
assert check_tuplex(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),'r')==True
assert check_tuplex(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),'5')==False
assert check_tuplex(("w", 3, "r", "e", "s", "o", "u", "r", "c","e"),3)==True
def check_tupl... |
mbpp_data_406 | Write a python function to find the parity of a given number.
assert find_Parity(12) == "Even Parity"
assert find_Parity(7) == "Odd Parity"
assert find_Parity(10) == "Even Parity"
def find_Parity(x):
y = x ^ (x >> 1);
y = y ^ (y >> 2);
y = y ^ (y >> 4);
y = y ^ (y >> 8);
y = y ^ (y >> 16);... |
mbpp_data_407 | Write a function to create the next bigger number by rearranging the digits of a given number.
assert rearrange_bigger(12)==21
assert rearrange_bigger(10)==False
assert rearrange_bigger(102)==120
def rearrange_bigger(n):
nums = list(str(n))
for i in range(len(nums)-2,-1,-1):
if nums[i] < nums[i+1]:
... |
mbpp_data_408 | Write a function to find k number of pairs which consist of one element from the first array and one element from the second array.
assert k_smallest_pairs([1,3,7],[2,4,6],2)==[[1, 2], [1, 4]]
assert k_smallest_pairs([1,3,7],[2,4,6],1)==[[1, 2]]
assert k_smallest_pairs([1,3,7],[2,4,6],7)==[[1, 2], [1, 4], [3, 2], [1, 6... |
mbpp_data_409 | Write a function to find the minimum product from the pairs of tuples within a given list.
assert min_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==8
assert min_product_tuple([(10,20), (15,2), (5,10)] )==30
assert min_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==100
def min_product_tuple(list1):
result... |
mbpp_data_410 | Write a function to find the minimum value in a given heterogeneous list.
assert min_val(['Python', 3, 2, 4, 5, 'version'])==2
assert min_val(['Python', 15, 20, 25])==15
assert min_val(['Python', 30, 20, 40, 50, 'version'])==20
def min_val(listval):
min_val = min(i for i in listval if isinstance(i, int))
re... |
mbpp_data_411 | Write a function to convert the given snake case string to camel case string by using regex.
assert snake_to_camel('android_tv') == 'AndroidTv'
assert snake_to_camel('google_pixel') == 'GooglePixel'
assert snake_to_camel('apple_watch') == 'AppleWatch'
import re
def snake_to_camel(word):
return ''.join(x.capitalize(... |
mbpp_data_412 | Write a python function to remove odd numbers from a given list.
assert remove_odd([1,2,3]) == [2]
assert remove_odd([2,4,6]) == [2,4,6]
assert remove_odd([10,20,3]) == [10,20]
def remove_odd(l):
for i in l:
if i % 2 != 0:
l.remove(i)
return l |
mbpp_data_413 | Write a function to extract the nth element from a given list of tuples.
assert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,0)==['Greyson Fulton', 'Brady Kent', 'Wyatt Knott', 'Beau Turnbull']
assert extract_nth_element([('Greyson Fulton'... |
mbpp_data_414 | Write a python function to check whether the value exists in a sequence or not.
assert overlapping([1,2,3,4,5],[6,7,8,9]) == False
assert overlapping([1,2,3],[4,5,6]) == False
assert overlapping([1,4,5],[1,4,5]) == True
def overlapping(list1,list2):
c=0
d=0
for i in list1:
c+=1
for i in ... |
mbpp_data_415 | Write a python function to find a pair with 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,2,3]) == (2,3)
def max_Product(arr):
arr_len = len(arr)
if (arr_len < 2):
return ("No ... |
mbpp_data_416 | Write a function to find the maximum sum we can make by dividing number in three parts recursively and summing them up together for the given number.
assert breakSum(12) == 13
assert breakSum(24) == 27
assert breakSum(23) == 23
MAX = 1000000
def breakSum(n):
dp = [0]*(n+1)
dp[0] = 0
dp[1] = 1
for i in range(... |
mbpp_data_417 | Write a function to find common first element in given list of tuple.
assert group_tuples([('x', 'y'), ('x', 'z'), ('w', 't')]) == [('x', 'y', 'z'), ('w', 't')]
assert group_tuples([('a', 'b'), ('a', 'c'), ('d', 'e')]) == [('a', 'b', 'c'), ('d', 'e')]
assert group_tuples([('f', 'g'), ('f', 'g'), ('h', 'i')]) == [('f', ... |
mbpp_data_418 | Write a python function to find the sublist having maximum length.
assert Find_Max([['A'],['A','B'],['A','B','C']]) == ['A','B','C']
assert Find_Max([[1],[1,2],[1,2,3]]) == [1,2,3]
assert Find_Max([[1,1],[1,2,3],[1,5,6,1]]) == [1,5,6,1]
def Find_Max(lst):
maxList = max((x) for x in lst)
return maxList |
mbpp_data_419 | Write a function to round every number of a given list of numbers and print the total sum multiplied by the length of the list.
assert round_and_sum([22.4, 4.0, -16.22, -9.10, 11.00, -12.22, 14.20, -5.20, 17.50])==243
assert round_and_sum([5,2,9,24.3,29])==345
assert round_and_sum([25.0,56.7,89.2])==513
def round_and_s... |
mbpp_data_420 | Write a python function to find the cube sum of first n even natural numbers.
assert cube_Sum(2) == 72
assert cube_Sum(3) == 288
assert cube_Sum(4) == 800
def cube_Sum(n):
sum = 0
for i in range(1,n + 1):
sum += (2*i)*(2*i)*(2*i)
return sum |
mbpp_data_421 | Write a function to concatenate each element of tuple by the delimiter.
assert concatenate_tuple(("ID", "is", 4, "UTS") ) == 'ID-is-4-UTS'
assert concatenate_tuple(("QWE", "is", 4, "RTY") ) == 'QWE-is-4-RTY'
assert concatenate_tuple(("ZEN", "is", 4, "OP") ) == 'ZEN-is-4-OP'
def concatenate_tuple(test_tup):
delim =... |
mbpp_data_422 | Write a python function to find the average of cubes of first n natural numbers.
assert find_Average_Of_Cube(2) == 4.5
assert find_Average_Of_Cube(3) == 12
assert find_Average_Of_Cube(1) == 1
def find_Average_Of_Cube(n):
sum = 0
for i in range(1, n + 1):
sum += i * i * i
return round(sum / ... |
mbpp_data_423 | Write a function to solve gold mine problem.
assert get_maxgold([[1, 3, 1, 5],[2, 2, 4, 1],[5, 0, 2, 3],[0, 6, 1, 2]],4,4)==16
assert get_maxgold([[10,20],[30,40]],2,2)==70
assert get_maxgold([[4,9],[3,7]],2,2)==13
def get_maxgold(gold, m, n):
goldTable = [[0 for i in range(n)]
for j in ... |
mbpp_data_424 | Write a function to extract only the rear index element of each string in the given tuple.
assert extract_rear(('Mers', 'for', 'Vers') ) == ['s', 'r', 's']
assert extract_rear(('Avenge', 'for', 'People') ) == ['e', 'r', 'e']
assert extract_rear(('Gotta', 'get', 'go') ) == ['a', 't', 'o']
def extract_rear(test_tuple):
... |
mbpp_data_425 | Write a function to count the number of sublists containing a particular element.
assert count_element_in_list([[1, 3], [5, 7], [1, 11], [1, 15, 7]],1)==3
assert count_element_in_list([['A', 'B'], ['A', 'C'], ['A', 'D', 'E'], ['B', 'C', 'D']],'A')==3
assert count_element_in_list([['A', 'B'], ['A', 'C'], ['A', 'D', 'E']... |
mbpp_data_426 | Write a function to filter odd numbers using lambda function.
assert filter_oddnumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9]
assert filter_oddnumbers([10,20,45,67,84,93])==[45,67,93]
assert filter_oddnumbers([5,7,9,8,6,4,3])==[5,7,9,3]
def filter_oddnumbers(nums):
odd_nums = list(filter(lambda x: x%2 != 0, nu... |
mbpp_data_427 | Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format by using regex.
assert change_date_format("2026-01-02") == '02-01-2026'
assert change_date_format("2020-11-13") == '13-11-2020'
assert change_date_format("2021-04-26") == '26-04-2021'
import re
def change_date_format(dt):
return re.s... |
mbpp_data_428 | Write a function to sort the given array by using shell sort.
assert shell_sort([12, 23, 4, 5, 3, 2, 12, 81, 56, 95]) == [2, 3, 4, 5, 12, 12, 23, 56, 81, 95]
assert shell_sort([24, 22, 39, 34, 87, 73, 68]) == [22, 24, 34, 39, 68, 73, 87]
assert shell_sort([32, 30, 16, 96, 82, 83, 74]) == [16, 30, 32, 74, 82, 83, 96]
de... |
mbpp_data_429 | Write a function to extract the elementwise and tuples from the given two tuples.
assert and_tuples((10, 4, 6, 9), (5, 2, 3, 3)) == (0, 0, 2, 1)
assert and_tuples((1, 2, 3, 4), (5, 6, 7, 8)) == (1, 2, 3, 0)
assert and_tuples((8, 9, 11, 12), (7, 13, 14, 17)) == (0, 9, 10, 0)
def and_tuples(test_tup1, test_tup2):
res ... |
mbpp_data_430 | Write a function to find the directrix of a parabola.
assert parabola_directrix(5,3,2)==-198
assert parabola_directrix(9,8,4)==-2336
assert parabola_directrix(2,4,6)==-130
def parabola_directrix(a, b, c):
directrix=((int)(c - ((b * b) + 1) * 4 * a ))
return directrix |
mbpp_data_431 | Write a function that takes two lists and returns true if they have at least one common element.
assert common_element([1,2,3,4,5], [5,6,7,8,9])==True
assert common_element([1,2,3,4,5], [6,7,8,9])==None
assert common_element(['a','b','c'], ['d','b','e'])==True
def common_element(list1, list2):
result = False
... |
mbpp_data_432 | Write a function to find the median of a trapezium.
assert median_trapezium(15,25,35)==20
assert median_trapezium(10,20,30)==15
assert median_trapezium(6,9,4)==7.5
def median_trapezium(base1,base2,height):
median = 0.5 * (base1+ base2)
return median |
mbpp_data_433 | Write a function to check whether the entered number is greater than the elements of the given array.
assert check_greater([1, 2, 3, 4, 5], 4) == 'No, entered number is less than those in the array'
assert check_greater([2, 3, 4, 5, 6], 8) == 'Yes, the entered number is greater than those in the array'
assert check_gre... |
mbpp_data_434 | Write a function that matches a string that has an a followed by one or more b's.
assert text_match_one("ac")==('Not matched!')
assert text_match_one("dc")==('Not matched!')
assert text_match_one("abba")==('Found a match!')
import re
def text_match_one(text):
patterns = 'ab+?'
if re.search(patterns, ... |
mbpp_data_435 | Write a python function to find the last digit of a given number.
assert last_Digit(123) == 3
assert last_Digit(25) == 5
assert last_Digit(30) == 0
def last_Digit(n) :
return (n % 10) |
mbpp_data_436 | Write a python function to print negative numbers in a list.
assert neg_nos([-1,4,5,-6]) == -1,-6
assert neg_nos([-1,-2,3,4]) == -1,-2
assert neg_nos([-7,-6,8,9]) == -7,-6
def neg_nos(list1):
for num in list1:
if num < 0:
return num |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.