id stringlengths 11 13 | content stringlengths 165 5.63k |
|---|---|
mbpp_data_137 | Write a function to find the ration of zeroes in an array of integers.
assert zero_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8])==0.15
assert zero_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==0.00
assert zero_count([2, 4, -6, -9, 11, -12, 14, -5, 17])==0.00
from array import array
def zero_count(nums):
... |
mbpp_data_138 | Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.
assert is_Sum_Of_Powers_Of_Two(10) == True
assert is_Sum_Of_Powers_Of_Two(7) == False
assert is_Sum_Of_Powers_Of_Two(14) == True
def is_Sum_Of_Powers_Of_Two(n):
if (n % 2 == 1):
return Fal... |
mbpp_data_139 | Write a function to find the circumference of a circle.
assert circle_circumference(10)==62.830000000000005
assert circle_circumference(5)==31.415000000000003
assert circle_circumference(4)==25.132
def circle_circumference(r):
perimeter=2*3.1415*r
return perimeter |
mbpp_data_140 | Write a function to extract elements that occur singly in the given tuple list.
assert extract_singly([(3, 4, 5), (4, 5, 7), (1, 4)]) == [3, 4, 5, 7, 1]
assert extract_singly([(1, 2, 3), (4, 2, 3), (7, 8)]) == [1, 2, 3, 4, 7, 8]
assert extract_singly([(7, 8, 9), (10, 11, 12), (10, 11)]) == [7, 8, 9, 10, 11, 12]
def ext... |
mbpp_data_141 | Write a function to sort a list of elements using pancake sort.
assert pancake_sort([15, 79, 25, 38, 69]) == [15, 25, 38, 69, 79]
assert pancake_sort([98, 12, 54, 36, 85]) == [12, 36, 54, 85, 98]
assert pancake_sort([41, 42, 32, 12, 23]) == [12, 23, 32, 41, 42]
def pancake_sort(nums):
arr_len = len(nums)
whil... |
mbpp_data_142 | Write a function to count the same pair in three given lists.
assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,9],[2,1,3,1,2,6,7,9])==3
assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==4
assert count_samepair([1,2,3,4,2,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==5
def count_samepair... |
mbpp_data_143 | Write a function to find number of lists present in the given tuple.
assert find_lists(([1, 2, 3, 4], [5, 6, 7, 8])) == 2
assert find_lists(([1, 2], [3, 4], [5, 6])) == 3
assert find_lists(([9, 8, 7, 6, 5, 4, 3, 2, 1])) == 1
def find_lists(Input):
if isinstance(Input, list):
return 1
else:
return len(Inpu... |
mbpp_data_144 | Write a python function to find the sum of absolute differences in all pairs of the given array.
assert sum_Pairs([1,8,9,15,16],5) == 74
assert sum_Pairs([1,2,3,4],4) == 10
assert sum_Pairs([1,2,3,4,5,7,9,11,14],9) == 188
def sum_Pairs(arr,n):
sum = 0
for i in range(n - 1,-1,-1):
sum += i*arr[i] - ... |
mbpp_data_145 | Write a python function to find the maximum difference between any two elements in a given array.
assert max_Abs_Diff((2,1,5,3),4) == 4
assert max_Abs_Diff((9,3,2,5,1),5) == 8
assert max_Abs_Diff((3,2,1),3) == 2
def max_Abs_Diff(arr,n):
minEle = arr[0]
maxEle = arr[0]
for i in range(1, n):
m... |
mbpp_data_146 | Write a function to find the ascii value of total characters in a string.
assert ascii_value_string("python")==112
assert ascii_value_string("Program")==80
assert ascii_value_string("Language")==76
def ascii_value_string(str1):
for i in range(len(str1)):
return ord(str1[i]) |
mbpp_data_147 | Write a function to find the maximum total path sum in the given triangle.
assert max_path_sum([[1, 0, 0], [4, 8, 0], [1, 5, 3]], 2, 2) == 14
assert max_path_sum([[13, 0, 0], [7, 4, 0], [2, 4, 6]], 2, 2) == 24
assert max_path_sum([[2, 0, 0], [11, 18, 0], [21, 25, 33]], 2, 2) == 53
def max_path_sum(tri, m, n):
for i... |
mbpp_data_148 | Write a function to divide a number into two parts such that the sum of digits is maximum.
assert sum_digits_twoparts(35)==17
assert sum_digits_twoparts(7)==7
assert sum_digits_twoparts(100)==19
def sum_digits_single(x) :
ans = 0
while x :
ans += x % 10
x //= 10
return ans
def clo... |
mbpp_data_149 | Write a function to find the longest subsequence such that the difference between adjacents is one for the given array.
assert longest_subseq_with_diff_one([1, 2, 3, 4, 5, 3, 2], 7) == 6
assert longest_subseq_with_diff_one([10, 9, 4, 5, 4, 8, 6], 7) == 3
assert longest_subseq_with_diff_one([1, 2, 3, 2, 3, 7, 2, 1], 8) ... |
mbpp_data_150 | Write a python function to find whether the given number is present in the infinite sequence or not.
assert does_Contain_B(1,7,3) == True
assert does_Contain_B(1,-3,5) == False
assert does_Contain_B(3,2,5) == False
def does_Contain_B(a,b,c):
if (a == b):
return True
if ((b - a) * c > 0 and (b - a) ... |
mbpp_data_151 | Write a python function to check whether the given number is co-prime or not.
assert is_coprime(17,13) == True
assert is_coprime(15,21) == False
assert is_coprime(25,45) == False
def gcd(p,q):
while q != 0:
p, q = q,p%q
return p
def is_coprime(x,y):
return gcd(x,y) == 1 |
mbpp_data_152 | Write a function to sort the given array by using merge sort.
assert merge_sort([3, 4, 2, 6, 5, 7, 1, 9]) == [1, 2, 3, 4, 5, 6, 7, 9]
assert merge_sort([7, 25, 45, 78, 11, 33, 19]) == [7, 11, 19, 25, 33, 45, 78]
assert merge_sort([3, 1, 4, 9, 8]) == [1, 3, 4, 8, 9]
def merge(a,b):
c = []
while len(a) != 0 and... |
mbpp_data_153 | Write a function to find the vertex of a parabola.
assert parabola_vertex(5,3,2)==(-0.3, 1.55)
assert parabola_vertex(9,8,4)==(-0.4444444444444444, 2.2222222222222223)
assert parabola_vertex(2,4,6)==(-1.0, 4.0)
def parabola_vertex(a, b, c):
vertex=(((-b / (2 * a)),(((4 * a * c) - (b * b)) / (4 * a))))
return ver... |
mbpp_data_154 | Write a function to extract every specified element from a given two dimensional list.
assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],0)==[1, 4, 7]
assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],2)==[3, 6, 9]
assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],3... |
mbpp_data_155 | Write a python function to toggle all even bits of a given number.
assert even_bit_toggle_number(10) == 0
assert even_bit_toggle_number(20) == 30
assert even_bit_toggle_number(30) == 20
def even_bit_toggle_number(n) :
res = 0; count = 0; temp = n
while (temp > 0) :
if (count % 2 == 1) :
... |
mbpp_data_156 | Write a function to convert a tuple of string values to a tuple of integer values.
assert tuple_int_str((('333', '33'), ('1416', '55')))==((333, 33), (1416, 55))
assert tuple_int_str((('999', '99'), ('1000', '500')))==((999, 99), (1000, 500))
assert tuple_int_str((('666', '66'), ('1500', '555')))==((666, 66), (1500, 55... |
mbpp_data_157 | Write a function to reflect the run-length encoding from a list.
assert encode_list([1,1,2,3,4,4.3,5,1])==[[2, 1], [1, 2], [1, 3], [1, 4], [1, 4.3], [1, 5], [1, 1]]
assert encode_list('automatically')==[[1, 'a'], [1, 'u'], [1, 't'], [1, 'o'], [1, 'm'], [1, 'a'], [1, 't'], [1, 'i'], [1, 'c'], [1, 'a'], [2, 'l'], [1, 'y'... |
mbpp_data_158 | Write a python function to find k number of operations required to make all elements equal.
assert min_Ops([2,2,2,2],4,3) == 0
assert min_Ops([4,2,6,8],4,3) == -1
assert min_Ops([21,33,9,45,63],5,6) == 24
def min_Ops(arr,n,k):
max1 = max(arr)
res = 0
for i in range(0,n):
if ((max1 - arr[i]) ... |
mbpp_data_159 | Write a function to print the season for the given month and day.
assert month_season('January',4)==('winter')
assert month_season('October',28)==('autumn')
assert month_season('June',6)==('spring')
def month_season(month,days):
if month in ('January', 'February', 'March'):
season = 'winter'
elif month in ('Apri... |
mbpp_data_160 | Write a function to find x and y that satisfies ax + by = n.
assert solution(2, 3, 7) == ('x = ', 2, ', y = ', 1)
assert solution(4, 2, 7) == 'No solution'
assert solution(1, 13, 17) == ('x = ', 4, ', y = ', 1)
def solution (a, b, n):
i = 0
while i * a <= n:
if (n - (i * a)) % b == 0:
return ("x = ",i ,",... |
mbpp_data_161 | Write a function to remove all elements from a given list present in another list.
assert remove_elements([1,2,3,4,5,6,7,8,9,10],[2,4,6,8])==[1, 3, 5, 7, 9, 10]
assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],[1, 3, 5, 7])==[2, 4, 6, 8, 9, 10]
assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],[5,7])==[1, 2,... |
mbpp_data_162 | Write a function to calculate the sum of the positive integers of n+(n-2)+(n-4)... (until n-x =< 0).
assert sum_series(6)==12
assert sum_series(10)==30
assert sum_series(9)==25
def sum_series(n):
if n < 1:
return 0
else:
return n + sum_series(n - 2) |
mbpp_data_163 | Write a function to calculate the area of a regular polygon.
assert area_polygon(4,20)==400.00000000000006
assert area_polygon(10,15)==1731.1969896610804
assert area_polygon(9,7)==302.90938549487214
from math import tan, pi
def area_polygon(s,l):
area = s * (l ** 2) / (4 * tan(pi / s))
return area |
mbpp_data_164 | Write a python function to check whether the sum of divisors are same or not.
assert areEquivalent(36,57) == False
assert areEquivalent(2,4) == False
assert areEquivalent(23,47) == True
import math
def divSum(n):
sum = 1;
i = 2;
while(i * i <= n):
if (n % i == 0):
sum = (sum ... |
mbpp_data_165 | Write a python function to count characters at same position in a given string (lower and uppercase characters) as in english alphabet.
assert count_char_position("xbcefg") == 2
assert count_char_position("ABcED") == 3
assert count_char_position("AbgdeF") == 5
def count_char_position(str1):
count_chars = 0
f... |
mbpp_data_166 | Write a python function to count the pairs with xor as an even number.
assert find_even_Pair([5,4,7,2,1],5) == 4
assert find_even_Pair([7,2,8,1,0,5,11],7) == 9
assert find_even_Pair([1,2,3],3) == 1
def find_even_Pair(A,N):
evenPair = 0
for i in range(0,N):
for j in range(i+1,N):
if ((... |
mbpp_data_167 | Write a python function to find smallest power of 2 greater than or equal to n.
assert next_Power_Of_2(0) == 1
assert next_Power_Of_2(5) == 8
assert next_Power_Of_2(17) == 32
def next_Power_Of_2(n):
count = 0;
if (n and not(n & (n - 1))):
return n
while( n != 0):
n >>= 1
... |
mbpp_data_168 | Write a python function to find the frequency of a number in a given array.
assert frequency([1,2,3],4) == 0
assert frequency([1,2,2,3,3,3,4],3) == 3
assert frequency([0,1,2,3,1,2],1) == 2
def frequency(a,x):
count = 0
for i in a:
if i == x: count += 1
return count |
mbpp_data_169 | Write a function to calculate the nth pell number.
assert get_pell(4) == 12
assert get_pell(7) == 169
assert get_pell(8) == 408
def get_pell(n):
if (n <= 2):
return n
a = 1
b = 2
for i in range(3, n+1):
c = 2 * b + a
a = b
b = c
return b |
mbpp_data_170 | Write a function to find sum of the numbers in a list between the indices of a specified range.
assert sum_range_list( [2,1,5,6,8,3,4,9,10,11,8,12],8,10)==29
assert sum_range_list( [2,1,5,6,8,3,4,9,10,11,8,12],5,7)==16
assert sum_range_list( [2,1,5,6,8,3,4,9,10,11,8,12],7,10)==38
def sum_range_list(list1, m, n): ... |
mbpp_data_171 | Write a function to find the perimeter of a pentagon.
assert perimeter_pentagon(5)==25
assert perimeter_pentagon(10)==50
assert perimeter_pentagon(15)==75
import math
def perimeter_pentagon(a):
perimeter=(5*a)
return perimeter |
mbpp_data_172 | Write a function to find the occurence of characters 'std' in the given string 1. list item 1. list item 1. list item 2. list item 2. list item 2. list item
assert count_occurance("letstdlenstdporstd") == 3
assert count_occurance("truststdsolensporsd") == 1
assert count_occurance("makestdsostdworthit") == 2
def count_o... |
mbpp_data_173 | Write a function to remove everything except alphanumeric characters from a string.
assert remove_splchar('python @#&^%$*program123')==('pythonprogram123')
assert remove_splchar('python %^$@!^&*() programming24%$^^() language')==('pythonprogramming24language')
assert remove_splchar('python ^%&^()(+_)(_^&67) ... |
mbpp_data_174 | Write a function to group a sequence of key-value pairs into a dictionary of lists.
assert group_keyvalue([('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)])=={'yellow': [1, 3], 'blue': [2, 4], 'red': [1]}
assert group_keyvalue([('python', 1), ('python', 2), ('python', 3), ('python', 4), ('python', 5)... |
mbpp_data_175 | Write a function to verify validity of a string of parentheses.
assert is_valid_parenthese("(){}[]")==True
assert is_valid_parenthese("()[{)}")==False
assert is_valid_parenthese("()")==True
def is_valid_parenthese( str1):
stack, pchar = [], {"(": ")", "{": "}", "[": "]"}
for parenthese in str1:
... |
mbpp_data_176 | Write a function to find the perimeter of a triangle.
assert perimeter_triangle(10,20,30)==60
assert perimeter_triangle(3,4,5)==12
assert perimeter_triangle(25,35,45)==105
def perimeter_triangle(a,b,c):
perimeter=a+b+c
return perimeter |
mbpp_data_177 | Write a python function to find two distinct numbers such that their lcm lies within the given range.
assert answer(3,8) == (3,6)
assert answer(2,6) == (2,4)
assert answer(1,3) == (1,2)
def answer(L,R):
if (2 * L <= R):
return (L ,2*L)
else:
return (-1) |
mbpp_data_178 | Write a function to search some literals strings in a string.
assert string_literals(['language'],'python language')==('Matched!')
assert string_literals(['program'],'python language')==('Not Matched!')
assert string_literals(['python'],'programming language')==('Not Matched!')
import re
def string_literals(patterns,t... |
mbpp_data_179 | Write a function to find if the given number is a keith number or not.
assert is_num_keith(14) == True
assert is_num_keith(12) == False
assert is_num_keith(197) == True
def is_num_keith(x):
terms = []
temp = x
n = 0
while (temp > 0):
terms.append(temp % 10)
temp = int(temp / 10)
n+=1
terms.re... |
mbpp_data_180 | Write a function to calculate distance between two points using latitude and longitude.
assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429
assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514
assert distance_lat_long(10,20,30,40)==6783.751974994595
from math import radians, sin, cos, acos
de... |
mbpp_data_181 | Write a function to find the longest common prefix in the given set of strings.
assert common_prefix(["tablets", "tables", "taxi", "tamarind"], 4) == 'ta'
assert common_prefix(["apples", "ape", "april"], 3) == 'ap'
assert common_prefix(["teens", "teenager", "teenmar"], 3) == 'teen'
def common_prefix_util(str1, str2):
... |
mbpp_data_182 | Write a function to find uppercase, lowercase, special character and numeric values using regex.
assert find_character("ThisIsGeeksforGeeks") == (['T', 'I', 'G', 'G'], ['h', 'i', 's', 's', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'e', 'e', 'k', 's'], [], [])
assert find_character("Hithere2") == (['H'], ['i', 't', 'h', 'e', '... |
mbpp_data_183 | Write a function to count all the distinct pairs having a difference of k in any array.
assert count_pairs([1, 5, 3, 4, 2], 5, 3) == 2
assert count_pairs([8, 12, 16, 4, 0, 20], 6, 4) == 5
assert count_pairs([2, 4, 1, 3, 4], 5, 2) == 3
def count_pairs(arr, n, k):
count=0;
for i in range(0,n):
for j in range(i... |
mbpp_data_184 | Write a function to find all the values in a list that are greater than a specified number.
assert greater_specificnum([220, 330, 500],200)==True
assert greater_specificnum([12, 17, 21],20)==False
assert greater_specificnum([1,2,3,4],10)==False
def greater_specificnum(list,num):
greater_specificnum=all(x >= num for x... |
mbpp_data_185 | Write a function to find the focus of a parabola.
assert parabola_focus(5,3,2)==(-0.3, 1.6)
assert parabola_focus(9,8,4)==(-0.4444444444444444, 2.25)
assert parabola_focus(2,4,6)==(-1.0, 4.125)
def parabola_focus(a, b, c):
focus= (((-b / (2 * a)),(((4 * a * c) - (b * b) + 1) / (4 * a))))
return focus |
mbpp_data_186 | Write a function to search some literals strings in a string by using regex.
assert check_literals('The quick brown fox jumps over the lazy dog.',['fox']) == 'Matched!'
assert check_literals('The quick brown fox jumps over the lazy dog.',['horse']) == 'Not Matched!'
assert check_literals('The quick brown fox jumps over... |
mbpp_data_187 | Write a function to find the longest common subsequence for the given two sequences.
assert longest_common_subsequence("AGGTAB" , "GXTXAYB", 6, 7) == 4
assert longest_common_subsequence("ABCDGH" , "AEDFHR", 6, 6) == 3
assert longest_common_subsequence("AXYT" , "AYZX", 4, 4) == 2
def longest_common_subsequence(X, Y, m, ... |
mbpp_data_188 | Write a python function to check whether the given number can be represented by product of two squares or not.
assert prod_Square(25) == False
assert prod_Square(30) == False
assert prod_Square(16) == True
def prod_Square(n):
for i in range(2,(n) + 1):
if (i*i < (n+1)):
for j in range(2,n + 1... |
mbpp_data_189 | Write a python function to find the first missing positive number.
assert first_Missing_Positive([1,2,3,-1,5],5) == 4
assert first_Missing_Positive([0,-1,-2,1,5,8],6) == 2
assert first_Missing_Positive([0,1,2,5,-8],5) == 3
def first_Missing_Positive(arr,n):
ptr = 0
for i in range(n):
if arr[i] == 1:... |
mbpp_data_190 | Write a python function to count the number of integral co-ordinates that lie inside a square.
assert count_Intgral_Points(1,1,4,4) == 4
assert count_Intgral_Points(1,2,1,2) == 1
assert count_Intgral_Points(4,2,6,4) == 1
def count_Intgral_Points(x1,y1,x2,y2):
return ((y2 - y1 - 1) * (x2 - x1 - 1)) |
mbpp_data_191 | Write a function to check whether the given month name contains 30 days or not.
assert check_monthnumber("February")==False
assert check_monthnumber("June")==True
assert check_monthnumber("April")==True
def check_monthnumber(monthname3):
if monthname3 =="April" or monthname3== "June" or monthname3== "September" or m... |
mbpp_data_192 | Write a python function to check whether a string has atleast one letter and one number.
assert check_String('thishasboth29') == True
assert check_String('python') == False
assert check_String ('string') == False
def check_String(str):
flag_l = False
flag_n = False
for i in str:
if i.isalpha()... |
mbpp_data_193 | Write a function to remove the duplicates from the given tuple.
assert remove_tuple((1, 3, 5, 2, 3, 5, 1, 1, 3)) == (1, 2, 3, 5)
assert remove_tuple((2, 3, 4, 4, 5, 6, 6, 7, 8, 8)) == (2, 3, 4, 5, 6, 7, 8)
assert remove_tuple((11, 12, 13, 11, 11, 12, 14, 13)) == (11, 12, 13, 14)
def remove_tuple(test_tup):
res = tup... |
mbpp_data_194 | Write a python function to convert octal number to decimal number.
assert octal_To_Decimal(25) == 21
assert octal_To_Decimal(30) == 24
assert octal_To_Decimal(40) == 32
def octal_To_Decimal(n):
num = n;
dec_value = 0;
base = 1;
temp = num;
while (temp):
last_digit = temp % 10;
... |
mbpp_data_195 | Write a python function to find the first position of an element in a sorted array.
assert first([1,2,3,4,5,6,6],6,6) == 5
assert first([1,2,2,2,3,2,2,4,2],2,9) == 1
assert first([1,2,3],1,3) == 0
def first(arr,x,n):
low = 0
high = n - 1
res = -1
while (low <= high):
mid = (low + high) /... |
mbpp_data_196 | Write a function to remove all the tuples with length k.
assert remove_tuples([(4, 5), (4, ), (8, 6, 7), (1, ), (3, 4, 6, 7)] , 1) == [(4, 5), (8, 6, 7), (3, 4, 6, 7)]
assert remove_tuples([(4, 5), (4,5), (6, 7), (1, 2, 3), (3, 4, 6, 7)] ,2) == [(1, 2, 3), (3, 4, 6, 7)]
assert remove_tuples([(1, 4, 4), (4, 3), (8, 6, 7... |
mbpp_data_197 | Write a function to perform the exponentiation of the given two tuples.
assert find_exponentio((10, 4, 5, 6), (5, 6, 7, 5)) == (100000, 4096, 78125, 7776)
assert find_exponentio((11, 5, 6, 7), (6, 7, 8, 6)) == (1771561, 78125, 1679616, 117649)
assert find_exponentio((12, 6, 7, 8), (7, 8, 9, 7)) == (35831808, 1679616, 4... |
mbpp_data_198 | Write a function to find the largest triangle that can be inscribed in an ellipse.
assert largest_triangle(4,2)==10.392304845413264
assert largest_triangle(5,7)==4.639421805988064
assert largest_triangle(9,1)==105.2220865598093
import math
def largest_triangle(a,b):
if (a < 0 or b < 0):
return -1
... |
mbpp_data_199 | Write a python function to find highest power of 2 less than or equal to given number.
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_200 | Write a function to find all index positions of the maximum values in a given list.
assert position_max([12,33,23,10,67,89,45,667,23,12,11,10,54])==[7]
assert position_max([1,2,2,2,4,4,4,5,5,5,5])==[7,8,9,10]
assert position_max([2,1,5,6,8,3,4,9,10,11,8,12])==[11]
def position_max(list1):
max_val = max(list1)
... |
mbpp_data_201 | Write a python function to check whether the elements in a list are same or not.
assert chkList(['one','one','one']) == True
assert chkList(['one','Two','Three']) == False
assert chkList(['bigdata','python','Django']) == False
def chkList(lst):
return len(set(lst)) == 1 |
mbpp_data_202 | Write a function to remove even characters in a string.
assert remove_even("python")==("pto")
assert remove_even("program")==("porm")
assert remove_even("language")==("lnug")
def remove_even(str1):
str2 = ''
for i in range(1, len(str1) + 1):
if(i % 2 != 0):
str2 = str2 + str1[i - 1]
return str2 |
mbpp_data_203 | Write a python function to find the hamming distance between given two integers.
assert hamming_Distance(4,8) == 2
assert hamming_Distance(2,4) == 2
assert hamming_Distance(1,2) == 2
def hamming_Distance(n1,n2) :
x = n1 ^ n2
setBits = 0
while (x > 0) :
setBits += x & 1
x >>= 1
... |
mbpp_data_204 | Write a python function to count the occurrence of a given character in a string.
assert count("abcc","c") == 2
assert count("ababca","a") == 3
assert count("mnmm0pm","m") == 4
def count(s,c) :
res = 0
for i in range(len(s)) :
if (s[i] == c):
res = res + 1
return res |
mbpp_data_205 | Write a function to find the inversions of tuple elements in the given tuple list.
assert inversion_elements((7, 8, 9, 1, 10, 7)) == (-8, -9, -10, -2, -11, -8)
assert inversion_elements((2, 4, 5, 6, 1, 7)) == (-3, -5, -6, -7, -2, -8)
assert inversion_elements((8, 9, 11, 14, 12, 13)) == (-9, -10, -12, -15, -13, -14)
def... |
mbpp_data_206 | Write a function to perform the adjacent element concatenation in the given tuples.
assert concatenate_elements(("DSP ", "IS ", "BEST ", "FOR ", "ALL ", "UTS")) == ('DSP IS ', 'IS BEST ', 'BEST FOR ', 'FOR ALL ', 'ALL UTS')
assert concatenate_elements(("RES ", "IS ", "BEST ", "FOR ", "ALL ", "QESR")) == ('RES IS ', 'IS... |
mbpp_data_207 | Write a function to count the longest repeating subsequences such that the two subsequences don’t have same string characters at same positions.
assert find_longest_repeating_subseq("AABEBCDD") == 3
assert find_longest_repeating_subseq("aabb") == 2
assert find_longest_repeating_subseq("aab") == 1
def find_longest_repea... |
mbpp_data_208 | Write a function to check the given decimal with a precision of 2 by using regex.
assert is_decimal('123.11') == True
assert is_decimal('0.21') == True
assert is_decimal('123.1214') == False
import re
def is_decimal(num):
num_fetch = re.compile(r"""^[0-9]+(\.[0-9]{1,2})?$""")
result = num_fetch.search(num)
re... |
mbpp_data_209 | Write a function to delete the smallest element from the given heap and then insert a new item.
assert heap_replace( [25, 44, 68, 21, 39, 23, 89],21)==[21, 25, 23, 44, 39, 68, 89]
assert heap_replace([25, 44, 68, 21, 39, 23, 89],110)== [23, 25, 68, 44, 39, 110, 89]
assert heap_replace([25, 44, 68, 21, 39, 23, 89],500)=... |
mbpp_data_210 | Write a function to check that the given string contains only a certain set of characters(in this case a-z, a-z and 0-9) by using regex.
assert is_allowed_specific_char("ABCDEFabcdef123450") == True
assert is_allowed_specific_char("*&%@#!}{") == False
assert is_allowed_specific_char("HELLOhowareyou98765") == True
impor... |
mbpp_data_211 | Write a python function to count numbers whose oth and nth bits are set.
assert count_Num(2) == 1
assert count_Num(3) == 2
assert count_Num(1) == 1
def count_Num(n):
if (n == 1):
return 1
count = pow(2,n - 2)
return count |
mbpp_data_212 | Write a python function to find the sum of fourth power of n natural numbers.
assert fourth_Power_Sum(2) == 17
assert fourth_Power_Sum(4) == 354
assert fourth_Power_Sum(6) == 2275
import math
def fourth_Power_Sum(n):
sum = 0
for i in range(1,n+1) :
sum = sum + (i*i*i*i)
return sum |
mbpp_data_213 | Write a function to perform the concatenation of two string tuples.
assert concatenate_strings(("Manjeet", "Nikhil", "Akshat"), (" Singh", " Meherwal", " Garg")) == ('Manjeet Singh', 'Nikhil Meherwal', 'Akshat Garg')
assert concatenate_strings(("Shaik", "Ayesha", "Sanya"), (" Dawood", " Begum", " Singh")) == ('Shaik Da... |
mbpp_data_214 | Write a function to convert radians to degrees.
assert degree_radian(90)==5156.620156177409
assert degree_radian(60)==3437.746770784939
assert degree_radian(120)==6875.493541569878
import math
def degree_radian(radian):
degree = radian*(180/math.pi)
return degree |
mbpp_data_215 | Write a function to decode a run-length encoded given list.
assert decode_list([[2, 1], 2, 3, [2, 4], 5,1])==[1,1,2,3,4,4,5,1]
assert decode_list(['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', [2, 'l'], 'y'])==['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', 'l', 'l', 'y']
assert decode_list(['p', 'y', 't', 'h', ... |
mbpp_data_216 | Write a function to check if a nested list is a subset of another nested list.
assert check_subset_list([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]])==False
assert check_subset_list([[2, 3, 1], [4, 5], [6, 8]],[[4, 5], [6, 8]])==True
assert check_sub... |
mbpp_data_217 | Write a python function to find the first repeated character in a given string.
assert first_Repeated_Char("Google") == "o"
assert first_Repeated_Char("data") == "a"
assert first_Repeated_Char("python") == '\0'
def first_Repeated_Char(str):
h = {}
for ch in str:
if ch in h:
return ch;
... |
mbpp_data_218 | Write a python function to find the minimum operations required to make two numbers equal.
assert min_Operations(2,4) == 1
assert min_Operations(4,10) == 4
assert min_Operations(1,4) == 3
import math
def min_Operations(A,B):
if (A > B):
swap(A,B)
B = B // math.gcd(A,B);
return B - 1 |
mbpp_data_219 | Write a function to extract maximum and minimum k elements in the given tuple.
assert extract_min_max((5, 20, 3, 7, 6, 8), 2) == (3, 5, 8, 20)
assert extract_min_max((4, 5, 6, 1, 2, 7), 3) == (1, 2, 4, 5, 6, 7)
assert extract_min_max((2, 3, 4, 8, 9, 11, 7), 4) == (2, 3, 4, 7, 8, 9, 11)
def extract_min_max(test_tup, K... |
mbpp_data_220 | Write a function to replace maximum n occurrences of spaces, commas, or dots with a colon.
assert replace_max_specialchar('Python language, Programming language.',2)==('Python:language: Programming language.')
assert replace_max_specialchar('a b c,d e f',3)==('a:b:c:d e f')
assert replace_max_specialchar('ram reshma,ra... |
mbpp_data_221 | Write a python function to find the first even number in a given list of numbers.
assert first_even ([1, 3, 5, 7, 4, 1, 6, 8]) == 4
assert first_even([2, 3, 4]) == 2
assert first_even([5, 6, 7]) == 6
def first_even(nums):
first_even = next((el for el in nums if el%2==0),-1)
return first_even |
mbpp_data_222 | Write a function to check if all the elements in tuple have same data type or not.
assert check_type((5, 6, 7, 3, 5, 6) ) == True
assert check_type((1, 2, "4") ) == False
assert check_type((3, 2, 1, 4, 5) ) == True
def check_type(test_tuple):
res = True
for ele in test_tuple:
if not isinstance(ele, type(test... |
mbpp_data_223 | Write a function to check for majority element in the given sorted array.
assert is_majority([1, 2, 3, 3, 3, 3, 10], 7, 3) == True
assert is_majority([1, 1, 2, 4, 4, 4, 6, 6], 8, 4) == False
assert is_majority([1, 1, 1, 2, 2], 5, 1) == True
def is_majority(arr, n, x):
i = binary_search(arr, 0, n-1, x)
if i == -1:
... |
mbpp_data_224 | Write a python function to count set bits of a given number.
assert count_Set_Bits(2) == 1
assert count_Set_Bits(4) == 1
assert count_Set_Bits(6) == 2
def count_Set_Bits(n):
count = 0
while (n):
count += n & 1
n >>= 1
return count |
mbpp_data_225 | Write a python function to find the minimum element in a sorted and rotated array.
assert find_Min([1,2,3,4,5],0,4) == 1
assert find_Min([4,6,8],0,2) == 4
assert find_Min([2,3,5,7,9],0,4) == 2
def find_Min(arr,low,high):
while (low < high):
mid = low + (high - low) // 2;
if (arr[mid] == arr[... |
mbpp_data_226 | Write a python function to remove the characters which have odd index values of a given string.
assert odd_values_string('abcdef') == 'ace'
assert odd_values_string('python') == 'pto'
assert odd_values_string('data') == 'dt'
def odd_values_string(str):
result = ""
for i in range(len(str)):
if i % 2 == 0:
... |
mbpp_data_227 | Write a function to find minimum of three numbers.
assert min_of_three(10,20,0)==0
assert min_of_three(19,15,18)==15
assert min_of_three(-10,-20,-30)==-30
def min_of_three(a,b,c):
if (a <= b) and (a <= c):
smallest = a
elif (b <= a) and (b <= c):
smallest = b
else:
... |
mbpp_data_228 | Write a python function to check whether all the bits are unset in the given range or not.
assert all_Bits_Set_In_The_Given_Range(4,1,2) == True
assert all_Bits_Set_In_The_Given_Range(17,2,4) == True
assert all_Bits_Set_In_The_Given_Range(39,4,6) == False
def all_Bits_Set_In_The_Given_Range(n,l,r):
num = (((1 <<... |
mbpp_data_229 | Write a function to re-arrange the elements of the given array so that all negative elements appear before positive ones.
assert re_arrange_array([-1, 2, -3, 4, 5, 6, -7, 8, 9], 9) == [-1, -3, -7, 4, 5, 6, 2, 8, 9]
assert re_arrange_array([12, -14, -26, 13, 15], 5) == [-14, -26, 12, 13, 15]
assert re_arrange_array([10,... |
mbpp_data_230 | Write a function to replace blank spaces with any character in a string.
assert replace_blank("hello people",'@')==("hello@people")
assert replace_blank("python program language",'$')==("python$program$language")
assert replace_blank("blank space","-")==("blank-space")
def replace_blank(str1,char):
str2 = str1.replac... |
mbpp_data_231 | Write a function to find the maximum sum in the given right triangle of numbers.
assert max_sum([[1], [2,1], [3,3,2]], 3) == 6
assert max_sum([[1], [1, 2], [4, 1, 12]], 3) == 15
assert max_sum([[2], [3,2], [13,23,12]], 3) == 28
def max_sum(tri, n):
if n > 1:
tri[1][1] = tri[1][1]+tri[0][0]
tri[1][0] = tri[1... |
mbpp_data_232 | Write a function to get the n largest items from a dataset.
assert larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2)==[100,90]
assert larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5)==[100,90,80,70,60]
assert larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3)==[100,90,80]
import heapq
def la... |
mbpp_data_233 | Write a function to find the lateral surface area of a cylinder.
assert lateralsuface_cylinder(10,5)==314.15000000000003
assert lateralsuface_cylinder(4,5)==125.66000000000001
assert lateralsuface_cylinder(4,10)==251.32000000000002
def lateralsuface_cylinder(r,h):
lateralsurface= 2*3.1415*r*h
return lateralsurfac... |
mbpp_data_234 | Write a function to find the volume of a cube.
assert volume_cube(3)==27
assert volume_cube(2)==8
assert volume_cube(5)==125
def volume_cube(l):
volume = l * l * l
return volume |
mbpp_data_235 | Write a python function to set all even bits of a given number.
assert even_bit_set_number(10) == 10
assert even_bit_set_number(20) == 30
assert even_bit_set_number(30) == 30
def even_bit_set_number(n):
count = 0;res = 0;temp = n
while(temp > 0):
if (count % 2 == 1):
res |= (1 << cou... |
mbpp_data_236 | Write a python function to count the maximum number of equilateral triangles that can be formed within a given equilateral triangle.
assert No_of_Triangle(4,2) == 7
assert No_of_Triangle(4,3) == 3
assert No_of_Triangle(1,3) == -1
def No_of_Triangle(N,K):
if (N < K):
return -1;
else:
Tri_up =... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.