question_title
stringlengths 7
8
| question_content
stringlengths 37
191
| question_id
stringlengths 2
3
| contest_id
stringclasses 1
value | test_id
int64 0
5
| contest_date
timestamp[us] | starter_code
stringlengths 37
1.33k
| function_name
stringlengths 3
32
| difficulty
stringclasses 1
value | test
stringlengths 57
1.94k
|
---|---|---|---|---|---|---|---|---|---|
Mbpp_11 | Write a python function to remove first and last occurrence of a given character from the string. | 11 | mbpp | 0 | 2024-11-26T21:40:54.077000 | def remove_Occ(s,ch):
for i in range(len(s)):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
for i in range(len(s) - 1,-1,-1):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
return s | remove_Occ | easy | [{"input": "\"hello\",\"l\"", "output": "\"heo\"", "testtype": "functional"}] |
Mbpp_11 | Write a python function to remove first and last occurrence of a given character from the string. | 11 | mbpp | 1 | 2024-11-26T21:40:54.078000 | def remove_Occ(s,ch):
for i in range(len(s)):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
for i in range(len(s) - 1,-1,-1):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
return s | remove_Occ | easy | [{"input": "\"abcda\",\"a\"", "output": "\"bcd\"", "testtype": "functional"}] |
Mbpp_11 | Write a python function to remove first and last occurrence of a given character from the string. | 11 | mbpp | 2 | 2024-11-26T21:40:54.078000 | def remove_Occ(s,ch):
for i in range(len(s)):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
for i in range(len(s) - 1,-1,-1):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
return s | remove_Occ | easy | [{"input": "\"PHP\",\"P\"", "output": "\"H\"", "testtype": "functional"}] |
Mbpp_11 | Write a python function to remove first and last occurrence of a given character from the string. | 11 | mbpp | 3 | 2024-11-26T21:40:54.078000 | def remove_Occ(s,ch):
for i in range(len(s)):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
for i in range(len(s) - 1,-1,-1):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
return s | remove_Occ | easy | [{"input": "\"hellolloll\",\"l\"", "output": "\"helollol\"", "testtype": "functional"}] |
Mbpp_11 | Write a python function to remove first and last occurrence of a given character from the string. | 11 | mbpp | 4 | 2024-11-26T21:40:54.079000 | def remove_Occ(s,ch):
for i in range(len(s)):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
for i in range(len(s) - 1,-1,-1):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
return s | remove_Occ | easy | [{"input": "\"\",\"l\"", "output": "\"\"", "testtype": "functional"}] |
Mbpp_12 | Write a function to sort a given matrix in ascending order according to the sum of its rows. | 12 | mbpp | 0 | 2024-11-26T21:40:54.079000 | def sort_matrix(M):
result = sorted(M, key=sum)
return result | sort_matrix | easy | [{"input": "[[1, 2, 3], [2, 4, 5], [1, 1, 1]]", "output": "[[1, 1, 1], [1, 2, 3], [2, 4, 5]]", "testtype": "functional"}] |
Mbpp_12 | Write a function to sort a given matrix in ascending order according to the sum of its rows. | 12 | mbpp | 1 | 2024-11-26T21:40:54.079000 | def sort_matrix(M):
result = sorted(M, key=sum)
return result | sort_matrix | easy | [{"input": "[[1, 2, 3], [-2, 4, -5], [1, -1, 1]]", "output": "[[-2, 4, -5], [1, -1, 1], [1, 2, 3]]", "testtype": "functional"}] |
Mbpp_12 | Write a function to sort a given matrix in ascending order according to the sum of its rows. | 12 | mbpp | 2 | 2024-11-26T21:40:54.079000 | def sort_matrix(M):
result = sorted(M, key=sum)
return result | sort_matrix | easy | [{"input": "[[5,8,9],[6,4,3],[2,1,4]]", "output": "[[2, 1, 4], [6, 4, 3], [5, 8, 9]]", "testtype": "functional"}] |
Mbpp_13 | Write a function to count the most common words in a dictionary. | 13 | mbpp | 0 | 2024-11-26T21:40:54.079000 | from collections import Counter
def count_common(words):
word_counts = Counter(words)
top_four = word_counts.most_common(4)
return (top_four)
| count_common | easy | [{"input": "['red','green','black','pink','black','white','black','eyes','white','black','orange','pink','pink','red','red','white','orange','white',\"black\",'pink','green','green','pink','green','pink','white','orange',\"orange\",'red']", "output": "[('pink', 6), ('black', 5), ('white', 5), ('red', 4)]", "testtype": "functional"}] |
Mbpp_13 | Write a function to count the most common words in a dictionary. | 13 | mbpp | 1 | 2024-11-26T21:40:54.080000 | from collections import Counter
def count_common(words):
word_counts = Counter(words)
top_four = word_counts.most_common(4)
return (top_four)
| count_common | easy | [{"input": "['one', 'two', 'three', 'four', 'five', 'one', 'two', 'one', 'three', 'one']", "output": "[('one', 4), ('two', 2), ('three', 2), ('four', 1)]", "testtype": "functional"}] |
Mbpp_13 | Write a function to count the most common words in a dictionary. | 13 | mbpp | 2 | 2024-11-26T21:40:54.080000 | from collections import Counter
def count_common(words):
word_counts = Counter(words)
top_four = word_counts.most_common(4)
return (top_four)
| count_common | easy | [{"input": "['Facebook', 'Apple', 'Amazon', 'Netflix', 'Google', 'Apple', 'Netflix', 'Amazon']", "output": "[('Apple', 2), ('Amazon', 2), ('Netflix', 2), ('Facebook', 1)]", "testtype": "functional"}] |
Mbpp_14 | Write a python function to find the volume of a triangular prism. | 14 | mbpp | 0 | 2024-11-26T21:40:54.080000 | def find_Volume(l,b,h) :
return ((l * b * h) / 2) | find_Volume | easy | [{"input": "10,8,6", "output": "240", "testtype": "functional"}] |
Mbpp_14 | Write a python function to find the volume of a triangular prism. | 14 | mbpp | 1 | 2024-11-26T21:40:54.080000 | def find_Volume(l,b,h) :
return ((l * b * h) / 2) | find_Volume | easy | [{"input": "3,2,2", "output": "6", "testtype": "functional"}] |
Mbpp_14 | Write a python function to find the volume of a triangular prism. | 14 | mbpp | 2 | 2024-11-26T21:40:54.080000 | def find_Volume(l,b,h) :
return ((l * b * h) / 2) | find_Volume | easy | [{"input": "1,2,1", "output": "1", "testtype": "functional"}] |
Mbpp_15 | Write a function to split a string at lowercase letters. | 15 | mbpp | 0 | 2024-11-26T21:40:54.080000 | import re
def split_lowerstring(text):
return (re.findall('[a-z][^a-z]*', text)) | split_lowerstring | easy | [{"input": "\"AbCd\"", "output": "['bC','d']", "testtype": "functional"}] |
Mbpp_15 | Write a function to split a string at lowercase letters. | 15 | mbpp | 1 | 2024-11-26T21:40:54.080000 | import re
def split_lowerstring(text):
return (re.findall('[a-z][^a-z]*', text)) | split_lowerstring | easy | [{"input": "\"Python\"", "output": "['y', 't', 'h', 'o', 'n']", "testtype": "functional"}] |
Mbpp_15 | Write a function to split a string at lowercase letters. | 15 | mbpp | 2 | 2024-11-26T21:40:54.080000 | import re
def split_lowerstring(text):
return (re.findall('[a-z][^a-z]*', text)) | split_lowerstring | easy | [{"input": "\"Programming\"", "output": "['r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g']", "testtype": "functional"}] |
Mbpp_16 | Write a function to find sequences of lowercase letters joined with an underscore. | 16 | mbpp | 0 | 2024-11-26T21:40:54.081000 | import re
def text_lowercase_underscore(text):
patterns = '^[a-z]+_[a-z]+$'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | text_lowercase_underscore | easy | [{"input": "\"aab_cbbbc\"", "output": "('Found a match!')", "testtype": "functional"}] |
Mbpp_16 | Write a function to find sequences of lowercase letters joined with an underscore. | 16 | mbpp | 1 | 2024-11-26T21:40:54.081000 | import re
def text_lowercase_underscore(text):
patterns = '^[a-z]+_[a-z]+$'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | text_lowercase_underscore | easy | [{"input": "\"aab_Abbbc\"", "output": "('Not matched!')", "testtype": "functional"}] |
Mbpp_16 | Write a function to find sequences of lowercase letters joined with an underscore. | 16 | mbpp | 2 | 2024-11-26T21:40:54.081000 | import re
def text_lowercase_underscore(text):
patterns = '^[a-z]+_[a-z]+$'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | text_lowercase_underscore | easy | [{"input": "\"Aaab_abbbc\"", "output": "('Not matched!')", "testtype": "functional"}] |
Mbpp_16 | Write a function to find sequences of lowercase letters joined with an underscore. | 16 | mbpp | 3 | 2024-11-26T21:40:54.081000 | import re
def text_lowercase_underscore(text):
patterns = '^[a-z]+_[a-z]+$'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | text_lowercase_underscore | easy | [{"input": "\"aab-cbbbc\"", "output": "('Not matched!')", "testtype": "functional"}] |
Mbpp_17 | Write a function to find the perimeter of a square. | 17 | mbpp | 0 | 2024-11-26T21:40:54.081000 | def square_perimeter(a):
perimeter=4*a
return perimeter | square_perimeter | easy | [{"input": "10", "output": "40", "testtype": "functional"}] |
Mbpp_17 | Write a function to find the perimeter of a square. | 17 | mbpp | 1 | 2024-11-26T21:40:54.081000 | def square_perimeter(a):
perimeter=4*a
return perimeter | square_perimeter | easy | [{"input": "5", "output": "20", "testtype": "functional"}] |
Mbpp_17 | Write a function to find the perimeter of a square. | 17 | mbpp | 2 | 2024-11-26T21:40:54.081000 | def square_perimeter(a):
perimeter=4*a
return perimeter | square_perimeter | easy | [{"input": "4", "output": "16", "testtype": "functional"}] |
Mbpp_19 | Write a function to find whether a given array of integers contains any duplicate element. | 19 | mbpp | 0 | 2024-11-26T21:40:54.082000 | def test_duplicate(arraynums):
nums_set = set(arraynums)
return len(arraynums) != len(nums_set) | test_duplicate | easy | [{"input": "([1,2,3,4,5])", "output": "False", "testtype": "functional"}] |
Mbpp_19 | Write a function to find whether a given array of integers contains any duplicate element. | 19 | mbpp | 1 | 2024-11-26T21:40:54.083000 | def test_duplicate(arraynums):
nums_set = set(arraynums)
return len(arraynums) != len(nums_set) | test_duplicate | easy | [{"input": "([1,2,3,4, 4])", "output": "True", "testtype": "functional"}] |
Mbpp_19 | Write a function to find whether a given array of integers contains any duplicate element. | 19 | mbpp | 2 | 2024-11-26T21:40:54.083000 | def test_duplicate(arraynums):
nums_set = set(arraynums)
return len(arraynums) != len(nums_set) | test_duplicate | easy | [{"input": "[1,1,2,2,3,3,4,4,5]", "output": "True", "testtype": "functional"}] |
Mbpp_20 | Write a function to check if the given number is woodball or not. | 20 | mbpp | 0 | 2024-11-26T21:40:54.083000 | def is_woodall(x):
if (x % 2 == 0):
return False
if (x == 1):
return True
x = x + 1
p = 0
while (x % 2 == 0):
x = x/2
p = p + 1
if (p == x):
return True
return False | is_woodall | easy | [{"input": "383", "output": "True", "testtype": "functional"}] |
Mbpp_20 | Write a function to check if the given number is woodball or not. | 20 | mbpp | 1 | 2024-11-26T21:40:54.083000 | def is_woodall(x):
if (x % 2 == 0):
return False
if (x == 1):
return True
x = x + 1
p = 0
while (x % 2 == 0):
x = x/2
p = p + 1
if (p == x):
return True
return False | is_woodall | easy | [{"input": "254", "output": "False", "testtype": "functional"}] |
Mbpp_20 | Write a function to check if the given number is woodball or not. | 20 | mbpp | 2 | 2024-11-26T21:40:54.084000 | def is_woodall(x):
if (x % 2 == 0):
return False
if (x == 1):
return True
x = x + 1
p = 0
while (x % 2 == 0):
x = x/2
p = p + 1
if (p == x):
return True
return False | is_woodall | easy | [{"input": "200", "output": "False", "testtype": "functional"}] |
Mbpp_20 | Write a function to check if the given number is woodball or not. | 20 | mbpp | 3 | 2024-11-26T21:40:54.084000 | def is_woodall(x):
if (x % 2 == 0):
return False
if (x == 1):
return True
x = x + 1
p = 0
while (x % 2 == 0):
x = x/2
p = p + 1
if (p == x):
return True
return False | is_woodall | easy | [{"input": "32212254719", "output": "True", "testtype": "functional"}] |
Mbpp_20 | Write a function to check if the given number is woodball or not. | 20 | mbpp | 4 | 2024-11-26T21:40:54.084000 | def is_woodall(x):
if (x % 2 == 0):
return False
if (x == 1):
return True
x = x + 1
p = 0
while (x % 2 == 0):
x = x/2
p = p + 1
if (p == x):
return True
return False | is_woodall | easy | [{"input": "32212254718", "output": "False", "testtype": "functional"}] |
Mbpp_20 | Write a function to check if the given number is woodball or not. | 20 | mbpp | 5 | 2024-11-26T21:40:54.084000 | def is_woodall(x):
if (x % 2 == 0):
return False
if (x == 1):
return True
x = x + 1
p = 0
while (x % 2 == 0):
x = x/2
p = p + 1
if (p == x):
return True
return False | is_woodall | easy | [{"input": "159", "output": "True", "testtype": "functional"}] |
Mbpp_21 | Write a function to find m number of multiples of n. | 21 | mbpp | 0 | 2024-11-26T21:40:54.085000 | def multiples_of_num(m,n):
multiples_of_num= list(range(n,(m+1)*n, n))
return list(multiples_of_num) | multiples_of_num | easy | [{"input": "4,3", "output": "[3,6,9,12]", "testtype": "functional"}] |
Mbpp_21 | Write a function to find m number of multiples of n. | 21 | mbpp | 1 | 2024-11-26T21:40:54.085000 | def multiples_of_num(m,n):
multiples_of_num= list(range(n,(m+1)*n, n))
return list(multiples_of_num) | multiples_of_num | easy | [{"input": "2,5", "output": "[5,10]", "testtype": "functional"}] |
Mbpp_21 | Write a function to find m number of multiples of n. | 21 | mbpp | 2 | 2024-11-26T21:40:54.085000 | def multiples_of_num(m,n):
multiples_of_num= list(range(n,(m+1)*n, n))
return list(multiples_of_num) | multiples_of_num | easy | [{"input": "9,2", "output": "[2,4,6,8,10,12,14,16,18]", "testtype": "functional"}] |
Mbpp_22 | Write a function to find the first duplicate element in a given array of integers. | 22 | mbpp | 0 | 2024-11-26T21:40:54.085000 | def find_first_duplicate(nums):
num_set = set()
no_duplicate = -1
for i in range(len(nums)):
if nums[i] in num_set:
return nums[i]
else:
num_set.add(nums[i])
return no_duplicate | find_first_duplicate | easy | [{"input": "([1, 2, 3, 4, 4, 5])", "output": "4", "testtype": "functional"}] |
Mbpp_22 | Write a function to find the first duplicate element in a given array of integers. | 22 | mbpp | 1 | 2024-11-26T21:40:54.085000 | def find_first_duplicate(nums):
num_set = set()
no_duplicate = -1
for i in range(len(nums)):
if nums[i] in num_set:
return nums[i]
else:
num_set.add(nums[i])
return no_duplicate | find_first_duplicate | easy | [{"input": "[1, 2, 3, 4]", "output": "-1", "testtype": "functional"}] |
Mbpp_22 | Write a function to find the first duplicate element in a given array of integers. | 22 | mbpp | 2 | 2024-11-26T21:40:54.086000 | def find_first_duplicate(nums):
num_set = set()
no_duplicate = -1
for i in range(len(nums)):
if nums[i] in num_set:
return nums[i]
else:
num_set.add(nums[i])
return no_duplicate | find_first_duplicate | easy | [{"input": "[1, 1, 2, 3, 3, 2, 2]", "output": "1", "testtype": "functional"}] |
Mbpp_23 | Write a python function to find the maximum sum of elements of list in a list of lists. | 23 | mbpp | 0 | 2024-11-26T21:40:54.086000 | def maximum_Sum(list1):
maxi = -100000
for x in list1:
sum = 0
for y in x:
sum+= y
maxi = max(sum,maxi)
return maxi | maximum_Sum | easy | [{"input": "[[1,2,3],[4,5,6],[10,11,12],[7,8,9]]", "output": "33", "testtype": "functional"}] |
Mbpp_23 | Write a python function to find the maximum sum of elements of list in a list of lists. | 23 | mbpp | 1 | 2024-11-26T21:40:54.086000 | def maximum_Sum(list1):
maxi = -100000
for x in list1:
sum = 0
for y in x:
sum+= y
maxi = max(sum,maxi)
return maxi | maximum_Sum | easy | [{"input": "[[0,1,1],[1,1,2],[3,2,1]]", "output": "6", "testtype": "functional"}] |
Mbpp_23 | Write a python function to find the maximum sum of elements of list in a list of lists. | 23 | mbpp | 2 | 2024-11-26T21:40:54.086000 | def maximum_Sum(list1):
maxi = -100000
for x in list1:
sum = 0
for y in x:
sum+= y
maxi = max(sum,maxi)
return maxi | maximum_Sum | easy | [{"input": "[[0,1,3],[1,2,1],[9,8,2],[0,1,0],[6,4,8]]", "output": "19", "testtype": "functional"}] |
Mbpp_23 | Write a python function to find the maximum sum of elements of list in a list of lists. | 23 | mbpp | 3 | 2024-11-26T21:40:54.086000 | def maximum_Sum(list1):
maxi = -100000
for x in list1:
sum = 0
for y in x:
sum+= y
maxi = max(sum,maxi)
return maxi | maximum_Sum | easy | [{"input": "[[0,-1,-1],[-1,-1,-2],[-3,-2,-1]]", "output": "-2", "testtype": "functional"}] |
Mbpp_24 | Write a function to convert the given binary number to its decimal equivalent. | 24 | mbpp | 0 | 2024-11-26T21:40:54.087000 | def binary_to_decimal(binary):
binary1 = binary
decimal, i, n = 0, 0, 0
while(binary != 0):
dec = binary % 10
decimal = decimal + dec * pow(2, i)
binary = binary//10
i += 1
return (decimal) | binary_to_decimal | easy | [{"input": "100", "output": "4", "testtype": "functional"}] |
Mbpp_24 | Write a function to convert the given binary number to its decimal equivalent. | 24 | mbpp | 1 | 2024-11-26T21:40:54.087000 | def binary_to_decimal(binary):
binary1 = binary
decimal, i, n = 0, 0, 0
while(binary != 0):
dec = binary % 10
decimal = decimal + dec * pow(2, i)
binary = binary//10
i += 1
return (decimal) | binary_to_decimal | easy | [{"input": "1011", "output": "11", "testtype": "functional"}] |
Mbpp_24 | Write a function to convert the given binary number to its decimal equivalent. | 24 | mbpp | 2 | 2024-11-26T21:40:54.088000 | def binary_to_decimal(binary):
binary1 = binary
decimal, i, n = 0, 0, 0
while(binary != 0):
dec = binary % 10
decimal = decimal + dec * pow(2, i)
binary = binary//10
i += 1
return (decimal) | binary_to_decimal | easy | [{"input": "1101101", "output": "109", "testtype": "functional"}] |
Mbpp_25 | Write a python function to find the product of non-repeated elements in a given array. | 25 | mbpp | 0 | 2024-11-26T21:40:54.088000 | def find_Product(arr,n):
arr.sort()
prod = 1
for i in range(0,n,1):
if (arr[i - 1] != arr[i]):
prod = prod * arr[i]
return prod; | find_Product | easy | [{"input": "[1,1,2,3],4", "output": "6", "testtype": "functional"}] |
Mbpp_25 | Write a python function to find the product of non-repeated elements in a given array. | 25 | mbpp | 1 | 2024-11-26T21:40:54.088000 | def find_Product(arr,n):
arr.sort()
prod = 1
for i in range(0,n,1):
if (arr[i - 1] != arr[i]):
prod = prod * arr[i]
return prod; | find_Product | easy | [{"input": "[1,2,3,1,1],5", "output": "6", "testtype": "functional"}] |
Mbpp_25 | Write a python function to find the product of non-repeated elements in a given array. | 25 | mbpp | 2 | 2024-11-26T21:40:54.089000 | def find_Product(arr,n):
arr.sort()
prod = 1
for i in range(0,n,1):
if (arr[i - 1] != arr[i]):
prod = prod * arr[i]
return prod; | find_Product | easy | [{"input": "[1,1,4,5,6],5", "output": "120", "testtype": "functional"}] |
Mbpp_25 | Write a python function to find the product of non-repeated elements in a given array. | 25 | mbpp | 3 | 2024-11-26T21:40:54.089000 | def find_Product(arr,n):
arr.sort()
prod = 1
for i in range(0,n,1):
if (arr[i - 1] != arr[i]):
prod = prod * arr[i]
return prod; | find_Product | easy | [{"input": "[1,1,4,5,6,5,7,1,1,3,4],11", "output": "2520", "testtype": "functional"}] |
Mbpp_26 | Write a function to check if the given tuple list has all k elements. | 26 | mbpp | 0 | 2024-11-26T21:40:54.089000 | def check_k_elements(test_list, K):
res = True
for tup in test_list:
for ele in tup:
if ele != K:
res = False
return (res) | check_k_elements | easy | [{"input": "[(4, 4), (4, 4, 4), (4, 4), (4, 4, 4, 4), (4, )], 4", "output": "True", "testtype": "functional"}] |
Mbpp_26 | Write a function to check if the given tuple list has all k elements. | 26 | mbpp | 1 | 2024-11-26T21:40:54.089000 | def check_k_elements(test_list, K):
res = True
for tup in test_list:
for ele in tup:
if ele != K:
res = False
return (res) | check_k_elements | easy | [{"input": "[(7, 7, 7), (7, 7)], 7", "output": "True", "testtype": "functional"}] |
Mbpp_26 | Write a function to check if the given tuple list has all k elements. | 26 | mbpp | 2 | 2024-11-26T21:40:54.089000 | def check_k_elements(test_list, K):
res = True
for tup in test_list:
for ele in tup:
if ele != K:
res = False
return (res) | check_k_elements | easy | [{"input": "[(9, 9), (9, 9, 9, 9)], 7", "output": "False", "testtype": "functional"}] |
Mbpp_26 | Write a function to check if the given tuple list has all k elements. | 26 | mbpp | 3 | 2024-11-26T21:40:54.089000 | def check_k_elements(test_list, K):
res = True
for tup in test_list:
for ele in tup:
if ele != K:
res = False
return (res) | check_k_elements | easy | [{"input": "[(4, 4), (4, 4, 4), (4, 4), (4, 4, 6, 4), (4, )], 4", "output": "False", "testtype": "functional"}] |
Mbpp_27 | Write a python function to remove all digits from a list of strings. | 27 | mbpp | 0 | 2024-11-26T21:40:54.090000 | import re
def remove(list):
pattern = '[0-9]'
list = [re.sub(pattern, '', i) for i in list]
return list | remove | easy | [{"input": "['4words', '3letters', '4digits']", "output": "['words', 'letters', 'digits']", "testtype": "functional"}] |
Mbpp_27 | Write a python function to remove all digits from a list of strings. | 27 | mbpp | 1 | 2024-11-26T21:40:54.090000 | import re
def remove(list):
pattern = '[0-9]'
list = [re.sub(pattern, '', i) for i in list]
return list | remove | easy | [{"input": "['28Jan','12Jan','11Jan']", "output": "['Jan','Jan','Jan']", "testtype": "functional"}] |
Mbpp_27 | Write a python function to remove all digits from a list of strings. | 27 | mbpp | 2 | 2024-11-26T21:40:54.090000 | import re
def remove(list):
pattern = '[0-9]'
list = [re.sub(pattern, '', i) for i in list]
return list | remove | easy | [{"input": "['wonder1','wonder2','wonder3']", "output": "['wonder','wonder','wonder']", "testtype": "functional"}] |
Mbpp_28 | Write a python function to find binomial co-efficient. | 28 | mbpp | 0 | 2024-11-26T21:40:54.090000 | def binomial_Coeff(n,k):
if k > n :
return 0
if k==0 or k ==n :
return 1
return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k) | binomial_Coeff | easy | [{"input": "5,2", "output": "10", "testtype": "functional"}] |
Mbpp_28 | Write a python function to find binomial co-efficient. | 28 | mbpp | 1 | 2024-11-26T21:40:54.090000 | def binomial_Coeff(n,k):
if k > n :
return 0
if k==0 or k ==n :
return 1
return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k) | binomial_Coeff | easy | [{"input": "4,3", "output": "4", "testtype": "functional"}] |
Mbpp_28 | Write a python function to find binomial co-efficient. | 28 | mbpp | 2 | 2024-11-26T21:40:54.091000 | def binomial_Coeff(n,k):
if k > n :
return 0
if k==0 or k ==n :
return 1
return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k) | binomial_Coeff | easy | [{"input": "3,2", "output": "3", "testtype": "functional"}] |
Mbpp_28 | Write a python function to find binomial co-efficient. | 28 | mbpp | 3 | 2024-11-26T21:40:54.091000 | def binomial_Coeff(n,k):
if k > n :
return 0
if k==0 or k ==n :
return 1
return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k) | binomial_Coeff | easy | [{"input": "14,6", "output": "3003", "testtype": "functional"}] |
Mbpp_29 | Write a python function to find the element occurring odd number of times. | 29 | mbpp | 0 | 2024-11-26T21:40:54.091000 | def get_Odd_Occurrence(arr,arr_size):
for i in range(0,arr_size):
count = 0
for j in range(0,arr_size):
if arr[i] == arr[j]:
count+=1
if (count % 2 != 0):
return arr[i]
return -1 | get_Odd_Occurrence | easy | [{"input": "[1,2,3,1,2,3,1],7", "output": "1", "testtype": "functional"}] |
Mbpp_29 | Write a python function to find the element occurring odd number of times. | 29 | mbpp | 1 | 2024-11-26T21:40:54.092000 | def get_Odd_Occurrence(arr,arr_size):
for i in range(0,arr_size):
count = 0
for j in range(0,arr_size):
if arr[i] == arr[j]:
count+=1
if (count % 2 != 0):
return arr[i]
return -1 | get_Odd_Occurrence | easy | [{"input": "[1,2,3,2,3,1,3],7", "output": "3", "testtype": "functional"}] |
Mbpp_29 | Write a python function to find the element occurring odd number of times. | 29 | mbpp | 2 | 2024-11-26T21:40:54.092000 | def get_Odd_Occurrence(arr,arr_size):
for i in range(0,arr_size):
count = 0
for j in range(0,arr_size):
if arr[i] == arr[j]:
count+=1
if (count % 2 != 0):
return arr[i]
return -1 | get_Odd_Occurrence | easy | [{"input": "[2,3,5,4,5,2,4,3,5,2,4,4,2],13", "output": "5", "testtype": "functional"}] |
Mbpp_31 | Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm. | 31 | mbpp | 0 | 2024-11-26T21:40:54.093000 | def func(nums, k):
import collections
d = collections.defaultdict(int)
for row in nums:
for i in row:
d[i] += 1
temp = []
import heapq
for key, v in d.items():
if len(temp) < k:
temp.append((v, key))
if len(temp) == k:
heapq.heapify(temp)
else:
if v > temp[0][0]:
heapq.heappop(temp)
heapq.heappush(temp, (v, key))
result = []
while temp:
v, key = heapq.heappop(temp)
result.append(key)
return result | func | easy | [{"input": "[[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],3", "output": "[5, 7, 1]", "testtype": "functional"}] |
Mbpp_31 | Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm. | 31 | mbpp | 1 | 2024-11-26T21:40:54.094000 | def func(nums, k):
import collections
d = collections.defaultdict(int)
for row in nums:
for i in row:
d[i] += 1
temp = []
import heapq
for key, v in d.items():
if len(temp) < k:
temp.append((v, key))
if len(temp) == k:
heapq.heapify(temp)
else:
if v > temp[0][0]:
heapq.heappop(temp)
heapq.heappush(temp, (v, key))
result = []
while temp:
v, key = heapq.heappop(temp)
result.append(key)
return result | func | easy | [{"input": "[[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],1", "output": "[1]", "testtype": "functional"}] |
Mbpp_31 | Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm. | 31 | mbpp | 2 | 2024-11-26T21:40:54.094000 | def func(nums, k):
import collections
d = collections.defaultdict(int)
for row in nums:
for i in row:
d[i] += 1
temp = []
import heapq
for key, v in d.items():
if len(temp) < k:
temp.append((v, key))
if len(temp) == k:
heapq.heapify(temp)
else:
if v > temp[0][0]:
heapq.heappop(temp)
heapq.heappush(temp, (v, key))
result = []
while temp:
v, key = heapq.heappop(temp)
result.append(key)
return result | func | easy | [{"input": "[[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],5", "output": "[6, 5, 7, 8, 1]", "testtype": "functional"}] |
Mbpp_32 | Write a python function to find the largest prime factor of a given number. | 32 | mbpp | 0 | 2024-11-26T21:40:54.095000 | import math
def max_Prime_Factors (n):
maxPrime = -1
while n%2 == 0:
maxPrime = 2
n >>= 1
for i in range(3,int(math.sqrt(n))+1,2):
while n % i == 0:
maxPrime = i
n = n / i
if n > 2:
maxPrime = n
return int(maxPrime) | max_Prime_Factors | easy | [{"input": "15", "output": "5", "testtype": "functional"}] |
Mbpp_32 | Write a python function to find the largest prime factor of a given number. | 32 | mbpp | 1 | 2024-11-26T21:40:54.095000 | import math
def max_Prime_Factors (n):
maxPrime = -1
while n%2 == 0:
maxPrime = 2
n >>= 1
for i in range(3,int(math.sqrt(n))+1,2):
while n % i == 0:
maxPrime = i
n = n / i
if n > 2:
maxPrime = n
return int(maxPrime) | max_Prime_Factors | easy | [{"input": "6", "output": "3", "testtype": "functional"}] |
Mbpp_32 | Write a python function to find the largest prime factor of a given number. | 32 | mbpp | 2 | 2024-11-26T21:40:54.095000 | import math
def max_Prime_Factors (n):
maxPrime = -1
while n%2 == 0:
maxPrime = 2
n >>= 1
for i in range(3,int(math.sqrt(n))+1,2):
while n % i == 0:
maxPrime = i
n = n / i
if n > 2:
maxPrime = n
return int(maxPrime) | max_Prime_Factors | easy | [{"input": "2", "output": "2", "testtype": "functional"}] |
Mbpp_33 | Write a python function to convert a decimal number to binary number. | 33 | mbpp | 0 | 2024-11-26T21:40:54.096000 | def decimal_To_Binary(N):
B_Number = 0
cnt = 0
while (N != 0):
rem = N % 2
c = pow(10,cnt)
B_Number += rem*c
N //= 2
cnt += 1
return B_Number | decimal_To_Binary | easy | [{"input": "10", "output": "1010", "testtype": "functional"}] |
Mbpp_33 | Write a python function to convert a decimal number to binary number. | 33 | mbpp | 1 | 2024-11-26T21:40:54.096000 | def decimal_To_Binary(N):
B_Number = 0
cnt = 0
while (N != 0):
rem = N % 2
c = pow(10,cnt)
B_Number += rem*c
N //= 2
cnt += 1
return B_Number | decimal_To_Binary | easy | [{"input": "1", "output": "1", "testtype": "functional"}] |
Mbpp_33 | Write a python function to convert a decimal number to binary number. | 33 | mbpp | 2 | 2024-11-26T21:40:54.096000 | def decimal_To_Binary(N):
B_Number = 0
cnt = 0
while (N != 0):
rem = N % 2
c = pow(10,cnt)
B_Number += rem*c
N //= 2
cnt += 1
return B_Number | decimal_To_Binary | easy | [{"input": "20", "output": "10100", "testtype": "functional"}] |
Mbpp_34 | Write a python function to find the missing number in a sorted array. | 34 | mbpp | 0 | 2024-11-26T21:40:54.096000 | def find_missing(ar,N):
l = 0
r = N - 1
while (l <= r):
mid = (l + r) / 2
mid= int (mid)
if (ar[mid] != mid + 1 and ar[mid - 1] == mid):
return (mid + 1)
elif (ar[mid] != mid + 1):
r = mid - 1
else:
l = mid + 1
return (-1) | find_missing | easy | [{"input": "[1,2,3,5],4", "output": "4", "testtype": "functional"}] |
Mbpp_34 | Write a python function to find the missing number in a sorted array. | 34 | mbpp | 1 | 2024-11-26T21:40:54.097000 | def find_missing(ar,N):
l = 0
r = N - 1
while (l <= r):
mid = (l + r) / 2
mid= int (mid)
if (ar[mid] != mid + 1 and ar[mid - 1] == mid):
return (mid + 1)
elif (ar[mid] != mid + 1):
r = mid - 1
else:
l = mid + 1
return (-1) | find_missing | easy | [{"input": "[1,3,4,5],4", "output": "2", "testtype": "functional"}] |
Mbpp_34 | Write a python function to find the missing number in a sorted array. | 34 | mbpp | 2 | 2024-11-26T21:40:54.097000 | def find_missing(ar,N):
l = 0
r = N - 1
while (l <= r):
mid = (l + r) / 2
mid= int (mid)
if (ar[mid] != mid + 1 and ar[mid - 1] == mid):
return (mid + 1)
elif (ar[mid] != mid + 1):
r = mid - 1
else:
l = mid + 1
return (-1) | find_missing | easy | [{"input": "[1,2,3,5,6,7],5", "output": "4", "testtype": "functional"}] |
Mbpp_35 | Write a function to find the n-th rectangular number. | 35 | mbpp | 0 | 2024-11-26T21:40:54.097000 | def find_rect_num(n):
return n*(n + 1) | find_rect_num | easy | [{"input": "4", "output": "20", "testtype": "functional"}] |
Mbpp_35 | Write a function to find the n-th rectangular number. | 35 | mbpp | 1 | 2024-11-26T21:40:54.098000 | def find_rect_num(n):
return n*(n + 1) | find_rect_num | easy | [{"input": "5", "output": "30", "testtype": "functional"}] |
Mbpp_35 | Write a function to find the n-th rectangular number. | 35 | mbpp | 2 | 2024-11-26T21:40:54.098000 | def find_rect_num(n):
return n*(n + 1) | find_rect_num | easy | [{"input": "6", "output": "42", "testtype": "functional"}] |
Mbpp_36 | Write a python function to find the nth digit in the proper fraction of two given numbers. | 36 | mbpp | 0 | 2024-11-26T21:40:54.098000 | def find_Nth_Digit(p,q,N) :
while (N > 0) :
N -= 1;
p *= 10;
res = p // q;
p %= q;
return res; | find_Nth_Digit | easy | [{"input": "1,2,1", "output": "5", "testtype": "functional"}] |
Mbpp_36 | Write a python function to find the nth digit in the proper fraction of two given numbers. | 36 | mbpp | 1 | 2024-11-26T21:40:54.098000 | def find_Nth_Digit(p,q,N) :
while (N > 0) :
N -= 1;
p *= 10;
res = p // q;
p %= q;
return res; | find_Nth_Digit | easy | [{"input": "3,5,1", "output": "6", "testtype": "functional"}] |
Mbpp_36 | Write a python function to find the nth digit in the proper fraction of two given numbers. | 36 | mbpp | 2 | 2024-11-26T21:40:54.098000 | def find_Nth_Digit(p,q,N) :
while (N > 0) :
N -= 1;
p *= 10;
res = p // q;
p %= q;
return res; | find_Nth_Digit | easy | [{"input": "5,6,5", "output": "3", "testtype": "functional"}] |
Mbpp_37 | Write a function to sort a given mixed list of integers and strings. | 37 | mbpp | 0 | 2024-11-26T21:40:54.099000 | def sort_mixed_list(mixed_list):
int_part = sorted([i for i in mixed_list if type(i) is int])
str_part = sorted([i for i in mixed_list if type(i) is str])
return int_part + str_part | sort_mixed_list | easy | [{"input": "[19,'red',12,'green','blue', 10,'white','green',1]", "output": "[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']", "testtype": "functional"}] |
Mbpp_37 | Write a function to sort a given mixed list of integers and strings. | 37 | mbpp | 1 | 2024-11-26T21:40:54.099000 | def sort_mixed_list(mixed_list):
int_part = sorted([i for i in mixed_list if type(i) is int])
str_part = sorted([i for i in mixed_list if type(i) is str])
return int_part + str_part | sort_mixed_list | easy | [{"input": "[19,'red',12,'green','blue', 10,'white','green',1]", "output": "[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']", "testtype": "functional"}] |
Mbpp_37 | Write a function to sort a given mixed list of integers and strings. | 37 | mbpp | 2 | 2024-11-26T21:40:54.099000 | def sort_mixed_list(mixed_list):
int_part = sorted([i for i in mixed_list if type(i) is int])
str_part = sorted([i for i in mixed_list if type(i) is str])
return int_part + str_part | sort_mixed_list | easy | [{"input": "[19,'red',12,'green','blue', 10,'white','green',1]", "output": "[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']", "testtype": "functional"}] |
Mbpp_38 | Write a function to find the division of first even and odd number of a given list. | 38 | mbpp | 0 | 2024-11-26T21:40:54.100000 | def div_even_odd(list1):
first_even = next((el for el in list1 if el%2==0),-1)
first_odd = next((el for el in list1 if el%2!=0),-1)
return (first_even/first_odd) | div_even_odd | easy | [{"input": "[1,3,5,7,4,1,6,8]", "output": "4", "testtype": "functional"}] |
Mbpp_38 | Write a function to find the division of first even and odd number of a given list. | 38 | mbpp | 1 | 2024-11-26T21:40:54.100000 | def div_even_odd(list1):
first_even = next((el for el in list1 if el%2==0),-1)
first_odd = next((el for el in list1 if el%2!=0),-1)
return (first_even/first_odd) | div_even_odd | easy | [{"input": "[1,2,3,4,5,6,7,8,9,10]", "output": "2", "testtype": "functional"}] |
Mbpp_38 | Write a function to find the division of first even and odd number of a given list. | 38 | mbpp | 2 | 2024-11-26T21:40:54.100000 | def div_even_odd(list1):
first_even = next((el for el in list1 if el%2==0),-1)
first_odd = next((el for el in list1 if el%2!=0),-1)
return (first_even/first_odd) | div_even_odd | easy | [{"input": "[1,5,7,9,10]", "output": "10", "testtype": "functional"}] |
Mbpp_39 | Write a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different. | 39 | mbpp | 0 | 2024-11-26T21:40:54.101000 | import heapq
from collections import Counter
def rearange_string(S):
ctr = Counter(S)
heap = [(-value, key) for key, value in ctr.items()]
heapq.heapify(heap)
if (-heap[0][0]) * 2 > len(S) + 1:
return ""
ans = []
while len(heap) >= 2:
nct1, char1 = heapq.heappop(heap)
nct2, char2 = heapq.heappop(heap)
ans.extend([char1, char2])
if nct1 + 1: heapq.heappush(heap, (nct1 + 1, char1))
if nct2 + 1: heapq.heappush(heap, (nct2 + 1, char2))
return "".join(ans) + (heap[0][1] if heap else "") | rearange_string | easy | [{"input": "\"aab\"", "output": "('aba')", "testtype": "functional"}] |
Mbpp_39 | Write a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different. | 39 | mbpp | 1 | 2024-11-26T21:40:54.102000 | import heapq
from collections import Counter
def rearange_string(S):
ctr = Counter(S)
heap = [(-value, key) for key, value in ctr.items()]
heapq.heapify(heap)
if (-heap[0][0]) * 2 > len(S) + 1:
return ""
ans = []
while len(heap) >= 2:
nct1, char1 = heapq.heappop(heap)
nct2, char2 = heapq.heappop(heap)
ans.extend([char1, char2])
if nct1 + 1: heapq.heappush(heap, (nct1 + 1, char1))
if nct2 + 1: heapq.heappush(heap, (nct2 + 1, char2))
return "".join(ans) + (heap[0][1] if heap else "") | rearange_string | easy | [{"input": "\"aabb\"", "output": "('abab')", "testtype": "functional"}] |
Mbpp_39 | Write a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different. | 39 | mbpp | 2 | 2024-11-26T21:40:54.103000 | import heapq
from collections import Counter
def rearange_string(S):
ctr = Counter(S)
heap = [(-value, key) for key, value in ctr.items()]
heapq.heapify(heap)
if (-heap[0][0]) * 2 > len(S) + 1:
return ""
ans = []
while len(heap) >= 2:
nct1, char1 = heapq.heappop(heap)
nct2, char2 = heapq.heappop(heap)
ans.extend([char1, char2])
if nct1 + 1: heapq.heappush(heap, (nct1 + 1, char1))
if nct2 + 1: heapq.heappush(heap, (nct2 + 1, char2))
return "".join(ans) + (heap[0][1] if heap else "") | rearange_string | easy | [{"input": "\"abccdd\"", "output": "('cdabcd')", "testtype": "functional"}] |
Mbpp_40 | Write a function to find frequency of the elements in a given list of lists using collections module. | 40 | mbpp | 0 | 2024-11-26T21:40:54.104000 | from collections import Counter
from itertools import chain
def freq_element(nums):
result = Counter(chain.from_iterable(nums))
return result | freq_element | easy | [{"input": "[[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]]", "output": "({2: 3, 1: 2, 5: 2, 3: 1, 4: 1, 6: 1, 7: 1, 9: 1})", "testtype": "functional"}] |
Mbpp_40 | Write a function to find frequency of the elements in a given list of lists using collections module. | 40 | mbpp | 1 | 2024-11-26T21:40:54.104000 | from collections import Counter
from itertools import chain
def freq_element(nums):
result = Counter(chain.from_iterable(nums))
return result | freq_element | easy | [{"input": "[[1,2,3,4],[5,6,7,8],[9,10,11,12]]", "output": "({1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1, 12: 1})", "testtype": "functional"}] |
Mbpp_40 | Write a function to find frequency of the elements in a given list of lists using collections module. | 40 | mbpp | 2 | 2024-11-26T21:40:54.104000 | from collections import Counter
from itertools import chain
def freq_element(nums):
result = Counter(chain.from_iterable(nums))
return result | freq_element | easy | [{"input": "[[15,20,30,40],[80,90,100,110],[30,30,80,90]]", "output": "({30: 3, 80: 2, 90: 2, 15: 1, 20: 1, 40: 1, 100: 1, 110: 1})", "testtype": "functional"}] |
Mbpp_41 | Write a function to filter even numbers using lambda function. | 41 | mbpp | 0 | 2024-11-26T21:40:54.104000 | def filter_evennumbers(nums):
even_nums = list(filter(lambda x: x%2 == 0, nums))
return even_nums | filter_evennumbers | easy | [{"input": "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]", "output": "[2, 4, 6, 8, 10]", "testtype": "functional"}] |
Mbpp_41 | Write a function to filter even numbers using lambda function. | 41 | mbpp | 1 | 2024-11-26T21:40:54.104000 | def filter_evennumbers(nums):
even_nums = list(filter(lambda x: x%2 == 0, nums))
return even_nums | filter_evennumbers | easy | [{"input": "[10,20,45,67,84,93]", "output": "[10,20,84]", "testtype": "functional"}] |
Mbpp_41 | Write a function to filter even numbers using lambda function. | 41 | mbpp | 2 | 2024-11-26T21:40:54.104000 | def filter_evennumbers(nums):
even_nums = list(filter(lambda x: x%2 == 0, nums))
return even_nums | filter_evennumbers | easy | [{"input": "[5,7,9,8,6,4,3]", "output": "[8,6,4]", "testtype": "functional"}] |
Mbpp_42 | Write a python function to find the sum of repeated elements in a given array. | 42 | mbpp | 0 | 2024-11-26T21:40:54.105000 | def find_Sum(arr,n):
return sum([x for x in arr if arr.count(x) > 1]) | find_Sum | easy | [{"input": "[1,2,3,1,1,4,5,6],8", "output": "3", "testtype": "functional"}] |
Mbpp_42 | Write a python function to find the sum of repeated elements in a given array. | 42 | mbpp | 1 | 2024-11-26T21:40:54.105000 | def find_Sum(arr,n):
return sum([x for x in arr if arr.count(x) > 1]) | find_Sum | easy | [{"input": "[1,2,3,1,1],5", "output": "3", "testtype": "functional"}] |
Mbpp_42 | Write a python function to find the sum of repeated elements in a given array. | 42 | mbpp | 2 | 2024-11-26T21:40:54.105000 | def find_Sum(arr,n):
return sum([x for x in arr if arr.count(x) > 1]) | find_Sum | easy | [{"input": "[1,1,2],3", "output": "2", "testtype": "functional"}] |
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
- Downloads last month
- 313