id stringlengths 11 13 | content stringlengths 165 5.63k |
|---|---|
mbpp_data_237 | Write a function to check the occurrences of records which occur similar times in the given tuples.
assert check_occurences([(3, 1), (1, 3), (2, 5), (5, 2), (6, 3)] ) == {(1, 3): 2, (2, 5): 2, (3, 6): 1}
assert check_occurences([(4, 2), (2, 4), (3, 6), (6, 3), (7, 4)] ) == {(2, 4): 2, (3, 6): 2, (4, 7): 1}
assert check... |
mbpp_data_238 | Write a python function to count number of non-empty substrings of a given string.
assert number_of_substrings("abc") == 6
assert number_of_substrings("abcd") == 10
assert number_of_substrings("abcde") == 15
def number_of_substrings(str):
str_len = len(str);
return int(str_len * (str_len + 1) / 2); |
mbpp_data_239 | Write a function to find the number of possible sequences of length n such that each of the next element is greater than or equal to twice of the previous element but less than or equal to m.
assert get_total_number_of_sequences(10, 4) == 4
assert get_total_number_of_sequences(5, 2) == 6
assert get_total_number_of_sequ... |
mbpp_data_240 | Write a function to replace the last element of the list with another list.
assert replace_list([1, 3, 5, 7, 9, 10],[2, 4, 6, 8])==[1, 3, 5, 7, 9, 2, 4, 6, 8]
assert replace_list([1,2,3,4,5],[5,6,7,8])==[1,2,3,4,5,6,7,8]
assert replace_list(["red","blue","green"],["yellow"])==["red","blue","yellow"]
def replace_list(li... |
mbpp_data_241 | Write a function to generate a 3d array having each element as '*'.
assert array_3d(6,4,3)==[[['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ... |
mbpp_data_242 | Write a function to count total characters in a string.
assert count_charac("python programming")==18
assert count_charac("language")==8
assert count_charac("words")==5
def count_charac(str1):
total = 0
for i in str1:
total = total + 1
return total |
mbpp_data_243 | Write a function to sort the given list based on the occurrence of first element of tuples.
assert sort_on_occurence([(1, 'Jake'), (2, 'Bob'), (1, 'Cara')]) == [(1, 'Jake', 'Cara', 2), (2, 'Bob', 1)]
assert sort_on_occurence([('b', 'ball'), ('a', 'arm'), ('b', 'b'), ('a', 'ant')]) == [('b', 'ball', 'b', 2), ('a', 'arm'... |
mbpp_data_244 | Write a python function to find the next perfect square greater than a given number.
assert next_Perfect_Square(35) == 36
assert next_Perfect_Square(6) == 9
assert next_Perfect_Square(9) == 16
import math
def next_Perfect_Square(N):
nextN = math.floor(math.sqrt(N)) + 1
return nextN * nextN |
mbpp_data_245 | Write a function to find the maximum sum of bi-tonic sub-sequence for the given array.
assert max_sum([1, 15, 51, 45, 33, 100, 12, 18, 9], 9) == 194
assert max_sum([80, 60, 30, 40, 20, 10], 6) == 210
assert max_sum([2, 3 ,14, 16, 21, 23, 29, 30], 8) == 138
def max_sum(arr, n):
MSIBS = arr[:]
for i in range(n):
... |
mbpp_data_246 | Write a function for computing square roots using the babylonian method.
assert babylonian_squareroot(10)==3.162277660168379
assert babylonian_squareroot(2)==1.414213562373095
assert babylonian_squareroot(9)==3.0
def babylonian_squareroot(number):
if(number == 0):
return 0;
g = number/2.0;
g2 = ... |
mbpp_data_247 | Write a function to find the longest palindromic subsequence in the given string.
assert lps("TENS FOR TENS") == 5
assert lps("CARDIO FOR CARDS") == 7
assert lps("PART OF THE JOURNEY IS PART") == 9
def lps(str):
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
f... |
mbpp_data_248 | Write a function to calculate the harmonic sum of n-1.
assert harmonic_sum(7) == 2.5928571428571425
assert harmonic_sum(4) == 2.083333333333333
assert harmonic_sum(19) == 3.547739657143682
def harmonic_sum(n):
if n < 2:
return 1
else:
return 1 / n + (harmonic_sum(n - 1)) |
mbpp_data_249 | Write a function to find the intersection of two arrays using lambda function.
assert intersection_array([1, 2, 3, 5, 7, 8, 9, 10],[1, 2, 4, 8, 9])==[1, 2, 8, 9]
assert intersection_array([1, 2, 3, 5, 7, 8, 9, 10],[3,5,7,9])==[3,5,7,9]
assert intersection_array([1, 2, 3, 5, 7, 8, 9, 10],[10,20,30,40])==[10]
def interse... |
mbpp_data_250 | Write a python function to count the occcurences of an element in a tuple.
assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),4) == 0
assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),10) == 3
assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),8) == 4
def count_X(tup, x):
count = 0
for ele in... |
mbpp_data_251 | Write a function to insert an element before each element of a list.
assert insert_element(['Red', 'Green', 'Black'] ,'c')==['c', 'Red', 'c', 'Green', 'c', 'Black']
assert insert_element(['python', 'java'] ,'program')==['program', 'python', 'program', 'java']
assert insert_element(['happy', 'sad'] ,'laugh')==['laugh'... |
mbpp_data_252 | Write a python function to convert complex numbers to polar coordinates.
assert convert(1) == (1.0, 0.0)
assert convert(4) == (4.0,0.0)
assert convert(5) == (5.0,0.0)
import cmath
def convert(numbers):
num = cmath.polar(numbers)
return (num) |
mbpp_data_253 | Write a python function to count integers from a given list.
assert count_integer([1,2,'abc',1.2]) == 2
assert count_integer([1,2,3]) == 3
assert count_integer([1,1.2,4,5.1]) == 2
def count_integer(list1):
ctr = 0
for i in list1:
if isinstance(i, int):
ctr = ctr + 1
return ctr |
mbpp_data_254 | Write a function to find all words starting with 'a' or 'e' in a given string.
assert words_ae("python programe")==['ame']
assert words_ae("python programe language")==['ame','anguage']
assert words_ae("assert statement")==['assert', 'atement']
import re
def words_ae(text):
list = re.findall("[ae]\w+", text)
retur... |
mbpp_data_255 | Write a function to choose specified number of colours from three different colours and generate all the combinations with repetitions.
assert combinations_colors( ["Red","Green","Blue"],1)==[('Red',), ('Green',), ('Blue',)]
assert combinations_colors( ["Red","Green","Blue"],2)==[('Red', 'Red'), ('Red', 'Green'), ('Red... |
mbpp_data_256 | Write a python function to count the number of prime numbers less than a given non-negative number.
assert count_Primes_nums(5) == 2
assert count_Primes_nums(10) == 4
assert count_Primes_nums(100) == 25
def count_Primes_nums(n):
ctr = 0
for num in range(n):
if num <= 1:
continue
... |
mbpp_data_257 | Write a function to swap two numbers.
assert swap_numbers(10,20)==(20,10)
assert swap_numbers(15,17)==(17,15)
assert swap_numbers(100,200)==(200,100)
def swap_numbers(a,b):
temp = a
a = b
b = temp
return (a,b) |
mbpp_data_258 | Write a function to find number of odd elements in the given list using lambda function.
assert count_odd([1, 2, 3, 5, 7, 8, 10])==4
assert count_odd([10,15,14,13,-18,12,-20])==2
assert count_odd([1, 2, 4, 8, 9])==2
def count_odd(array_nums):
count_odd = len(list(filter(lambda x: (x%2 != 0) , array_nums)))
retu... |
mbpp_data_259 | Write a function to maximize the given two tuples.
assert maximize_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((6, 7), (4, 9), (2, 9), (7, 10))
assert maximize_elements(((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))) == ((7, 8), (5, 10), (3, 10), (8, 11))
ass... |
mbpp_data_260 | Write a function to find the nth newman–shanks–williams prime number.
assert newman_prime(3) == 7
assert newman_prime(4) == 17
assert newman_prime(5) == 41
def newman_prime(n):
if n == 0 or n == 1:
return 1
return 2 * newman_prime(n - 1) + newman_prime(n - 2) |
mbpp_data_261 | Write a function to perform mathematical division operation across the given tuples.
assert division_elements((10, 4, 6, 9),(5, 2, 3, 3)) == (2, 2, 2, 3)
assert division_elements((12, 6, 8, 16),(6, 3, 4, 4)) == (2, 2, 2, 4)
assert division_elements((20, 14, 36, 18),(5, 7, 6, 9)) == (4, 2, 6, 2)
def division_elements(te... |
mbpp_data_262 | Write a function to split a given list into two parts where the length of the first part of the list is given.
assert split_two_parts([1,1,2,3,4,4,5,1],3)==([1, 1, 2], [3, 4, 4, 5, 1])
assert split_two_parts(['a', 'b', 'c', 'd'],2)==(['a', 'b'], ['c', 'd'])
assert split_two_parts(['p', 'y', 't', 'h', 'o', 'n'],4)==(['p... |
mbpp_data_263 | Write a function to merge two dictionaries.
assert merge_dict({'a': 100, 'b': 200},{'x': 300, 'y': 200})=={'x': 300, 'y': 200, 'a': 100, 'b': 200}
assert merge_dict({'a':900,'b':900,'d':900},{'a':900,'b':900,'d':900})=={'a':900,'b':900,'d':900,'a':900,'b':900,'d':900}
assert merge_dict({'a':10,'b':20},{'x':30,'y':40})=... |
mbpp_data_264 | Write a function to calculate a dog's age in dog's years.
assert dog_age(12)==61
assert dog_age(15)==73
assert dog_age(24)==109
def dog_age(h_age):
if h_age < 0:
exit()
elif h_age <= 2:
d_age = h_age * 10.5
else:
d_age = 21 + (h_age - 2)*4
return d_age |
mbpp_data_265 | Write a function to split a list for every nth element.
assert list_split(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'],3)==[['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']]
assert list_split([1,2,3,4,5,6,7,8,9,10,11,12,13,14],3)==[[1,4,7,10,13], [2,5,8,11,14], [3,6,... |
mbpp_data_266 | Write a function to find the lateral surface area of a cube.
assert lateralsurface_cube(5)==100
assert lateralsurface_cube(9)==324
assert lateralsurface_cube(10)==400
def lateralsurface_cube(l):
LSA = 4 * (l * l)
return LSA |
mbpp_data_267 | Write a python function to find the sum of squares of first n odd natural numbers.
assert square_Sum(2) == 10
assert square_Sum(3) == 35
assert square_Sum(4) == 84
def square_Sum(n):
return int(n*(4*n*n-1)/3) |
mbpp_data_268 | Write a function to find the n'th star number.
assert find_star_num(3) == 37
assert find_star_num(4) == 73
assert find_star_num(5) == 121
def find_star_num(n):
return (6 * n * (n - 1) + 1) |
mbpp_data_269 | Write a function to find the ascii value of a character.
assert ascii_value('A')==65
assert ascii_value('R')==82
assert ascii_value('S')==83
def ascii_value(k):
ch=k
return ord(ch) |
mbpp_data_270 | Write a python function to find the sum of even numbers at even positions.
assert sum_even_and_even_index([5, 6, 12, 1, 18, 8],6) == 30
assert sum_even_and_even_index([3, 20, 17, 9, 2, 10, 18, 13, 6, 18],10) == 26
assert sum_even_and_even_index([5, 6, 12, 1],4) == 12
def sum_even_and_even_index(arr,n):
i = 0
... |
mbpp_data_271 | Write a python function to find the sum of fifth power of first n even natural numbers.
assert even_Power_Sum(2) == 1056
assert even_Power_Sum(3) == 8832
assert even_Power_Sum(1) == 32
def even_Power_Sum(n):
sum = 0;
for i in range(1,n+1):
j = 2*i;
sum = sum + (j*j*j*j*j);
return s... |
mbpp_data_272 | Write a function to perfom the rear element extraction from list of tuples records.
assert rear_extract([(1, 'Rash', 21), (2, 'Varsha', 20), (3, 'Kil', 19)]) == [21, 20, 19]
assert rear_extract([(1, 'Sai', 36), (2, 'Ayesha', 25), (3, 'Salman', 45)]) == [36, 25, 45]
assert rear_extract([(1, 'Sudeep', 14), (2, 'Vandana',... |
mbpp_data_273 | Write a function to substract the contents of one tuple with corresponding index of other tuple.
assert substract_elements((10, 4, 5), (2, 5, 18)) == (8, -1, -13)
assert substract_elements((11, 2, 3), (24, 45 ,16)) == (-13, -43, -13)
assert substract_elements((7, 18, 9), (10, 11, 12)) == (-3, 7, -3)
def substract_eleme... |
mbpp_data_274 | Write a python function to find sum of even index binomial coefficients.
assert even_binomial_Coeff_Sum(4) == 8
assert even_binomial_Coeff_Sum(6) == 32
assert even_binomial_Coeff_Sum(2) == 2
import math
def even_binomial_Coeff_Sum( n):
return (1 << (n - 1)) |
mbpp_data_275 | Write a python function to find the position of the last removed element from the given array.
assert get_Position([2,5,4],3,2) == 2
assert get_Position([4,3],2,2) == 2
assert get_Position([1,2,3,4],4,1) == 4
import math as mt
def get_Position(a,n,m):
for i in range(n):
a[i] = (a[i] // m + (a[i] % m !... |
mbpp_data_276 | Write a function to find the volume of a cylinder.
assert volume_cylinder(10,5)==1570.7500000000002
assert volume_cylinder(4,5)==251.32000000000002
assert volume_cylinder(4,10)==502.64000000000004
def volume_cylinder(r,h):
volume=3.1415*r*r*h
return volume |
mbpp_data_277 | Write a function to filter a dictionary based on values.
assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},170)=={'Cierra Vega': 175, 'Alden Cantrell': 180, 'Pierre Cox': 190}
assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pier... |
mbpp_data_278 | Write a function to find the element count that occurs before the record in the given tuple.
assert count_first_elements((1, 5, 7, (4, 6), 10) ) == 3
assert count_first_elements((2, 9, (5, 7), 11) ) == 2
assert count_first_elements((11, 15, 5, 8, (2, 3), 8) ) == 4
def count_first_elements(test_tup):
for count, ele i... |
mbpp_data_279 | Write a function to find the nth decagonal number.
assert is_num_decagonal(3) == 27
assert is_num_decagonal(7) == 175
assert is_num_decagonal(10) == 370
def is_num_decagonal(n):
return 4 * n * n - 3 * n |
mbpp_data_280 | Write a function to search an element in the given array by using sequential search.
assert sequential_search([11,23,58,31,56,77,43,12,65,19],31) == (True, 3)
assert sequential_search([12, 32, 45, 62, 35, 47, 44, 61],61) == (True, 7)
assert sequential_search([9, 10, 17, 19, 22, 39, 48, 56],48) == (True, 6)
def sequenti... |
mbpp_data_281 | Write a python function to check if the elements of a given list are unique or not.
assert all_unique([1,2,3]) == True
assert all_unique([1,2,1,2]) == False
assert all_unique([1,2,3,4,5]) == True
def all_unique(test_list):
if len(test_list) > len(set(test_list)):
return False
return True |
mbpp_data_282 | Write a function to substaract two lists using map and lambda function.
assert sub_list([1, 2, 3],[4,5,6])==[-3,-3,-3]
assert sub_list([1,2],[3,4])==[-2,-2]
assert sub_list([90,120],[50,70])==[40,50]
def sub_list(nums1,nums2):
result = map(lambda x, y: x - y, nums1, nums2)
return list(result) |
mbpp_data_283 | Write a python function to check whether the frequency of each digit is less than or equal to the digit itself.
assert validate(1234) == True
assert validate(51241) == False
assert validate(321) == True
def validate(n):
for i in range(10):
temp = n;
count = 0;
while (temp):
... |
mbpp_data_284 | Write a function to check whether all items of a list are equal to a given string.
assert check_element(["green", "orange", "black", "white"],'blue')==False
assert check_element([1,2,3,4],7)==False
assert check_element(["green", "green", "green", "green"],'green')==True
def check_element(list,element):
check_element... |
mbpp_data_285 | Write a function that matches a string that has an a followed by two to three 'b'.
assert text_match_two_three("ac")==('Not matched!')
assert text_match_two_three("dc")==('Not matched!')
assert text_match_two_three("abbbba")==('Found a match!')
import re
def text_match_two_three(text):
patterns = 'ab{2,3}'
... |
mbpp_data_286 | Write a function to find the largest sum of contiguous array in the modified array which is formed by repeating the given array k times.
assert max_sub_array_sum_repeated([10, 20, -30, -1], 4, 3) == 30
assert max_sub_array_sum_repeated([-1, 10, 20], 3, 2) == 59
assert max_sub_array_sum_repeated([-1, -2, -3], 3, 3) == -... |
mbpp_data_287 | Write a python function to find the sum of squares of first n even natural numbers.
assert square_Sum(2) == 20
assert square_Sum(3) == 56
assert square_Sum(4) == 120
def square_Sum(n):
return int(2*n*(n+1)*(2*n+1)/3) |
mbpp_data_288 | Write a function to count array elements having modular inverse under given prime number p equal to itself.
assert modular_inverse([ 1, 6, 4, 5 ], 4, 7) == 2
assert modular_inverse([1, 3, 8, 12, 12], 5, 13) == 3
assert modular_inverse([2, 3, 4, 5], 4, 6) == 1
def modular_inverse(arr, N, P):
current_element = 0
for ... |
mbpp_data_289 | Write a python function to calculate the number of odd days in a given year.
assert odd_Days(100) == 5
assert odd_Days(50) ==6
assert odd_Days(75) == 2
def odd_Days(N):
hund1 = N // 100
hund4 = N // 400
leap = N >> 2
ordd = N - leap
if (hund1):
ordd += hund1
leap -= hund1 ... |
mbpp_data_290 | Write a function to find the list of lists with maximum length.
assert max_length([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])
assert max_length([[1], [5, 7], [10, 12, 14,15]])==(4, [10, 12, 14,15])
assert max_length([[5], [15,20,25]])==(3, [15,20,25])
def max_length(list1):
max_length = max(le... |
mbpp_data_291 | Write a function to find out the number of ways of painting the fence such that at most 2 adjacent posts have the same color for the given fence with n posts and k colors.
assert count_no_of_ways(2, 4) == 16
assert count_no_of_ways(3, 2) == 6
assert count_no_of_ways(4, 4) == 228
def count_no_of_ways(n, k):
dp = [0] ... |
mbpp_data_292 | Write a python function to find quotient of two numbers.
assert find(10,3) == 3
assert find(4,2) == 2
assert find(20,5) == 4
def find(n,m):
q = n//m
return (q) |
mbpp_data_293 | Write a function to find the third side of a right angled triangle.
assert otherside_rightangle(7,8)==10.63014581273465
assert otherside_rightangle(3,4)==5
assert otherside_rightangle(7,15)==16.55294535724685
import math
def otherside_rightangle(w,h):
s=math.sqrt((w*w)+(h*h))
return s |
mbpp_data_294 | Write a function to find the maximum value in a given heterogeneous list.
assert max_val(['Python', 3, 2, 4, 5, 'version'])==5
assert max_val(['Python', 15, 20, 25])==25
assert max_val(['Python', 30, 20, 40, 50, 'version'])==50
def max_val(listval):
max_val = max(i for i in listval if isinstance(i, int))
r... |
mbpp_data_295 | Write a function to return the sum of all divisors of a number.
assert sum_div(8)==7
assert sum_div(12)==16
assert sum_div(7)==1
def sum_div(number):
divisors = [1]
for i in range(2, number):
if (number % i)==0:
divisors.append(i)
return sum(divisors) |
mbpp_data_296 | Write a python function to count inversions in an array.
assert get_Inv_Count([1,20,6,4,5],5) == 5
assert get_Inv_Count([1,2,1],3) == 1
assert get_Inv_Count([1,2,5,6,1],5) == 3
def get_Inv_Count(arr,n):
inv_count = 0
for i in range(n):
for j in range(i + 1,n):
if (arr[i] > arr[j]):
... |
mbpp_data_297 | Write a function to flatten a given nested list structure.
assert flatten_list([0, 10, [20, 30], 40, 50, [60, 70, 80], [90, 100, 110, 120]])==[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]
assert flatten_list([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])==[10, 20, 40, 30, 56, 25, 10, 20, 33, 40]
assert ... |
mbpp_data_298 | Write a function to find the nested list elements which are present in another list.
assert intersection_nested_lists( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],[[12, 18, 23, 25, 45], [7, 11, 19, 24, 28], [1, 5, 8, 18, 15, 16]])==[[12], [7, 11], [1, 5, 8]]
assert intersection_nested_lists([[2, 3, 1], [4, 5], [6, ... |
mbpp_data_299 | Write a function to calculate the maximum aggregate from the list of tuples.
assert max_aggregate([('Juan Whelan',90),('Sabah Colley',88),('Peter Nichols',7),('Juan Whelan',122),('Sabah Colley',84)])==('Juan Whelan', 212)
assert max_aggregate([('Juan Whelan',50),('Sabah Colley',48),('Peter Nichols',37),('Juan Whelan',2... |
mbpp_data_300 | Write a function to find the count of all binary sequences of length 2n such that sum of first n bits is same as sum of last n bits.
assert count_binary_seq(1) == 2.0
assert count_binary_seq(2) == 6.0
assert count_binary_seq(3) == 20.0
def count_binary_seq(n):
nCr = 1
res = 1
for r in range(1, n + 1):
nCr = ... |
mbpp_data_301 | Write a function to find the depth of a dictionary.
assert dict_depth({'a':1, 'b': {'c': {'d': {}}}})==4
assert dict_depth({'a':1, 'b': {'c':'python'}})==2
assert dict_depth({1: 'Sun', 2: {3: {4:'Mon'}}})==3
def dict_depth(d):
if isinstance(d, dict):
return 1 + (max(map(dict_depth, d.values())) if d else ... |
mbpp_data_302 | Write a python function to find the most significant bit number which is also a set bit.
assert set_Bit_Number(6) == 4
assert set_Bit_Number(10) == 8
assert set_Bit_Number(18) == 16
def set_Bit_Number(n):
if (n == 0):
return 0;
msb = 0;
n = int(n / 2);
while (n > 0):
n = int(... |
mbpp_data_303 | Write a python function to check whether the count of inversion of two types are same or not.
assert solve([1,0,2],3) == True
assert solve([1,2,0],3) == False
assert solve([1,2,1],3) == True
import sys
def solve(a,n):
mx = -sys.maxsize - 1
for j in range(1,n):
if (mx > a[j]):
re... |
mbpp_data_304 | Write a python function to find element at a given index after number of rotations.
assert find_Element([1,2,3,4,5],[[0,2],[0,3]],2,1) == 3
assert find_Element([1,2,3,4],[[0,1],[0,2]],1,2) == 3
assert find_Element([1,2,3,4,5,6],[[0,1],[0,2]],1,1) == 1
def find_Element(arr,ranges,rotations,index) :
for i in range... |
mbpp_data_305 | Write a function to match two words from a list of words starting with letter 'p'.
assert start_withp(["Python PHP", "Java JavaScript", "c c++"])==('Python', 'PHP')
assert start_withp(["Python Programming","Java Programming"])==('Python','Programming')
assert start_withp(["Pqrst Pqr","qrstuv"])==('Pqrst','Pqr')
import ... |
mbpp_data_306 | Write a function to find the maximum sum of increasing subsequence from prefix till ith index and also including a given kth element which is after i, i.e., k > i .
assert max_sum_increasing_subseq([1, 101, 2, 3, 100, 4, 5 ], 7, 4, 6) == 11
assert max_sum_increasing_subseq([1, 101, 2, 3, 100, 4, 5 ], 7, 2, 5) == 7
asse... |
mbpp_data_307 | Write a function to get a colon of a tuple.
assert colon_tuplex(("HELLO", 5, [], True) ,2,50)==("HELLO", 5, [50], True)
assert colon_tuplex(("HELLO", 5, [], True) ,2,100)==(("HELLO", 5, [100],True))
assert colon_tuplex(("HELLO", 5, [], True) ,2,500)==("HELLO", 5, [500], True)
from copy import deepcopy
def colon_tuple... |
mbpp_data_308 | Write a function to find the specified number of largest products from two given lists.
assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],3)==[60, 54, 50]
assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],4)==[60, 54, 50, 48]
assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],5)==[60, 54, 5... |
mbpp_data_309 | Write a python function to find the maximum of two numbers.
assert maximum(5,10) == 10
assert maximum(-1,-2) == -1
assert maximum(9,7) == 9
def maximum(a,b):
if a >= b:
return a
else:
return b |
mbpp_data_310 | Write a function to convert a given string to a tuple.
assert string_to_tuple("python 3.0")==('p', 'y', 't', 'h', 'o', 'n', '3', '.', '0')
assert string_to_tuple("item1")==('i', 't', 'e', 'm', '1')
assert string_to_tuple("15.10")==('1', '5', '.', '1', '0')
def string_to_tuple(str1):
result = tuple(x for x in str1 ... |
mbpp_data_311 | Write a python function to set the left most unset bit.
assert set_left_most_unset_bit(10) == 14
assert set_left_most_unset_bit(12) == 14
assert set_left_most_unset_bit(15) == 15
def set_left_most_unset_bit(n):
if not (n & (n + 1)):
return n
pos, temp, count = 0, n, 0
while temp:
i... |
mbpp_data_312 | Write a function to find the volume of a cone.
assert volume_cone(5,12)==314.15926535897927
assert volume_cone(10,15)==1570.7963267948965
assert volume_cone(19,17)==6426.651371693521
import math
def volume_cone(r,h):
volume = (1.0/3) * math.pi * r * r * h
return volume |
mbpp_data_313 | Write a python function to print positive numbers in a list.
assert pos_nos([-1,-2,1,2]) == 1,2
assert pos_nos([3,4,-5]) == 3,4
assert pos_nos([-2,-3,1]) == 1
def pos_nos(list1):
for num in list1:
if num >= 0:
return num |
mbpp_data_314 | Write a function to find out the maximum sum such that no two chosen numbers are adjacent for the given rectangular grid of dimension 2 x n.
assert max_sum_rectangular_grid([ [1, 4, 5], [2, 0, 0 ] ], 3) == 7
assert max_sum_rectangular_grid([ [ 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10] ], 5) == 24
assert max_sum_rectangular_gri... |
mbpp_data_315 | Write a python function to find the first maximum length of even word.
assert find_Max_Len_Even("python language") == "language"
assert find_Max_Len_Even("maximum even length") == "length"
assert find_Max_Len_Even("eve") == "-1"
def find_Max_Len_Even(str):
n = len(str)
i = 0
currlen = 0
maxlen = 0... |
mbpp_data_316 | Write a function to find the index of the last occurrence of a given number in a sorted array.
assert find_last_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 3
assert find_last_occurrence([2, 3, 5, 8, 6, 6, 8, 9, 9, 9], 9) == 9
assert find_last_occurrence([2, 2, 1, 5, 6, 6, 6, 9, 9, 9], 6) == 6
def find_last_occurre... |
mbpp_data_317 | Write a function to reflect the modified run-length encoding from a list.
assert modified_encode([1,1,2,3,4,4,5,1])==[[2, 1], 2, 3, [2, 4], 5, 1]
assert modified_encode('automatically')==['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', [2, 'l'], 'y']
assert modified_encode('python')==['p', 'y', 't', 'h', 'o', 'n']
fr... |
mbpp_data_318 | Write a python function to find the maximum volume of a cuboid with given sum of sides.
assert max_volume(8) == 18
assert max_volume(4) == 2
assert max_volume(1) == 0
def max_volume (s):
maxvalue = 0
i = 1
for i in range(s - 1):
j = 1
for j in range(s):
k = s - i - j
... |
mbpp_data_319 | Write a function to find all five characters long word in the given string by using regex.
assert find_long_word('Please move back to strem') == ['strem']
assert find_long_word('4K Ultra HD streaming player') == ['Ultra']
assert find_long_word('Streaming Media Player') == ['Media']
import re
def find_long_word(text):
... |
mbpp_data_320 | Write a function to calculate the difference between the squared sum of first n natural numbers and the sum of squared first n natural numbers.
assert sum_difference(12)==5434
assert sum_difference(20)==41230
assert sum_difference(54)==2151270
def sum_difference(n):
sumofsquares = 0
squareofsum = 0
for n... |
mbpp_data_321 | Write a function to find the demlo number for the given number.
assert find_demlo("111111") == '12345654321'
assert find_demlo("1111") == '1234321'
assert find_demlo("13333122222") == '123456789101110987654321'
def find_demlo(s):
l = len(s)
res = ""
for i in range(1,l+1):
res = res + str(i)
for i in ran... |
mbpp_data_322 | Write a function to find all index positions of the minimum values in a given list.
assert position_min([12,33,23,10,67,89,45,667,23,12,11,10,54])==[3,11]
assert position_min([1,2,2,2,4,4,4,5,5,5,5])==[0]
assert position_min([2,1,5,6,8,3,4,9,10,11,8,12])==[1]
def position_min(list1):
min_val = min(list1)
min_... |
mbpp_data_323 | Write a function to re-arrange the given array in alternating positive and negative items.
assert re_arrange([-5, -2, 5, 2, 4, 7, 1, 8, 0, -8], 10) == [-5, 5, -2, 2, -8, 4, 7, 1, 8, 0]
assert re_arrange([1, 2, 3, -4, -1, 4], 6) == [-4, 1, -1, 2, 3, 4]
assert re_arrange([4, 7, 9, 77, -4, 5, -3, -9], 8) == [-4, 4, -3, 7,... |
mbpp_data_324 | Write a function to extract the sum of alternate chains of tuples.
assert sum_of_alternates((5, 6, 3, 6, 10, 34)) == (46, 18)
assert sum_of_alternates((1, 2, 3, 4, 5)) == (6, 9)
assert sum_of_alternates((6, 7, 8, 9, 4, 5)) == (21, 18)
def sum_of_alternates(test_tuple):
sum1 = 0
sum2 = 0
for idx, ele in enumera... |
mbpp_data_325 | Write a python function to find the minimum number of squares whose sum is equal to a given number.
assert get_Min_Squares(6) == 3
assert get_Min_Squares(2) == 2
assert get_Min_Squares(4) == 1
def get_Min_Squares(n):
if n <= 3:
return n;
res = n
for x in range(1,n + 1):
temp = x * x;
... |
mbpp_data_326 | Write a function to get the word with most number of occurrences in the given strings list.
assert most_occurrences(["UTS is best for RTF", "RTF love UTS", "UTS is best"] ) == 'UTS'
assert most_occurrences(["Its been a great year", "this year is so worse", "this year is okay"] ) == 'year'
assert most_occurrences(["Fami... |
mbpp_data_327 | Write a function to print check if the triangle is isosceles or not.
assert check_isosceles(6,8,12)==False
assert check_isosceles(6,6,12)==True
assert check_isosceles(6,16,20)==False
def check_isosceles(x,y,z):
if x==y or y==z or z==x:
return True
else:
return False |
mbpp_data_328 | Write a function to rotate a given list by specified number of items to the left direction.
assert rotate_left([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],3,4)==[4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4]
assert rotate_left([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2,2)==[3, 4, 5, 6, 7, 8, 9, 10, 1, 2]
assert rotate_left([1, 2, 3, 4, 5, 6, 7, 8, 9, ... |
mbpp_data_329 | Write a python function to count negative numbers in a list.
assert neg_count([-1,-2,3,-4,-5]) == 4
assert neg_count([1,2,3]) == 0
assert neg_count([1,2,-3,-10,20]) == 2
def neg_count(list):
neg_count= 0
for num in list:
if num <= 0:
neg_count += 1
return neg_count |
mbpp_data_330 | Write a function to find all three, four, five characters long words in the given string by using regex.
assert find_char('For the four consumer complaints contact manager AKR reddy') == ['For', 'the', 'four', 'AKR', 'reddy']
assert find_char('Certain service are subject to change MSR') == ['are', 'MSR']
assert find_ch... |
mbpp_data_331 | Write a python function to count unset bits of a given number.
assert count_unset_bits(2) == 1
assert count_unset_bits(4) == 2
assert count_unset_bits(6) == 1
def count_unset_bits(n):
count = 0
x = 1
while(x < n + 1):
if ((x & n) == 0):
count += 1
x = x << 1
return ... |
mbpp_data_332 | Write a function to count character frequency of a given string.
assert char_frequency('python')=={'p': 1, 'y': 1, 't': 1, 'h': 1, 'o': 1, 'n': 1}
assert char_frequency('program')=={'p': 1, 'r': 2, 'o': 1, 'g': 1, 'a': 1, 'm': 1}
assert char_frequency('language')=={'l': 1, 'a': 2, 'n': 1, 'g': 2, 'u': 1, 'e': 1}
def ch... |
mbpp_data_333 | Write a python function to sort a list according to the second element in sublist.
assert Sort([['a', 10], ['b', 5], ['c', 20], ['d', 15]]) == [['b', 5], ['a', 10], ['d', 15], ['c', 20]]
assert Sort([['452', 10], ['256', 5], ['100', 20], ['135', 15]]) == [['256', 5], ['452', 10], ['135', 15], ['100', 20]]
assert Sort([... |
mbpp_data_334 | Write a python function to check whether the triangle is valid or not if sides are given.
assert check_Validity(1,2,3) == False
assert check_Validity(2,3,5) == False
assert check_Validity(7,10,5) == True
def check_Validity(a,b,c):
if (a + b <= c) or (a + c <= b) or (b + c <= a) :
return False
else... |
mbpp_data_335 | Write a function to find the sum of arithmetic progression.
assert ap_sum(1,5,2)==25
assert ap_sum(2,6,4)==72
assert ap_sum(1,4,5)==34
def ap_sum(a,n,d):
total = (n * (2 * a + (n - 1) * d)) / 2
return total |
mbpp_data_336 | Write a function to check whether the given month name contains 28 days or not.
assert check_monthnum("February")==True
assert check_monthnum("January")==False
assert check_monthnum("March")==False
def check_monthnum(monthname1):
if monthname1 == "February":
return True
else:
return False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.