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_111 | Write a function to find common elements in given nested lists. * list item * list item * list item * list item | 111 | mbpp | 0 | 2024-11-26T21:40:54.156894 | def common_in_nested_lists(nestedlist):
result = list(set.intersection(*map(set, nestedlist)))
return result | common_in_nested_lists | easy | [{"input": "[[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]]", "output": "[18, 12]", "testtype": "functional"}] |
Mbpp_111 | Write a function to find common elements in given nested lists. * list item * list item * list item * list item | 111 | mbpp | 1 | 2024-11-26T21:40:54.157043 | def common_in_nested_lists(nestedlist):
result = list(set.intersection(*map(set, nestedlist)))
return result | common_in_nested_lists | easy | [{"input": "[[12, 5, 23, 25, 45], [7, 11, 5, 23, 28], [1, 5, 8, 18, 23, 16]]", "output": "[5,23]", "testtype": "functional"}] |
Mbpp_111 | Write a function to find common elements in given nested lists. * list item * list item * list item * list item | 111 | mbpp | 2 | 2024-11-26T21:40:54.157194 | def common_in_nested_lists(nestedlist):
result = list(set.intersection(*map(set, nestedlist)))
return result | common_in_nested_lists | easy | [{"input": "[[2, 3,4, 1], [4, 5], [6,4, 8],[4, 5], [6, 8,4]]", "output": "[4]", "testtype": "functional"}] |
Mbpp_112 | Write a python function to find the perimeter of a cylinder. | 112 | mbpp | 0 | 2024-11-26T21:40:54.157305 | def perimeter(diameter,height) :
return 2*(diameter+height) | perimeter | easy | [{"input": "2,4", "output": "12", "testtype": "functional"}] |
Mbpp_112 | Write a python function to find the perimeter of a cylinder. | 112 | mbpp | 1 | 2024-11-26T21:40:54.157397 | def perimeter(diameter,height) :
return 2*(diameter+height) | perimeter | easy | [{"input": "1,2", "output": "6", "testtype": "functional"}] |
Mbpp_112 | Write a python function to find the perimeter of a cylinder. | 112 | mbpp | 2 | 2024-11-26T21:40:54.157488 | def perimeter(diameter,height) :
return 2*(diameter+height) | perimeter | easy | [{"input": "3,1", "output": "8", "testtype": "functional"}] |
Mbpp_113 | Write a function to check if a string represents an integer or not. | 113 | mbpp | 0 | 2024-11-26T21:40:54.157907 | def check_integer(text):
text = text.strip()
if len(text) < 1:
return None
else:
if all(text[i] in "0123456789" for i in range(len(text))):
return True
elif (text[0] in "+-") and \
all(text[i] in "0123456789" for i in range(1,len(text))):
return True
else:
return False | check_integer | easy | [{"input": "\"python\"", "output": "False", "testtype": "functional"}] |
Mbpp_113 | Write a function to check if a string represents an integer or not. | 113 | mbpp | 1 | 2024-11-26T21:40:54.158297 | def check_integer(text):
text = text.strip()
if len(text) < 1:
return None
else:
if all(text[i] in "0123456789" for i in range(len(text))):
return True
elif (text[0] in "+-") and \
all(text[i] in "0123456789" for i in range(1,len(text))):
return True
else:
return False | check_integer | easy | [{"input": "\"1\"", "output": "True", "testtype": "functional"}] |
Mbpp_113 | Write a function to check if a string represents an integer or not. | 113 | mbpp | 2 | 2024-11-26T21:40:54.158711 | def check_integer(text):
text = text.strip()
if len(text) < 1:
return None
else:
if all(text[i] in "0123456789" for i in range(len(text))):
return True
elif (text[0] in "+-") and \
all(text[i] in "0123456789" for i in range(1,len(text))):
return True
else:
return False | check_integer | easy | [{"input": "\"12345\"", "output": "True", "testtype": "functional"}] |
Mbpp_114 | Write a function to assign frequency to each tuple in the given tuple list. | 114 | mbpp | 0 | 2024-11-26T21:40:54.158952 | from collections import Counter
def assign_freq(test_list):
res = [(*key, val) for key, val in Counter(test_list).items()]
return (str(res)) | assign_freq | easy | [{"input": "[(6, 5, 8), (2, 7), (6, 5, 8), (6, 5, 8), (9, ), (2, 7)] ", "output": "'[(6, 5, 8, 3), (2, 7, 2), (9, 1)]'", "testtype": "functional"}] |
Mbpp_114 | Write a function to assign frequency to each tuple in the given tuple list. | 114 | mbpp | 1 | 2024-11-26T21:40:54.159158 | from collections import Counter
def assign_freq(test_list):
res = [(*key, val) for key, val in Counter(test_list).items()]
return (str(res)) | assign_freq | easy | [{"input": "[(4, 2, 4), (7, 1), (4, 8), (4, 2, 4), (9, 2), (7, 1)] ", "output": "'[(4, 2, 4, 2), (7, 1, 2), (4, 8, 1), (9, 2, 1)]'", "testtype": "functional"}] |
Mbpp_114 | Write a function to assign frequency to each tuple in the given tuple list. | 114 | mbpp | 2 | 2024-11-26T21:40:54.159362 | from collections import Counter
def assign_freq(test_list):
res = [(*key, val) for key, val in Counter(test_list).items()]
return (str(res)) | assign_freq | easy | [{"input": "[(11, 13, 10), (17, 21), (4, 2, 3), (17, 21), (9, 2), (4, 2, 3)] ", "output": "'[(11, 13, 10, 1), (17, 21, 2), (4, 2, 3, 2), (9, 2, 1)]'", "testtype": "functional"}] |
Mbpp_115 | Write a function to check whether all dictionaries in a list are empty or not. | 115 | mbpp | 0 | 2024-11-26T21:40:54.159507 | def empty_dit(list1):
empty_dit=all(not d for d in list1)
return empty_dit | empty_dit | easy | [{"input": "[{},{},{}]", "output": "True", "testtype": "functional"}] |
Mbpp_115 | Write a function to check whether all dictionaries in a list are empty or not. | 115 | mbpp | 1 | 2024-11-26T21:40:54.159627 | def empty_dit(list1):
empty_dit=all(not d for d in list1)
return empty_dit | empty_dit | easy | [{"input": "[{1,2},{},{}]", "output": "False", "testtype": "functional"}] |
Mbpp_115 | Write a function to check whether all dictionaries in a list are empty or not. | 115 | mbpp | 2 | 2024-11-26T21:40:54.159765 | def empty_dit(list1):
empty_dit=all(not d for d in list1)
return empty_dit | empty_dit | easy | [{"input": "{}", "output": "True", "testtype": "functional"}] |
Mbpp_116 | Write a function to convert a given tuple of positive integers into an integer. | 116 | mbpp | 0 | 2024-11-26T21:40:54.159905 | def tuple_to_int(nums):
result = int(''.join(map(str,nums)))
return result | tuple_to_int | easy | [{"input": "(1,2,3)", "output": "123", "testtype": "functional"}] |
Mbpp_116 | Write a function to convert a given tuple of positive integers into an integer. | 116 | mbpp | 1 | 2024-11-26T21:40:54.160027 | def tuple_to_int(nums):
result = int(''.join(map(str,nums)))
return result | tuple_to_int | easy | [{"input": "(4,5,6)", "output": "456", "testtype": "functional"}] |
Mbpp_116 | Write a function to convert a given tuple of positive integers into an integer. | 116 | mbpp | 2 | 2024-11-26T21:40:54.160163 | def tuple_to_int(nums):
result = int(''.join(map(str,nums)))
return result | tuple_to_int | easy | [{"input": "(5,6,7)", "output": "567", "testtype": "functional"}] |
Mbpp_117 | Write a function to convert all possible convertible elements in the list to float. | 117 | mbpp | 0 | 2024-11-26T21:40:54.160670 | def list_to_float(test_list):
res = []
for tup in test_list:
temp = []
for ele in tup:
if ele.isalpha():
temp.append(ele)
else:
temp.append(float(ele))
res.append((temp[0],temp[1]))
return (str(res)) | list_to_float | easy | [{"input": " [(\"3\", \"4\"), (\"1\", \"26.45\"), (\"7.32\", \"8\"), (\"4\", \"8\")] ", "output": "'[(3.0, 4.0), (1.0, 26.45), (7.32, 8.0), (4.0, 8.0)]'", "testtype": "functional"}] |
Mbpp_117 | Write a function to convert all possible convertible elements in the list to float. | 117 | mbpp | 1 | 2024-11-26T21:40:54.161076 | def list_to_float(test_list):
res = []
for tup in test_list:
temp = []
for ele in tup:
if ele.isalpha():
temp.append(ele)
else:
temp.append(float(ele))
res.append((temp[0],temp[1]))
return (str(res)) | list_to_float | easy | [{"input": " [(\"4\", \"4\"), (\"2\", \"27\"), (\"4.12\", \"9\"), (\"7\", \"11\")] ", "output": "'[(4.0, 4.0), (2.0, 27.0), (4.12, 9.0), (7.0, 11.0)]'", "testtype": "functional"}] |
Mbpp_117 | Write a function to convert all possible convertible elements in the list to float. | 117 | mbpp | 2 | 2024-11-26T21:40:54.161703 | def list_to_float(test_list):
res = []
for tup in test_list:
temp = []
for ele in tup:
if ele.isalpha():
temp.append(ele)
else:
temp.append(float(ele))
res.append((temp[0],temp[1]))
return (str(res)) | list_to_float | easy | [{"input": " [(\"6\", \"78\"), (\"5\", \"26.45\"), (\"1.33\", \"4\"), (\"82\", \"13\")] ", "output": "'[(6.0, 78.0), (5.0, 26.45), (1.33, 4.0), (82.0, 13.0)]'", "testtype": "functional"}] |
Mbpp_118 | [link text](https:// [link text](https:// [link text](https://)))write a function to convert a string to a list. | 118 | mbpp | 0 | 2024-11-26T21:40:54.161869 | def string_to_list(string):
lst = list(string.split(" "))
return lst | string_to_list | easy | [{"input": "\"python programming\"", "output": "['python','programming']", "testtype": "functional"}] |
Mbpp_118 | [link text](https:// [link text](https:// [link text](https://)))write a function to convert a string to a list. | 118 | mbpp | 1 | 2024-11-26T21:40:54.161987 | def string_to_list(string):
lst = list(string.split(" "))
return lst | string_to_list | easy | [{"input": "\"lists tuples strings\"", "output": "['lists','tuples','strings']", "testtype": "functional"}] |
Mbpp_118 | [link text](https:// [link text](https:// [link text](https://)))write a function to convert a string to a list. | 118 | mbpp | 2 | 2024-11-26T21:40:54.162107 | def string_to_list(string):
lst = list(string.split(" "))
return lst | string_to_list | easy | [{"input": "\"write a program\"", "output": "['write','a','program']", "testtype": "functional"}] |
Mbpp_119 | Write a python function to find the element that appears only once in a sorted array. | 119 | mbpp | 0 | 2024-11-26T21:40:54.162466 | def search(arr,n) :
XOR = 0
for i in range(n) :
XOR = XOR ^ arr[i]
return (XOR) | search | easy | [{"input": "[1,1,2,2,3],5", "output": "3", "testtype": "functional"}] |
Mbpp_119 | Write a python function to find the element that appears only once in a sorted array. | 119 | mbpp | 1 | 2024-11-26T21:40:54.164019 | def search(arr,n) :
XOR = 0
for i in range(n) :
XOR = XOR ^ arr[i]
return (XOR) | search | easy | [{"input": "[1,1,3,3,4,4,5,5,7,7,8],11", "output": "8", "testtype": "functional"}] |
Mbpp_119 | Write a python function to find the element that appears only once in a sorted array. | 119 | mbpp | 2 | 2024-11-26T21:40:54.164281 | def search(arr,n) :
XOR = 0
for i in range(n) :
XOR = XOR ^ arr[i]
return (XOR) | search | easy | [{"input": "[1,2,2,3,3,4,4],7", "output": "1", "testtype": "functional"}] |
Mbpp_120 | Write a function to find the maximum product from the pairs of tuples within a given list. | 120 | mbpp | 0 | 2024-11-26T21:40:54.164476 | def max_product_tuple(list1):
result_max = max([abs(x * y) for x, y in list1] )
return result_max | max_product_tuple | easy | [{"input": "[(2, 7), (2, 6), (1, 8), (4, 9)] ", "output": "36", "testtype": "functional"}] |
Mbpp_120 | Write a function to find the maximum product from the pairs of tuples within a given list. | 120 | mbpp | 1 | 2024-11-26T21:40:54.164658 | def max_product_tuple(list1):
result_max = max([abs(x * y) for x, y in list1] )
return result_max | max_product_tuple | easy | [{"input": "[(10,20), (15,2), (5,10)] ", "output": "200", "testtype": "functional"}] |
Mbpp_120 | Write a function to find the maximum product from the pairs of tuples within a given list. | 120 | mbpp | 2 | 2024-11-26T21:40:54.164826 | def max_product_tuple(list1):
result_max = max([abs(x * y) for x, y in list1] )
return result_max | max_product_tuple | easy | [{"input": "[(11,44), (10,15), (20,5), (12, 9)] ", "output": "484", "testtype": "functional"}] |
Mbpp_121 | Write a function to find the triplet with sum of the given array | 121 | mbpp | 0 | 2024-11-26T21:40:54.165256 | def check_triplet(A, n, sum, count):
if count == 3 and sum == 0:
return True
if count == 3 or n == 0 or sum < 0:
return False
return check_triplet(A, n - 1, sum - A[n - 1], count + 1) or\
check_triplet(A, n - 1, sum, count) | check_triplet | easy | [{"input": "[2, 7, 4, 0, 9, 5, 1, 3], 8, 6, 0", "output": "True", "testtype": "functional"}] |
Mbpp_121 | Write a function to find the triplet with sum of the given array | 121 | mbpp | 1 | 2024-11-26T21:40:54.165675 | def check_triplet(A, n, sum, count):
if count == 3 and sum == 0:
return True
if count == 3 or n == 0 or sum < 0:
return False
return check_triplet(A, n - 1, sum - A[n - 1], count + 1) or\
check_triplet(A, n - 1, sum, count) | check_triplet | easy | [{"input": "[1, 4, 5, 6, 7, 8, 5, 9], 8, 6, 0", "output": "False", "testtype": "functional"}] |
Mbpp_121 | Write a function to find the triplet with sum of the given array | 121 | mbpp | 2 | 2024-11-26T21:40:54.166022 | def check_triplet(A, n, sum, count):
if count == 3 and sum == 0:
return True
if count == 3 or n == 0 or sum < 0:
return False
return check_triplet(A, n - 1, sum - A[n - 1], count + 1) or\
check_triplet(A, n - 1, sum, count) | check_triplet | easy | [{"input": "[10, 4, 2, 3, 5], 5, 15, 0", "output": "True", "testtype": "functional"}] |
Mbpp_122 | Write a function to find n’th smart number. | 122 | mbpp | 0 | 2024-11-26T21:40:54.166538 | MAX = 3000
def smartNumber(n):
primes = [0] * MAX
result = []
for i in range(2, MAX):
if (primes[i] == 0):
primes[i] = 1
j = i * 2
while (j < MAX):
primes[j] -= 1
if ( (primes[j] + 3) == 0):
result.append(j)
j = j + i
result.sort()
return result[n - 1] | smartNumber | easy | [{"input": "1", "output": "30", "testtype": "functional"}] |
Mbpp_122 | Write a function to find n’th smart number. | 122 | mbpp | 1 | 2024-11-26T21:40:54.167222 | MAX = 3000
def smartNumber(n):
primes = [0] * MAX
result = []
for i in range(2, MAX):
if (primes[i] == 0):
primes[i] = 1
j = i * 2
while (j < MAX):
primes[j] -= 1
if ( (primes[j] + 3) == 0):
result.append(j)
j = j + i
result.sort()
return result[n - 1] | smartNumber | easy | [{"input": "50", "output": "273", "testtype": "functional"}] |
Mbpp_122 | Write a function to find n’th smart number. | 122 | mbpp | 2 | 2024-11-26T21:40:54.167985 | MAX = 3000
def smartNumber(n):
primes = [0] * MAX
result = []
for i in range(2, MAX):
if (primes[i] == 0):
primes[i] = 1
j = i * 2
while (j < MAX):
primes[j] -= 1
if ( (primes[j] + 3) == 0):
result.append(j)
j = j + i
result.sort()
return result[n - 1] | smartNumber | easy | [{"input": "1000", "output": "2664", "testtype": "functional"}] |
Mbpp_123 | Write a function to sum all amicable numbers from 1 to a specified number. | 123 | mbpp | 0 | 2024-11-26T21:40:54.168710 | def amicable_numbers_sum(limit):
if not isinstance(limit, int):
return "Input is not an integer!"
if limit < 1:
return "Input must be bigger than 0!"
amicables = set()
for num in range(2, limit+1):
if num in amicables:
continue
sum_fact = sum([fact for fact in range(1, num) if num % fact == 0])
sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0])
if num == sum_fact2 and num != sum_fact:
amicables.add(num)
amicables.add(sum_fact2)
return sum(amicables) | amicable_numbers_sum | easy | [{"input": "999", "output": "504", "testtype": "functional"}] |
Mbpp_123 | Write a function to sum all amicable numbers from 1 to a specified number. | 123 | mbpp | 1 | 2024-11-26T21:40:54.169365 | def amicable_numbers_sum(limit):
if not isinstance(limit, int):
return "Input is not an integer!"
if limit < 1:
return "Input must be bigger than 0!"
amicables = set()
for num in range(2, limit+1):
if num in amicables:
continue
sum_fact = sum([fact for fact in range(1, num) if num % fact == 0])
sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0])
if num == sum_fact2 and num != sum_fact:
amicables.add(num)
amicables.add(sum_fact2)
return sum(amicables) | amicable_numbers_sum | easy | [{"input": "9999", "output": "31626", "testtype": "functional"}] |
Mbpp_123 | Write a function to sum all amicable numbers from 1 to a specified number. | 123 | mbpp | 2 | 2024-11-26T21:40:54.169983 | def amicable_numbers_sum(limit):
if not isinstance(limit, int):
return "Input is not an integer!"
if limit < 1:
return "Input must be bigger than 0!"
amicables = set()
for num in range(2, limit+1):
if num in amicables:
continue
sum_fact = sum([fact for fact in range(1, num) if num % fact == 0])
sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0])
if num == sum_fact2 and num != sum_fact:
amicables.add(num)
amicables.add(sum_fact2)
return sum(amicables) | amicable_numbers_sum | easy | [{"input": "99", "output": "0", "testtype": "functional"}] |
Mbpp_124 | Write a function to get the angle of a complex number. | 124 | mbpp | 0 | 2024-11-26T21:40:54.170225 | import cmath
def angle_complex(a,b):
cn=complex(a,b)
angle=cmath.phase(a+b)
return angle | angle_complex | easy | [{"input": "0,1j", "output": "1.5707963267948966", "testtype": "functional"}] |
Mbpp_124 | Write a function to get the angle of a complex number. | 124 | mbpp | 1 | 2024-11-26T21:40:54.170387 | import cmath
def angle_complex(a,b):
cn=complex(a,b)
angle=cmath.phase(a+b)
return angle | angle_complex | easy | [{"input": "2,1j", "output": "0.4636476090008061", "testtype": "functional"}] |
Mbpp_124 | Write a function to get the angle of a complex number. | 124 | mbpp | 2 | 2024-11-26T21:40:54.170551 | import cmath
def angle_complex(a,b):
cn=complex(a,b)
angle=cmath.phase(a+b)
return angle | angle_complex | easy | [{"input": "0,2j", "output": "1.5707963267948966", "testtype": "functional"}] |
Mbpp_125 | Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string. | 125 | mbpp | 0 | 2024-11-26T21:40:54.170896 | def find_length(string, n):
current_sum = 0
max_sum = 0
for i in range(n):
current_sum += (1 if string[i] == '0' else -1)
if current_sum < 0:
current_sum = 0
max_sum = max(current_sum, max_sum)
return max_sum if max_sum else 0 | find_length | easy | [{"input": "\"11000010001\", 11", "output": "6", "testtype": "functional"}] |
Mbpp_125 | Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string. | 125 | mbpp | 1 | 2024-11-26T21:40:54.171215 | def find_length(string, n):
current_sum = 0
max_sum = 0
for i in range(n):
current_sum += (1 if string[i] == '0' else -1)
if current_sum < 0:
current_sum = 0
max_sum = max(current_sum, max_sum)
return max_sum if max_sum else 0 | find_length | easy | [{"input": "\"10111\", 5", "output": "1", "testtype": "functional"}] |
Mbpp_125 | Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string. | 125 | mbpp | 2 | 2024-11-26T21:40:54.171544 | def find_length(string, n):
current_sum = 0
max_sum = 0
for i in range(n):
current_sum += (1 if string[i] == '0' else -1)
if current_sum < 0:
current_sum = 0
max_sum = max(current_sum, max_sum)
return max_sum if max_sum else 0 | find_length | easy | [{"input": "\"11011101100101\", 14", "output": "2", "testtype": "functional"}] |
Mbpp_126 | Write a python function to find the sum of common divisors of two given numbers. | 126 | mbpp | 0 | 2024-11-26T21:40:54.171832 | def sum(a,b):
sum = 0
for i in range (1,min(a,b)):
if (a % i == 0 and b % i == 0):
sum += i
return sum | sum | easy | [{"input": "10,15", "output": "6", "testtype": "functional"}] |
Mbpp_126 | Write a python function to find the sum of common divisors of two given numbers. | 126 | mbpp | 1 | 2024-11-26T21:40:54.172154 | def sum(a,b):
sum = 0
for i in range (1,min(a,b)):
if (a % i == 0 and b % i == 0):
sum += i
return sum | sum | easy | [{"input": "100,150", "output": "93", "testtype": "functional"}] |
Mbpp_126 | Write a python function to find the sum of common divisors of two given numbers. | 126 | mbpp | 2 | 2024-11-26T21:40:54.172395 | def sum(a,b):
sum = 0
for i in range (1,min(a,b)):
if (a % i == 0 and b % i == 0):
sum += i
return sum | sum | easy | [{"input": "4,6", "output": "3", "testtype": "functional"}] |
Mbpp_127 | Write a function to multiply two integers without using the * operator in python. | 127 | mbpp | 0 | 2024-11-26T21:40:54.172668 | def multiply_int(x, y):
if y < 0:
return -multiply_int(x, -y)
elif y == 0:
return 0
elif y == 1:
return x
else:
return x + multiply_int(x, y - 1) | multiply_int | easy | [{"input": "10,20", "output": "200", "testtype": "functional"}] |
Mbpp_127 | Write a function to multiply two integers without using the * operator in python. | 127 | mbpp | 1 | 2024-11-26T21:40:54.172903 | def multiply_int(x, y):
if y < 0:
return -multiply_int(x, -y)
elif y == 0:
return 0
elif y == 1:
return x
else:
return x + multiply_int(x, y - 1) | multiply_int | easy | [{"input": "5,10", "output": "50", "testtype": "functional"}] |
Mbpp_127 | Write a function to multiply two integers without using the * operator in python. | 127 | mbpp | 2 | 2024-11-26T21:40:54.173170 | def multiply_int(x, y):
if y < 0:
return -multiply_int(x, -y)
elif y == 0:
return 0
elif y == 1:
return x
else:
return x + multiply_int(x, y - 1) | multiply_int | easy | [{"input": "4,8", "output": "32", "testtype": "functional"}] |
Mbpp_128 | Write a function to shortlist words that are longer than n from a given list of words. | 128 | mbpp | 0 | 2024-11-26T21:40:54.173405 | def long_words(n, str):
word_len = []
txt = str.split(" ")
for x in txt:
if len(x) > n:
word_len.append(x)
return word_len | long_words | easy | [{"input": "3,\"python is a programming language\"", "output": "['python','programming','language']", "testtype": "functional"}] |
Mbpp_128 | Write a function to shortlist words that are longer than n from a given list of words. | 128 | mbpp | 1 | 2024-11-26T21:40:54.173655 | def long_words(n, str):
word_len = []
txt = str.split(" ")
for x in txt:
if len(x) > n:
word_len.append(x)
return word_len | long_words | easy | [{"input": "2,\"writing a program\"", "output": "['writing','program']", "testtype": "functional"}] |
Mbpp_128 | Write a function to shortlist words that are longer than n from a given list of words. | 128 | mbpp | 2 | 2024-11-26T21:40:54.173877 | def long_words(n, str):
word_len = []
txt = str.split(" ")
for x in txt:
if len(x) > n:
word_len.append(x)
return word_len | long_words | easy | [{"input": "5,\"sorting list\"", "output": "['sorting']", "testtype": "functional"}] |
Mbpp_129 | Write a function to calculate magic square. | 129 | mbpp | 0 | 2024-11-26T21:40:54.174706 | def magic_square_test(my_matrix):
iSize = len(my_matrix[0])
sum_list = []
sum_list.extend([sum (lines) for lines in my_matrix])
for col in range(iSize):
sum_list.append(sum(row[col] for row in my_matrix))
result1 = 0
for i in range(0,iSize):
result1 +=my_matrix[i][i]
sum_list.append(result1)
result2 = 0
for i in range(iSize-1,-1,-1):
result2 +=my_matrix[i][i]
sum_list.append(result2)
if len(set(sum_list))>1:
return False
return True | magic_square_test | easy | [{"input": "[[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]]", "output": "True", "testtype": "functional"}] |
Mbpp_129 | Write a function to calculate magic square. | 129 | mbpp | 1 | 2024-11-26T21:40:54.175351 | def magic_square_test(my_matrix):
iSize = len(my_matrix[0])
sum_list = []
sum_list.extend([sum (lines) for lines in my_matrix])
for col in range(iSize):
sum_list.append(sum(row[col] for row in my_matrix))
result1 = 0
for i in range(0,iSize):
result1 +=my_matrix[i][i]
sum_list.append(result1)
result2 = 0
for i in range(iSize-1,-1,-1):
result2 +=my_matrix[i][i]
sum_list.append(result2)
if len(set(sum_list))>1:
return False
return True | magic_square_test | easy | [{"input": "[[2, 7, 6], [9, 5, 1], [4, 3, 8]]", "output": "True", "testtype": "functional"}] |
Mbpp_129 | Write a function to calculate magic square. | 129 | mbpp | 2 | 2024-11-26T21:40:54.176007 | def magic_square_test(my_matrix):
iSize = len(my_matrix[0])
sum_list = []
sum_list.extend([sum (lines) for lines in my_matrix])
for col in range(iSize):
sum_list.append(sum(row[col] for row in my_matrix))
result1 = 0
for i in range(0,iSize):
result1 +=my_matrix[i][i]
sum_list.append(result1)
result2 = 0
for i in range(iSize-1,-1,-1):
result2 +=my_matrix[i][i]
sum_list.append(result2)
if len(set(sum_list))>1:
return False
return True | magic_square_test | easy | [{"input": "[[2, 7, 6], [9, 5, 1], [4, 3, 7]]", "output": "False", "testtype": "functional"}] |
Mbpp_130 | Write a function to find the item with maximum frequency in a given list. | 130 | mbpp | 0 | 2024-11-26T21:40:54.176321 | from collections import defaultdict
def max_occurrences(nums):
dict = defaultdict(int)
for i in nums:
dict[i] += 1
result = max(dict.items(), key=lambda x: x[1])
return result | max_occurrences | easy | [{"input": "[2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2]", "output": "(2, 5)", "testtype": "functional"}] |
Mbpp_130 | Write a function to find the item with maximum frequency in a given list. | 130 | mbpp | 1 | 2024-11-26T21:40:54.176588 | from collections import defaultdict
def max_occurrences(nums):
dict = defaultdict(int)
for i in nums:
dict[i] += 1
result = max(dict.items(), key=lambda x: x[1])
return result | max_occurrences | easy | [{"input": "[2,3,8,4,7,9,8,7,9,15,14,10,12,13,16,16,18]", "output": "(8, 2)", "testtype": "functional"}] |
Mbpp_130 | Write a function to find the item with maximum frequency in a given list. | 130 | mbpp | 2 | 2024-11-26T21:40:54.176863 | from collections import defaultdict
def max_occurrences(nums):
dict = defaultdict(int)
for i in nums:
dict[i] += 1
result = max(dict.items(), key=lambda x: x[1])
return result | max_occurrences | easy | [{"input": "[10,20,20,30,40,90,80,50,30,20,50,10]", "output": "(20, 3)", "testtype": "functional"}] |
Mbpp_131 | Write a python function to reverse only the vowels of a given string. | 131 | mbpp | 0 | 2024-11-26T21:40:54.177185 | def reverse_vowels(str1):
vowels = ""
for char in str1:
if char in "aeiouAEIOU":
vowels += char
result_string = ""
for char in str1:
if char in "aeiouAEIOU":
result_string += vowels[-1]
vowels = vowels[:-1]
else:
result_string += char
return result_string | reverse_vowels | easy | [{"input": "\"Python\"", "output": "\"Python\"", "testtype": "functional"}] |
Mbpp_131 | Write a python function to reverse only the vowels of a given string. | 131 | mbpp | 1 | 2024-11-26T21:40:54.177516 | def reverse_vowels(str1):
vowels = ""
for char in str1:
if char in "aeiouAEIOU":
vowels += char
result_string = ""
for char in str1:
if char in "aeiouAEIOU":
result_string += vowels[-1]
vowels = vowels[:-1]
else:
result_string += char
return result_string | reverse_vowels | easy | [{"input": "\"USA\"", "output": "\"ASU\"", "testtype": "functional"}] |
Mbpp_131 | Write a python function to reverse only the vowels of a given string. | 131 | mbpp | 2 | 2024-11-26T21:40:54.177811 | def reverse_vowels(str1):
vowels = ""
for char in str1:
if char in "aeiouAEIOU":
vowels += char
result_string = ""
for char in str1:
if char in "aeiouAEIOU":
result_string += vowels[-1]
vowels = vowels[:-1]
else:
result_string += char
return result_string | reverse_vowels | easy | [{"input": "\"ab\"", "output": "\"ab\"", "testtype": "functional"}] |
Mbpp_132 | Write a function to convert tuple to a string. | 132 | mbpp | 0 | 2024-11-26T21:40:54.177954 | def tup_string(tup1):
str = ''.join(tup1)
return str | tup_string | easy | [{"input": "('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's')", "output": "(\"exercises\")", "testtype": "functional"}] |
Mbpp_132 | Write a function to convert tuple to a string. | 132 | mbpp | 1 | 2024-11-26T21:40:54.178086 | def tup_string(tup1):
str = ''.join(tup1)
return str | tup_string | easy | [{"input": "('p','y','t','h','o','n')", "output": "(\"python\")", "testtype": "functional"}] |
Mbpp_132 | Write a function to convert tuple to a string. | 132 | mbpp | 2 | 2024-11-26T21:40:54.178161 | def tup_string(tup1):
str = ''.join(tup1)
return str | tup_string | easy | [{"input": "('p','r','o','g','r','a','m')", "output": "(\"program\")", "testtype": "functional"}] |
Mbpp_133 | Write a function to calculate the sum of the negative numbers of a given list of numbers using lambda function. | 133 | mbpp | 0 | 2024-11-26T21:40:54.178269 | def sum_negativenum(nums):
sum_negativenum = list(filter(lambda nums:nums<0,nums))
return sum(sum_negativenum) | sum_negativenum | easy | [{"input": "[2, 4, -6, -9, 11, -12, 14, -5, 17]", "output": "-32", "testtype": "functional"}] |
Mbpp_133 | Write a function to calculate the sum of the negative numbers of a given list of numbers using lambda function. | 133 | mbpp | 1 | 2024-11-26T21:40:54.178366 | def sum_negativenum(nums):
sum_negativenum = list(filter(lambda nums:nums<0,nums))
return sum(sum_negativenum) | sum_negativenum | easy | [{"input": "[10,15,-14,13,-18,12,-20]", "output": "-52", "testtype": "functional"}] |
Mbpp_133 | Write a function to calculate the sum of the negative numbers of a given list of numbers using lambda function. | 133 | mbpp | 2 | 2024-11-26T21:40:54.178456 | def sum_negativenum(nums):
sum_negativenum = list(filter(lambda nums:nums<0,nums))
return sum(sum_negativenum) | sum_negativenum | easy | [{"input": "[19, -65, 57, 39, 152,-639, 121, 44, 90, -190]", "output": "-894", "testtype": "functional"}] |
Mbpp_134 | Write a python function to check whether the last element of given array is even or odd after performing an operation p times. | 134 | mbpp | 0 | 2024-11-26T21:40:54.178613 | def check_last (arr,n,p):
_sum = 0
for i in range(n):
_sum = _sum + arr[i]
if p == 1:
if _sum % 2 == 0:
return "ODD"
else:
return "EVEN"
return "EVEN"
| check_last | easy | [{"input": "[5,7,10],3,1", "output": "\"ODD\"", "testtype": "functional"}] |
Mbpp_134 | Write a python function to check whether the last element of given array is even or odd after performing an operation p times. | 134 | mbpp | 1 | 2024-11-26T21:40:54.178814 | def check_last (arr,n,p):
_sum = 0
for i in range(n):
_sum = _sum + arr[i]
if p == 1:
if _sum % 2 == 0:
return "ODD"
else:
return "EVEN"
return "EVEN"
| check_last | easy | [{"input": "[2,3],2,3", "output": "\"EVEN\"", "testtype": "functional"}] |
Mbpp_134 | Write a python function to check whether the last element of given array is even or odd after performing an operation p times. | 134 | mbpp | 2 | 2024-11-26T21:40:54.178967 | def check_last (arr,n,p):
_sum = 0
for i in range(n):
_sum = _sum + arr[i]
if p == 1:
if _sum % 2 == 0:
return "ODD"
else:
return "EVEN"
return "EVEN"
| check_last | easy | [{"input": "[1,2,3],3,1", "output": "\"ODD\"", "testtype": "functional"}] |
Mbpp_135 | Write a function to find the nth hexagonal number. | 135 | mbpp | 0 | 2024-11-26T21:40:54.179224 | def hexagonal_num(n):
return n*(2*n - 1) | hexagonal_num | easy | [{"input": "10", "output": "190", "testtype": "functional"}] |
Mbpp_135 | Write a function to find the nth hexagonal number. | 135 | mbpp | 1 | 2024-11-26T21:40:54.179308 | def hexagonal_num(n):
return n*(2*n - 1) | hexagonal_num | easy | [{"input": "5", "output": "45", "testtype": "functional"}] |
Mbpp_135 | Write a function to find the nth hexagonal number. | 135 | mbpp | 2 | 2024-11-26T21:40:54.179513 | def hexagonal_num(n):
return n*(2*n - 1) | hexagonal_num | easy | [{"input": "7", "output": "91", "testtype": "functional"}] |
Mbpp_136 | Write a function to calculate electricity bill. | 136 | mbpp | 0 | 2024-11-26T21:40:54.179860 | def cal_electbill(units):
if(units < 50):
amount = units * 2.60
surcharge = 25
elif(units <= 100):
amount = 130 + ((units - 50) * 3.25)
surcharge = 35
elif(units <= 200):
amount = 130 + 162.50 + ((units - 100) * 5.26)
surcharge = 45
else:
amount = 130 + 162.50 + 526 + ((units - 200) * 8.45)
surcharge = 75
total = amount + surcharge
return total | cal_electbill | easy | [{"input": "75", "output": "246.25", "testtype": "functional"}] |
Mbpp_136 | Write a function to calculate electricity bill. | 136 | mbpp | 1 | 2024-11-26T21:40:54.180122 | def cal_electbill(units):
if(units < 50):
amount = units * 2.60
surcharge = 25
elif(units <= 100):
amount = 130 + ((units - 50) * 3.25)
surcharge = 35
elif(units <= 200):
amount = 130 + 162.50 + ((units - 100) * 5.26)
surcharge = 45
else:
amount = 130 + 162.50 + 526 + ((units - 200) * 8.45)
surcharge = 75
total = amount + surcharge
return total | cal_electbill | easy | [{"input": "265", "output": "1442.75", "testtype": "functional"}] |
Mbpp_136 | Write a function to calculate electricity bill. | 136 | mbpp | 2 | 2024-11-26T21:40:54.180371 | def cal_electbill(units):
if(units < 50):
amount = units * 2.60
surcharge = 25
elif(units <= 100):
amount = 130 + ((units - 50) * 3.25)
surcharge = 35
elif(units <= 200):
amount = 130 + 162.50 + ((units - 100) * 5.26)
surcharge = 45
else:
amount = 130 + 162.50 + 526 + ((units - 200) * 8.45)
surcharge = 75
total = amount + surcharge
return total | cal_electbill | easy | [{"input": "100", "output": "327.5", "testtype": "functional"}] |
Mbpp_137 | Write a function to find the ration of zeroes in an array of integers. | 137 | mbpp | 0 | 2024-11-26T21:40:54.180533 | from array import array
def zero_count(nums):
n = len(nums)
n1 = 0
for x in nums:
if x == 0:
n1 += 1
else:
None
return round(n1/n,2) | zero_count | easy | [{"input": "[0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8]", "output": "0.15", "testtype": "functional"}] |
Mbpp_137 | Write a function to find the ration of zeroes in an array of integers. | 137 | mbpp | 1 | 2024-11-26T21:40:54.180714 | from array import array
def zero_count(nums):
n = len(nums)
n1 = 0
for x in nums:
if x == 0:
n1 += 1
else:
None
return round(n1/n,2) | zero_count | easy | [{"input": "[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8]", "output": "0.00", "testtype": "functional"}] |
Mbpp_137 | Write a function to find the ration of zeroes in an array of integers. | 137 | mbpp | 2 | 2024-11-26T21:40:54.180861 | from array import array
def zero_count(nums):
n = len(nums)
n1 = 0
for x in nums:
if x == 0:
n1 += 1
else:
None
return round(n1/n,2) | zero_count | easy | [{"input": "[2, 4, -6, -9, 11, -12, 14, -5, 17]", "output": "0.00", "testtype": "functional"}] |
Mbpp_138 | Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not. | 138 | mbpp | 0 | 2024-11-26T21:40:54.180941 | def is_Sum_Of_Powers_Of_Two(n):
if (n % 2 == 1):
return False
else:
return True | is_Sum_Of_Powers_Of_Two | easy | [{"input": "10", "output": "True", "testtype": "functional"}] |
Mbpp_138 | Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not. | 138 | mbpp | 1 | 2024-11-26T21:40:54.181009 | def is_Sum_Of_Powers_Of_Two(n):
if (n % 2 == 1):
return False
else:
return True | is_Sum_Of_Powers_Of_Two | easy | [{"input": "7", "output": "False", "testtype": "functional"}] |
Mbpp_138 | Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not. | 138 | mbpp | 2 | 2024-11-26T21:40:54.181072 | def is_Sum_Of_Powers_Of_Two(n):
if (n % 2 == 1):
return False
else:
return True | is_Sum_Of_Powers_Of_Two | easy | [{"input": "14", "output": "True", "testtype": "functional"}] |
Mbpp_139 | Write a function to find the circumference of a circle. | 139 | mbpp | 0 | 2024-11-26T21:40:54.181140 | def circle_circumference(r):
perimeter=2*3.1415*r
return perimeter | circle_circumference | easy | [{"input": "10", "output": "62.830000000000005", "testtype": "functional"}] |
Mbpp_139 | Write a function to find the circumference of a circle. | 139 | mbpp | 1 | 2024-11-26T21:40:54.181218 | def circle_circumference(r):
perimeter=2*3.1415*r
return perimeter | circle_circumference | easy | [{"input": "5", "output": "31.415000000000003", "testtype": "functional"}] |
Mbpp_139 | Write a function to find the circumference of a circle. | 139 | mbpp | 2 | 2024-11-26T21:40:54.181321 | def circle_circumference(r):
perimeter=2*3.1415*r
return perimeter | circle_circumference | easy | [{"input": "4", "output": "25.132", "testtype": "functional"}] |
Mbpp_140 | Write a function to extract elements that occur singly in the given tuple list. | 140 | mbpp | 0 | 2024-11-26T21:40:54.181597 | def extract_singly(test_list):
res = []
temp = set()
for inner in test_list:
for ele in inner:
if not ele in temp:
temp.add(ele)
res.append(ele)
return (res) | extract_singly | easy | [{"input": "[(3, 4, 5), (4, 5, 7), (1, 4)]", "output": "[3, 4, 5, 7, 1]", "testtype": "functional"}] |
Mbpp_140 | Write a function to extract elements that occur singly in the given tuple list. | 140 | mbpp | 1 | 2024-11-26T21:40:54.181880 | def extract_singly(test_list):
res = []
temp = set()
for inner in test_list:
for ele in inner:
if not ele in temp:
temp.add(ele)
res.append(ele)
return (res) | extract_singly | easy | [{"input": "[(1, 2, 3), (4, 2, 3), (7, 8)]", "output": "[1, 2, 3, 4, 7, 8]", "testtype": "functional"}] |
Mbpp_140 | Write a function to extract elements that occur singly in the given tuple list. | 140 | mbpp | 2 | 2024-11-26T21:40:54.182142 | def extract_singly(test_list):
res = []
temp = set()
for inner in test_list:
for ele in inner:
if not ele in temp:
temp.add(ele)
res.append(ele)
return (res) | extract_singly | easy | [{"input": "[(7, 8, 9), (10, 11, 12), (10, 11)]", "output": "[7, 8, 9, 10, 11, 12]", "testtype": "functional"}] |
Mbpp_141 | Write a function to sort a list of elements using pancake sort. | 141 | mbpp | 0 | 2024-11-26T21:40:54.182581 | def pancake_sort(nums):
arr_len = len(nums)
while arr_len > 1:
mi = nums.index(max(nums[0:arr_len]))
nums = nums[mi::-1] + nums[mi+1:len(nums)]
nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)]
arr_len -= 1
return nums | pancake_sort | easy | [{"input": "[15, 79, 25, 38, 69]", "output": "[15, 25, 38, 69, 79]", "testtype": "functional"}] |
Mbpp_141 | Write a function to sort a list of elements using pancake sort. | 141 | mbpp | 1 | 2024-11-26T21:40:54.183024 | def pancake_sort(nums):
arr_len = len(nums)
while arr_len > 1:
mi = nums.index(max(nums[0:arr_len]))
nums = nums[mi::-1] + nums[mi+1:len(nums)]
nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)]
arr_len -= 1
return nums | pancake_sort | easy | [{"input": "[98, 12, 54, 36, 85]", "output": "[12, 36, 54, 85, 98]", "testtype": "functional"}] |
Mbpp_141 | Write a function to sort a list of elements using pancake sort. | 141 | mbpp | 2 | 2024-11-26T21:40:54.183427 | def pancake_sort(nums):
arr_len = len(nums)
while arr_len > 1:
mi = nums.index(max(nums[0:arr_len]))
nums = nums[mi::-1] + nums[mi+1:len(nums)]
nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)]
arr_len -= 1
return nums | pancake_sort | easy | [{"input": "[41, 42, 32, 12, 23]", "output": "[12, 23, 32, 41, 42]", "testtype": "functional"}] |
Mbpp_142 | Write a function to count the same pair in three given lists. | 142 | mbpp | 0 | 2024-11-26T21:40:54.183677 | def count_samepair(list1,list2,list3):
result = sum(m == n == o for m, n, o in zip(list1,list2,list3))
return result | count_samepair | easy | [{"input": "[1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,9],[2,1,3,1,2,6,7,9]", "output": "3", "testtype": "functional"}] |
Mbpp_142 | Write a function to count the same pair in three given lists. | 142 | mbpp | 1 | 2024-11-26T21:40:54.183878 | def count_samepair(list1,list2,list3):
result = sum(m == n == o for m, n, o in zip(list1,list2,list3))
return result | count_samepair | easy | [{"input": "[1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8]", "output": "4", "testtype": "functional"}] |
Mbpp_142 | Write a function to count the same pair in three given lists. | 142 | mbpp | 2 | 2024-11-26T21:40:54.184055 | def count_samepair(list1,list2,list3):
result = sum(m == n == o for m, n, o in zip(list1,list2,list3))
return result | count_samepair | easy | [{"input": "[1,2,3,4,2,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8]", "output": "5", "testtype": "functional"}] |
Mbpp_143 | Write a function to find number of lists present in the given tuple. | 143 | mbpp | 0 | 2024-11-26T21:40:54.184195 | def find_lists(Input):
if isinstance(Input, list):
return 1
else:
return len(Input) | find_lists | easy | [{"input": "([1, 2, 3, 4], [5, 6, 7, 8])", "output": "2", "testtype": "functional"}] |
Mbpp_143 | Write a function to find number of lists present in the given tuple. | 143 | mbpp | 1 | 2024-11-26T21:40:54.184314 | def find_lists(Input):
if isinstance(Input, list):
return 1
else:
return len(Input) | find_lists | easy | [{"input": "([1, 2], [3, 4], [5, 6])", "output": "3", "testtype": "functional"}] |
Mbpp_143 | Write a function to find number of lists present in the given tuple. | 143 | mbpp | 2 | 2024-11-26T21:40:54.184442 | def find_lists(Input):
if isinstance(Input, list):
return 1
else:
return len(Input) | find_lists | easy | [{"input": "([9, 8, 7, 6, 5, 4, 3, 2, 1])", "output": "1", "testtype": "functional"}] |
Mbpp_144 | Write a python function to find the sum of absolute differences in all pairs of the given array. | 144 | mbpp | 0 | 2024-11-26T21:40:54.184703 | def sum_Pairs(arr,n):
sum = 0
for i in range(n - 1,-1,-1):
sum += i*arr[i] - (n-1-i) * arr[i]
return sum | sum_Pairs | easy | [{"input": "[1,8,9,15,16],5", "output": "74", "testtype": "functional"}] |