task_id
stringlengths 6
8
| text
stringlengths 368
1.62k
|
---|---|
Mbpp/439 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to join a list of multiple integers into a single integer
assert multiple_to_single([11, 33, 50])==113350
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def multiple_to_single(L):
return int(''.join(map(str,L)))
``` |
Mbpp/440 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the first adverb and their positions in a given sentence
assert find_adverb_position("clearly!! we can see the sky")==(0, 7, 'clearly')
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import re
def find_adverb_position(text):
for m in re.finditer(r"\w+ly", text):
return (m.start(), m.end(), m.group(0))
``` |
Mbpp/441 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the surface area of a cube of a given size
assert surfacearea_cube(5)==150
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def surfacearea_cube(l):
return 6 * l * l
``` |
Mbpp/445 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to perform index wise multiplication of tuple elements in the given two tuples
assert index_multiplication(((1, 3), (4, 5), (2, 9), (1, 10)),((6, 7), (3, 9), (1, 1), (7, 3)) ) == ((6, 21), (12, 45), (2, 9), (7, 30))
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def index_multiplication(test_tup1, test_tup2):
return tuple(tuple(a * b for a, b in zip(tup1, tup2))
for tup1, tup2 in zip(test_tup1, test_tup2))
``` |
Mbpp/446 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to count the occurence of all elements of list in a tuple
assert count_Occurrence(('a', 'a', 'c', 'b', 'd'),['a', 'b'] ) == 3
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
from collections import Counter
def count_Occurrence(tup, lst):
return sum(tup.count(ele) for ele in lst)
``` |
Mbpp/447 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find cubes of individual elements in a list
assert cube_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def cube_nums(nums):
return [n**3 for n in nums]
``` |
Mbpp/448 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to calculate the sum of perrin numbers
assert cal_sum(9) == 49
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def cal_sum(n):
a = 3
b = 0
c = 2
if (n == 0):
return 3
if (n == 1):
return 3
if (n == 2):
return 5
sum = 5
while (n > 2):
d = a + b
sum = sum + d
a = b
b = c
c = d
n = n - 1
return sum
``` |
Mbpp/450 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to extract specified size of strings from a given list of string values
assert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,8)==['practice', 'solution']
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def extract_string(str1, l):
return [e for e in str1 if len(e) == l]
``` |
Mbpp/451 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to remove all whitespaces from the given string
assert remove_whitespaces(' Google Flutter ') == 'GoogleFlutter'
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import re
def remove_whitespaces(text1):
return text1.replace(' ', '')
``` |
Mbpp/453 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the sum of even factors of a number
assert sumofFactors(18) == 26
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import math
def sumofFactors(n) :
if (n % 2 != 0) :
return 0
return sum([i for i in range(2, n + 1) if n % i == 0 and i % 2 == 0])
``` |
Mbpp/454 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function that matches a word containing 'z'
assert text_match_wordz("pythonz.")==True
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import re
def text_match_wordz(text):
return 'z' in text
``` |
Mbpp/455 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to check whether the given month number contains 31 days or not
assert check_monthnumb_number(5)==True
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def check_monthnumb_number(monthnum2):
return monthnum2 in [1, 3, 5, 7, 8, 10, 12]
``` |
Mbpp/456 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to reverse each string in a given list of string values
assert reverse_string_list(['Red', 'Green', 'Blue', 'White', 'Black'])==['deR', 'neerG', 'eulB', 'etihW', 'kcalB']
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def reverse_string_list(stringlist):
return [x[::-1] for x in stringlist]
``` |
Mbpp/457 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the sublist having minimum length
assert Find_Min([[1],[1,2],[1,2,3]]) == [1]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def Find_Min(lst):
return min(lst, key=len)
``` |
Mbpp/458 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the area of a rectangle
assert rectangle_area(10,20)==200
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def rectangle_area(l,b):
return l * b
``` |
Mbpp/459 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to remove uppercase substrings from a given string
assert remove_uppercase('cAstyoUrFavoRitETVshoWs') == 'cstyoravoitshos'
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def remove_uppercase(str1):
return ''.join(c for c in str1 if c.islower())
``` |
Mbpp/460 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to get the first element of each sublist
assert Extract([[1, 2], [3, 4, 5], [6, 7, 8, 9]]) == [1, 3, 6]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def Extract(lst):
return [item[0] for item in lst]
``` |
Mbpp/462 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find all possible combinations of the elements of a given list
assert combinations_list(['orange', 'red', 'green', 'blue'])==[[], ['orange'], ['red'], ['red', 'orange'], ['green'], ['green', 'orange'], ['green', 'red'], ['green', 'red', 'orange'], ['blue'], ['blue', 'orange'], ['blue', 'red'], ['blue', 'red', 'orange'], ['blue', 'green'], ['blue', 'green', 'orange'], ['blue', 'green', 'red'], ['blue', 'green', 'red', 'orange']]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def combinations_list(list1):
if len(list1) == 0:
return [[]]
result = []
for el in combinations_list(list1[1:]):
result += [el, el+[list1[0]]]
return result
``` |
Mbpp/463 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the maximum product subarray of the given array
assert max_subarray_product([1, -2, -3, 0, 7, -8, -2]) == 112
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def max_subarray_product(arr):
max_so_far = min_ending = max_ending = arr[0]
for n in arr[1:]:
min_ending, max_ending = min(n, min_ending * n, max_ending * n), max(n, min_ending * n, max_ending * n)
max_so_far = max(max_so_far, max_ending)
return max_so_far
``` |
Mbpp/465 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to drop empty items from a given dictionary
assert drop_empty({'c1': 'Red', 'c2': 'Green', 'c3':None})=={'c1': 'Red', 'c2': 'Green'}
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def drop_empty(dict1):
dict1 = {key:value for (key, value) in dict1.items() if value is not None}
return dict1
``` |
Mbpp/468 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the maximum product formed by multiplying numbers of an increasing subsequence of that array
assert max_product([3, 100, 4, 5, 150, 6]) == 3000
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def max_product(arr):
# record the correspond ending element to maintain the increasing subsequence
ret = max_ending = min_ending = (arr[0], arr[0])
for n in arr[1:]:
if n > max_ending[1]:
max_ending = max((max_ending[0] * n, n), max_ending, key=lambda x: x[0])
else:
max_ending = (n, n)
if n > min_ending[1]:
min_ending = min((min_ending[0] * n, n), min_ending, key=lambda x: x[0])
else:
min_ending = (n, n)
ret = max(ret, max_ending, min_ending, key=lambda x: x[0])
return ret[0]
``` |
Mbpp/470 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the pairwise addition of the neighboring elements of the given tuple
assert add_pairwise((1, 5, 7, 8, 10)) == (6, 12, 15, 18)
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def add_pairwise(test_tup):
return tuple(a + b for a, b in zip(test_tup, test_tup[1:]))
``` |
Mbpp/471 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the product of the array multiplication modulo n
assert find_remainder([ 100, 10, 5, 25, 35, 14 ],11) ==9
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def find_remainder(arr, n):
from functools import reduce
return reduce(lambda x, y: x * y, arr) % n
``` |
Mbpp/472 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to check whether the given list contains consecutive numbers or not
assert check_Consecutive([1,2,3,4,5]) == True
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def check_Consecutive(l):
return sorted(l) == list(range(min(l),max(l)+1))
``` |
Mbpp/473 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the tuple intersection of elements in the given tuple list irrespective of their order
assert tuple_intersection([(3, 4), (5, 6), (9, 10), (4, 5)] , [(5, 4), (3, 4), (6, 5), (9, 11)]) == {(4, 5), (3, 4), (5, 6)}
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def tuple_intersection(test_list1, test_list2):
return set([tuple(sorted(ele)) for ele in test_list1]) & set([tuple(sorted(ele)) for ele in test_list2])
``` |
Mbpp/474 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to replace characters in a string
assert replace_char("polygon",'y','l')==("pollgon")
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def replace_char(str1, ch, newch):
return str1.replace(ch, newch)
``` |
Mbpp/475 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to sort a dictionary by value
assert sort_counter({'Math':81, 'Physics':83, 'Chemistry':87})==[('Chemistry', 87), ('Physics', 83), ('Math', 81)]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def sort_counter(dict1):
return sorted(dict1.items(), key=lambda x: x[1], reverse=True)
``` |
Mbpp/476 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the sum of the largest and smallest value in a given array
assert big_sum([1,2,3]) == 4
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def big_sum(nums):
return max(nums) + min(nums)
``` |
Mbpp/477 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to convert the given string to lower case
assert is_lower("InValid") == "invalid"
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def is_lower(string):
return string.lower()
``` |
Mbpp/478 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to remove lowercase substrings from a given string
assert remove_lowercase("PYTHon")==('PYTH')
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import re
def remove_lowercase(str1):
return re.sub('[a-z]', '', str1)
``` |
Mbpp/479 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the first digit of a given number
assert first_Digit(123) == 1
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def first_Digit(n) :
return int(str(n)[0])
``` |
Mbpp/554 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function which takes a list of integers and only returns the odd ones
assert Split([1,2,3,4,5,6]) == [1,3,5]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def Split(l):
return list(filter(lambda x: x % 2 == 1, l))
``` |
Mbpp/555 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the difference between the sum of cubes of the first n natural numbers and the sum of the first n natural numbers
assert difference(3) == 30
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def difference(n) :
S = (n*(n + 1))//2;
res = S*(S-1);
return res;
``` |
Mbpp/556 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to count the number of pairs whose xor value is odd
assert find_Odd_Pair([5,4,7,2,1],5) == 6
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def find_Odd_Pair(A,N) :
oddPair = 0
for i in range(0,N) :
for j in range(i+1,N) :
if ((A[i] ^ A[j]) % 2 != 0):
oddPair+=1
return oddPair
``` |
Mbpp/557 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to toggle the case of all characters in a string
assert toggle_string("Python")==("pYTHON")
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def toggle_string(string):
return string.swapcase()
``` |
Mbpp/558 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the sum of the per-digit difference between two integers
assert digit_distance_nums(1,2) == 1
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def digit_distance_nums(n1, n2):
return sum([abs(int(c1) - int(c2)) for c1, c2 in zip(str(n1), str(n2))])
``` |
Mbpp/559 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the sum of the largest contiguous sublist in the given list
assert max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3], 8) == 7
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def max_sub_array_sum(a, size):
max_so_far = 0
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if max_ending_here < 0:
max_ending_here = 0
elif (max_so_far < max_ending_here):
max_so_far = max_ending_here
return max_so_far
``` |
Mbpp/560 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the union of the elements of two given tuples and output them in sorted order
assert union_elements((3, 4, 5, 6),(5, 7, 4, 10) ) == (3, 4, 5, 6, 7, 10)
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def union_elements(test_tup1, test_tup2):
return tuple(sorted(set(test_tup1 + test_tup2)))
``` |
Mbpp/562 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the length of the longest sublists
assert Find_Max_Length([[1],[1,4],[5,6,7,8]]) == 4
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def Find_Max_Length(lst):
return len(max(lst, key = len))
``` |
Mbpp/563 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to extract values between quotation marks from a string
assert extract_values('"Python", "PHP", "Java"')==['Python', 'PHP', 'Java']
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import re
def extract_values(text):
return (re.findall(r'"(.*?)"', text))
``` |
Mbpp/564 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function which takes a list of integers and counts the number of possible unordered pairs where both elements are unequal
assert count_Pairs([1,2,1],3) == 2
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def count_Pairs(arr,n):
cnt = 0;
for i in range(n):
for j in range(i + 1,n):
if (arr[i] != arr[j]):
cnt += 1;
return cnt;
``` |
Mbpp/565 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to split a string into characters
assert split('python') == ['p','y','t','h','o','n']
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def split(word):
return list(word)
``` |
Mbpp/566 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to get the sum of the digits of a non-negative integer
assert sum_digits(345)==12
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def sum_digits(n):
return sum(map(int, str(n)))
``` |
Mbpp/567 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to check whether a specified list is sorted or not
assert issort_list([1,2,4,6,8,10,12,14,16,17])==True
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def issort_list(list1):
return all(a <= b for a, b in zip(list1, list1[1:]))
``` |
Mbpp/568 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to create a list of N empty dictionaries
assert empty_list(5)==[{},{},{},{},{}]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def empty_list(length):
return [{} for _ in range(length)]
``` |
Mbpp/569 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to sort each sublist of strings in a given list of lists
assert sort_sublists((["green", "orange"], ["black", "white"], ["white", "black", "orange"]))==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def sort_sublists(input_list):
return [sorted(x) for x in input_list]
``` |
Mbpp/572 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to remove duplicate numbers from a given number of lists
assert two_unique_nums([1,2,3,2,3,4,5]) == [1, 4, 5]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def two_unique_nums(nums):
return [n for n in nums if nums.count(n)==1]
``` |
Mbpp/573 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to calculate the product of the unique numbers in a given list
assert unique_product([10, 20, 30, 40, 20, 50, 60, 40]) == 720000000
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def unique_product(list_data):
from functools import reduce
return reduce(lambda x, y: x*y, set(list_data))
``` |
Mbpp/576 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to check whether a list is sublist of another or not
assert is_Sub_Array([1,4,3,5],[1,2]) == False
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def is_Sub_Array(A,B):
a = 0
b = 0
while a < len(A) and b < len(B):
if A[a] == B[b]:
a += 1
b += 1
else:
a += 1
return b == len(B)
``` |
Mbpp/577 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the last digit in factorial of a given number
assert last_Digit_Factorial(4) == 4
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def last_Digit_Factorial(n):
if (n == 0):
return 1
elif (n <= 2):
return n
elif (n == 3):
return 6
elif (n == 4):
return 4
else:
return 0
``` |
Mbpp/578 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to interleave 3 lists of the same length into a single flat list
assert interleave_lists([1,2,3,4,5,6,7],[10,20,30,40,50,60,70],[100,200,300,400,500,600,700])==[1, 10, 100, 2, 20, 200, 3, 30, 300, 4, 40, 400, 5, 50, 500, 6, 60, 600, 7, 70, 700]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def interleave_lists(list1, list2, list3):
return [el for pair in zip(list1, list2, list3) for el in pair]
``` |
Mbpp/579 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the dissimilar elements in the given two tuples
assert find_dissimilar((3, 4, 5, 6), (5, 7, 4, 10)) == (3, 6, 7, 10)
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def find_dissimilar(test_tup1, test_tup2):
return tuple(set(test_tup1) ^ set(test_tup2))
``` |
Mbpp/580 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to remove uneven elements in the nested mixed tuple
assert extract_even((4, 5, (7, 6, (2, 4)), 6, 8)) == (4, (6, (2, 4)), 6, 8)
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def even_ele(test_tuple, ):
res = tuple()
for ele in test_tuple:
if isinstance(ele, tuple):
res += (even_ele(ele), )
elif ele % 2 == 0:
res += (ele, )
return res
def extract_even(test_tuple):
return even_ele(test_tuple)
``` |
Mbpp/581 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the surface area of a square pyramid with a given base edge and height
assert surface_Area(3,4) == 33
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def surface_Area(b,s):
return 2 * b * s + pow(b,2)
``` |
Mbpp/583 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function which returns nth catalan number
assert catalan_number(10)==16796
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def catalan_number(num):
if num <= 1:
return 1
res_num = 0
for i in range(num):
res_num += catalan_number(i) * catalan_number(num - i - 1)
return res_num
``` |
Mbpp/585 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the n most expensive items in a given dataset
assert expensive_items([{'name': 'Item-1', 'price': 101.1},{'name': 'Item-2', 'price': 555.22}],1)==[{'name': 'Item-2', 'price': 555.22}]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import heapq
def expensive_items(items,n):
expensive_items = heapq.nlargest(n, items, key=lambda s: s['price'])
return expensive_items
``` |
Mbpp/586 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to split a list at the nth eelment and add the first part to the end
assert split_Arr([12,10,5,6,52,36],2) == [5,6,52,36,12,10]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def split_Arr(l, n):
return l[n:] + l[:n]
``` |
Mbpp/587 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to convert a list to a tuple
assert list_tuple([5, 10, 7, 4, 15, 3])==(5, 10, 7, 4, 15, 3)
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def list_tuple(listx):
return tuple(listx)
``` |
Mbpp/588 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the difference between largest and smallest value in a given list
assert big_diff([1,2,3,4]) == 3
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def big_diff(nums):
return max(nums) - min(nums)
``` |
Mbpp/589 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find perfect squares between two given numbers
assert perfect_squares(1,30)==[1, 4, 9, 16, 25]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import math
def perfect_squares(a, b):
if a > b:
a, b = b, a
if b < 0:
return []
if a < 0:
a = 0
return list(filter(lambda x: math.sqrt(x).is_integer(), range(a, b+1)))
``` |
Mbpp/590 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to convert polar coordinates to rectangular coordinates
assert polar_rect(3,4)==((5.0, 0.9272952180016122), (-2+2.4492935982947064e-16j))
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import cmath
def polar_rect(x,y):
cn = cmath.polar(complex(x, y))
cn1 = cmath.rect(2, cmath.pi)
return (cn, cn1)
``` |
Mbpp/591 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to interchange the first and last elements in a list
assert swap_List([12, 35, 9, 56, 24]) == [24, 35, 9, 56, 12]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def swap_List(newList):
return newList[-1:] + newList[1:-1] + newList[:1]
``` |
Mbpp/592 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the sum of the product of consecutive binomial co-efficients
assert sum_Of_product(3) == 15
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def binomial_Coeff(n, k):
C = [0] * (k + 1);
C[0] = 1; # nC0 is 1
for i in range(1,n + 1):
for j in range(min(i, k),0,-1):
C[j] = C[j] + C[j - 1];
return C[k];
def sum_Of_product(n):
return binomial_Coeff(2 * n, n - 1);
``` |
Mbpp/593 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to remove leading zeroes from an ip address
assert removezero_ip("216.08.094.196")==('216.8.94.196')
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import re
def removezero_ip(ip):
return re.sub('\.[0]*', '.', ip)
``` |
Mbpp/594 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the difference of the first even and first odd number of a given list
assert diff_even_odd([1,3,5,7,4,1,6,8])==3
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def diff_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)
``` |
Mbpp/596 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the size in bytes of the given tuple
assert tuple_size(("A", 1, "B", 2, "C", 3) ) == sys.getsizeof(("A", 1, "B", 2, "C", 3))
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import sys
def tuple_size(tuple_list):
return sys.getsizeof(tuple_list)
``` |
Mbpp/597 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find kth element from the given two sorted arrays
assert find_kth([2, 3, 6, 7, 9], [1, 4, 8, 10], 5) == 6
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def find_kth(arr1, arr2, k):
return sorted(arr1 + arr2)[k - 1]
``` |
Mbpp/598 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to check whether the given number is armstrong or not
assert armstrong_number(153)==True
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def armstrong_number(number):
order = len(str(number))
return sum([int(i) ** order for i in str(number)]) == number
``` |
Mbpp/599 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find sum and average of first n natural numbers
assert sum_average(10)==(55, 5.5)
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def sum_average(number):
sum_ = sum(range(1, number+1))
average = sum_/number
return sum_, average
``` |
Mbpp/600 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to check whether the given number is even or not
assert is_Even(1) == False
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def is_Even(n) :
return n % 2 == 0
``` |
Mbpp/602 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the first repeated character in a given string
assert first_repeated_char("abcabc") == "a"
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def first_repeated_char(str1):
for index, c in enumerate(str1):
if str1[:index + 1].count(c) > 1:
return c
return None
``` |
Mbpp/603 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to get all lucid numbers smaller than or equal to a given integer
assert get_ludic(10) == [1, 2, 3, 5, 7]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def get_ludic(n):
ludics = []
for i in range(1, n + 1):
ludics.append(i)
index = 1
while(index != len(ludics)):
first_ludic = ludics[index]
remove_index = index + first_ludic
while(remove_index < len(ludics)):
ludics.remove(ludics[remove_index])
remove_index = remove_index + first_ludic - 1
index += 1
return ludics
``` |
Mbpp/604 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to reverse words seperated by spaces in a given string
assert reverse_words("python program")==("program python")
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def reverse_words(s):
return ' '.join(reversed(s.split()))
``` |
Mbpp/605 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to check if the given integer is a prime number
assert prime_num(13)==True
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import math
def prime_num(num):
if num <= 1:
return False
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
return False
return True
``` |
Mbpp/606 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to convert degrees to radians
assert radian_degree(90)==1.5707963267948966
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import math
def radian_degree(degree):
return degree * math.pi / 180
``` |
Mbpp/607 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to search a string for a regex pattern
assert find_literals('The quick brown fox jumps over the lazy dog.', 'fox') == ('fox', 16, 19)
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import re
def find_literals(text, pattern):
match = re.search(pattern, text)
if match is None:
return None
s = match.start()
e = match.end()
return (match.re.pattern, s, e)
``` |
Mbpp/608 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find nth bell number
assert bell_Number(2) == 2
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def bell_Number(n):
bell = [[0 for i in range(n+1)] for j in range(n+1)]
bell[0][0] = 1
for i in range(1, n+1):
bell[i][0] = bell[i-1][i-1]
for j in range(1, i+1):
bell[i][j] = bell[i-1][j-1] + bell[i][j-1]
return bell[n][0]
``` |
Mbpp/610 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function which takes a list and returns a list with the same elements, but the k'th element removed
assert remove_kth_element([1,1,2,3,4,4,5,1],3)==[1, 1, 3, 4, 4, 5, 1]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def remove_kth_element(list1, k):
return list1[:k-1] + list1[k:]
``` |
Mbpp/611 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function which given a matrix represented as a list of lists returns the max of the n'th column
assert max_of_nth([[5, 6, 7], [1, 3, 5], [8, 9, 19]], 2) == 19
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def max_of_nth(test_list, N):
return max([sub[N] for sub in test_list])
``` |
Mbpp/612 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function which takes a list of lists, where each sublist has two elements, and returns a list of two lists where the first list has the first element of each sublist and the second one has the second
assert merge([['x', 'y'], ['a', 'b'], ['m', 'n']]) == [['x', 'a', 'm'], ['y', 'b', 'n']]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def merge(lst):
return [list(ele) for ele in list(zip(*lst))]
``` |
Mbpp/614 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the cumulative sum of all the values that are present in the given tuple list
assert cummulative_sum([(1, 3), (5, 6, 7), (2, 6)]) == 30
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def cummulative_sum(test_list):
return sum(map(sum, test_list))
``` |
Mbpp/615 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function which takes a tuple of tuples and returns the average value for each tuple as a list
assert average_tuple(((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4)))==[30.5, 34.25, 27.0, 23.25]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def average_tuple(nums):
result = [sum(x) / len(x) for x in zip(*nums)]
return result
``` |
Mbpp/616 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function which takes two tuples of the same length and performs the element wise modulo
assert tuple_modulo((10, 4, 5, 6), (5, 6, 7, 5)) == (0, 4, 5, 1)
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def tuple_modulo(test_tup1, test_tup2):
res = tuple(ele1 % ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res)
``` |
Mbpp/618 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to divide two lists element wise
assert div_list([4,5,6],[1, 2, 3])==[4.0,2.5,2.0]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def div_list(nums1,nums2):
result = map(lambda x, y: x / y, nums1, nums2)
return list(result)
``` |
Mbpp/619 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to move all the numbers to the end of the given string
assert move_num('I1love143you55three3000thousand') == 'Iloveyouthreethousand1143553000'
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def move_num(test_str):
num_str = ''.join(i for i in test_str if i.isdigit())
else_str = ''.join(i for i in test_str if not i.isdigit())
return else_str + num_str
``` |
Mbpp/620 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the size of the largest subset of a list of numbers so that every pair is divisible
assert largest_subset([ 1, 3, 6, 13, 17, 18 ]) == 4
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def largest_subset(a):
n = len(a)
dp = [0 for _ in range(n)]
dp[n - 1] = 1;
for i in range(n - 2, -1, -1):
mxm = 0
for j in range(i + 1, n):
if a[j] % a[i] == 0 or a[i] % a[j] == 0:
mxm = max(mxm, dp[j])
dp[i] = 1 + mxm
return max(dp)
``` |
Mbpp/622 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to find the median of two sorted lists of same size
assert get_median([1, 12, 15, 26, 38], [2, 13, 17, 30, 45], 5) == 16.0
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def get_median(arr1, arr2, n):
i = 0
j = 0
m1 = -1
m2 = -1
count = 0
while count < n + 1:
count += 1
if i == n:
m1 = m2
m2 = arr2[0]
break
elif j == n:
m1 = m2
m2 = arr1[0]
break
if arr1[i] <= arr2[j]:
m1 = m2
m2 = arr1[i]
i += 1
else:
m1 = m2
m2 = arr2[j]
j += 1
return (m1 + m2)/2
``` |
Mbpp/623 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to compute the n-th power of each number in a list
assert nth_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2)==[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def nth_nums(nums, n):
nth_nums = list(map(lambda x: x ** n, nums))
return nth_nums
``` |
Mbpp/624 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to convert a given string to uppercase
assert is_upper("person") =="PERSON"
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def is_upper(string):
return string.upper()
``` |
Mbpp/626 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the area of the largest triangle that can be inscribed in a semicircle with a given radius
assert triangle_area(-1) == None
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def triangle_area(r) :
if r < 0 :
return None
return r * r
``` |
Mbpp/628 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to replace all spaces in the given string with '%20'
assert replace_spaces("My Name is Dawood") == 'My%20Name%20is%20Dawood'
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def replace_spaces(string):
return string.replace(" ", "%20")
``` |
Mbpp/629 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find even numbers from a list of numbers
assert Split([1,2,3,4,5]) == [2,4]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def Split(l):
return [num for num in l if num % 2 == 0]
``` |
Mbpp/630 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to extract all the adjacent coordinates of the given coordinate tuple
assert get_coordinates((3, 4)) == [[2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5]]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def adjac(ele, sub = []):
if not ele:
yield sub
else:
yield from [idx for j in range(ele[0] - 1, ele[0] + 2)
for idx in adjac(ele[1:], sub + [j])]
def get_coordinates(test_tup):
return list(adjac(test_tup))
``` |
Mbpp/631 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to replace whitespaces with an underscore and vice versa in a given string
assert replace_spaces('Jumanji The Jungle') == 'Jumanji_The_Jungle'
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def replace_spaces(text):
return "".join(" " if c == "_" else ("_" if c == " " else c) for c in text)
``` |
Mbpp/632 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to move all zeroes to the end of the given list
assert move_zero([1,0,2,0,3,4]) == [1,2,3,4,0,0]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def move_zero(num_list):
zeros = [0] * num_list.count(0)
front = [i for i in num_list if i != 0]
return front + zeros
``` |
Mbpp/633 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a python function to find the sum of xor of all pairs of numbers in the given list
assert pair_xor_Sum([5,9,7,6],4) == 47
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def pair_xor_Sum(arr,n) :
ans = 0
for i in range(0,n) :
for j in range(i + 1,n) :
ans = ans + (arr[i] ^ arr[j])
return ans
``` |
Mbpp/635 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to sort the given list
assert heap_sort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import heapq as hq
def heap_sort(iterable):
hq.heapify(iterable)
return [hq.heappop(iterable) for _ in range(len(iterable))]
``` |
Mbpp/637 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to check whether the given amount has no profit and no loss
assert noprofit_noloss(1500,1200)==False
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def noprofit_noloss(actual_cost, sale_amount):
return actual_cost == sale_amount
``` |
Mbpp/638 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to calculate the wind chill index rounded to the next integer given the wind velocity in km/h and a temperature in celsius
assert wind_chill(120,35)==40
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
import math
def wind_chill(v,t):
windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16)
return int(round(windchill, 0))
``` |
Mbpp/639 | Please provide a self-contained Python script that solves the following problem in a markdown code block:
```
Write a function to sum the length of the names of a given list of names after removing the names that start with a lowercase letter
assert sample_nam(['sally', 'Dylan', 'rebecca', 'Diana', 'Joanne', 'keith'])==16
```
### Answer:
Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:
```python
def sample_nam(sample_names):
sample_names=list(filter(lambda el:el[0].isupper() and el[1:].islower(),sample_names))
return len(''.join(sample_names))
``` |