task_id
stringlengths
6
8
text
stringlengths
368
1.62k
Mbpp/226
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to remove the characters which have odd index values of a given string assert odd_values_string('abcdef') == 'ace' ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def odd_values_string(str1): return ''.join(str1[i] for i in range(0, len(str1), 2)) ```
Mbpp/227
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find minimum of three numbers assert min_of_three(10,20,0)==0 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def min_of_three(a,b,c): return min(a, b, c) ```
Mbpp/230
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string assert replace_blank("hello people",'@')==("hello@people") ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def replace_blank(str1, char): return str1.replace(' ', char) ```
Mbpp/232
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in a list and an integer n and returns a list containing the n largest items from the list assert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2))==set([100,90]) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import heapq def larg_nnum(list1, n): return heapq.nlargest(n,list1) ```
Mbpp/233
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the lateral surface area of a cylinder assert math.isclose(lateralsuface_cylinder(10,5), 314.15000000000003, rel_tol=0.001) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import math def lateralsuface_cylinder(r, h): return 2 * math.pi * r * h ```
Mbpp/234
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the volume of a cube given its side length assert volume_cube(3)==27 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def volume_cube(l): return l ** 3 ```
Mbpp/235
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to set all even bits of a given number assert even_bit_set_number(10) == 10 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def even_bit_set_number(n): mask = 2 while mask < n: n |= mask mask <<= 2 return n ```
Mbpp/237
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in a list of tuples and returns a dictionary mapping each unique tuple to the number of times it occurs in the list assert check_occurences([(3, 1), (1, 3), (2, 5), (5, 2), (6, 3)] ) == {(1, 3): 2, (2, 5): 2, (3, 6): 1} ``` ### 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 check_occurences(test_list): return dict(Counter(tuple(sorted(t)) for t in test_list)) ```
Mbpp/238
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 non-empty substrings of a given string assert number_of_substrings("abc") == 6 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def number_of_substrings(str1): str_len = len(str1) return str_len * (str_len + 1) // 2 ```
Mbpp/239
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m assert get_total_number_of_sequences(10, 4) == 4 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def get_total_number_of_sequences(m, n): T=[[0 for _ in range(n + 1)] for _ in range(m + 1)] for i in range(m + 1): for j in range(n + 1): if i==0 or j==0: T[i][j] = 0 elif i<j: T[i][j] = 0 elif j==1: T[i][j] = i else: T[i][j] = T[i-1][j] + T[i//2][j-1] return T[m][n] ```
Mbpp/240
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in two lists and replaces the last element of the first list with the elements of the second list assert replace_list([1, 3, 5, 7, 9, 10],[2, 4, 6, 8])==[1, 3, 5, 7, 9, 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 replace_list(list1, list2): return list1[:-1] + list2 ```
Mbpp/242
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to count the total number of characters in a string assert count_charac("python programming")==18 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def count_charac(str1): return len(str1) ```
Mbpp/244
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find the next perfect square greater than a given number assert next_Perfect_Square(35) == 36 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import math def next_Perfect_Square(N): if N < 0: return 0 nextN = math.floor(math.sqrt(N)) + 1 return nextN * nextN ```
Mbpp/245
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing assert max_sum([1, 15, 51, 45, 33, 100, 12, 18, 9]) == 194 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def max_sum(arr): MSIBS = arr[:] for i in range(len(arr)): for j in range(0, i): if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]: MSIBS[i] = MSIBS[j] + arr[i] MSDBS = arr[:] for i in range(1, len(arr) + 1): for j in range(1, i): if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]: MSDBS[-i] = MSDBS[-j] + arr[-i] max_sum = float("-Inf") for i, j, k in zip(MSIBS, MSDBS, arr): max_sum = max(max_sum, i + j - k) return max_sum ```
Mbpp/247
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the length of the longest palindromic subsequence in the given string assert lps("TENS FOR TENS") == 5 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def lps(str1): n = len(str1) dp = [[0] * n for _ in range(n)] for i in range(n - 1, -1, -1): dp[i][i] = 1 for j in range(i + 1, n): if str1[i] == str1[j]: dp[i][j] = dp[i + 1][j - 1] + 2 else: dp[i][j] = max(dp[i + 1][j], dp[i][j - 1]) return dp[0][n - 1] ```
Mbpp/250
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function that takes in a tuple and an element and counts the occcurences of the element in the tuple assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),4) == 0 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def count_X(tup, x): return tup.count(x) ```
Mbpp/251
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in a list and an element and inserts the element before each element in the list, and returns the resulting list assert insert_element(['Red', 'Green', 'Black'] ,'c')==['c', 'Red', 'c', 'Green', 'c', 'Black'] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def insert_element(list1, element): list1 = [v for elt in list1 for v in (element, elt)] return list1 ```
Mbpp/252
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to convert complex numbers to polar coordinates assert convert(1) == (1.0, 0.0) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import cmath def convert(numbers): return cmath.polar(numbers) ```
Mbpp/253
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function that returns the number of integer elements in a given list assert count_integer([1,2,'abc',1.2]) == 2 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def count_integer(list1): return sum(isinstance(x, int) for x in list1) ```
Mbpp/255
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in a list and length n, and generates all combinations (with repetition) of the elements of the list and returns a list with a tuple for each combination assert combinations_colors( ["Red","Green","Blue"],1)==[('Red',), ('Green',), ('Blue',)] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python from itertools import combinations_with_replacement def combinations_colors(l, n): return list(combinations_with_replacement(l, n)) ```
Mbpp/256
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function that takes in a non-negative number and returns the number of prime numbers less than the given non-negative number assert count_Primes_nums(5) == 2 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def count_Primes_nums(n): return sum(all(i % j != 0 for j in range(2, i)) for i in range(2, n)) ```
Mbpp/257
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in two numbers and returns a tuple with the second number and then the first number assert swap_numbers(10,20)==(20,10) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def swap_numbers(a,b): return (b, a) ```
Mbpp/259
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to maximize the given two tuples assert maximize_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((6, 7), (4, 9), (2, 9), (7, 10)) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def maximize_elements(test_tup1, test_tup2): return tuple((max(a, c), max(b, d)) for (a, b), (c, d) in zip(test_tup1, test_tup2)) ```
Mbpp/260
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the nth newman–shanks–williams prime number assert newman_prime(3) == 7 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def newman_prime(n): if n == 0 or n == 1: return 1 a = 1 b = 1 c = 1 for _ in range(2, n + 1): c = 2 * b + a a = b b = c return c ```
Mbpp/261
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in two tuples and performs mathematical division operation element-wise across the given tuples assert division_elements((10, 4, 6, 9),(5, 2, 3, 3)) == (2, 2, 2, 3) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def division_elements(test_tup1, test_tup2): return tuple(ele1 / ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) ```
Mbpp/262
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in a list and an integer L and splits the given list into two parts where the length of the first part of the list is L, and returns the resulting lists in a tuple assert split_two_parts([1,1,2,3,4,4,5,1],3)==([1, 1, 2], [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 split_two_parts(list1, L): return list1[:L], list1[L:] ```
Mbpp/264
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to calculate a dog's age in dog's years assert dog_age(12)==61 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def dog_age(h_age): if h_age <= 2: d_age = h_age * 10.5 else: d_age = 21 + (h_age - 2) * 4 return d_age ```
Mbpp/265
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in a list and an integer n and splits a list for every nth element, returning a list of the resulting lists assert list_split(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'],3)==[['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def list_split(S, step): return [S[i::step] for i in range(step)] ```
Mbpp/266
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the lateral surface area of a cube given its side length assert lateralsurface_cube(5)==100 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def lateralsurface_cube(l): return 4 * l * l ```
Mbpp/267
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function that takes in an integer n and returns the sum of the squares of the first n odd natural numbers assert square_Sum(2) == 10 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def square_Sum(n): return n * (4 * n * n - 1) / 3 ```
Mbpp/268
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the n'th star number assert find_star_num(3) == 37 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find_star_num(n): return 6 * n * (n - 1) + 1 ```
Mbpp/269
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the ascii value of a character assert ascii_value('A')==65 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def ascii_value(k): return ord(k) ```
Mbpp/270
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 numbers at even positions of a list assert sum_even_and_even_index([5, 6, 12, 1, 18, 8]) == 30 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def sum_even_and_even_index(arr): return sum(x for x in arr[::2] if x % 2 == 0) ```
Mbpp/271
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function that takes in an integer n and finds the sum of the first n even natural numbers that are raised to the fifth power assert even_Power_Sum(2) == 1056 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def even_Power_Sum(n): return sum(x ** 5 for x in range(2, 2 * n + 1, 2)) ```
Mbpp/272
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in a list of tuples and returns a list containing the rear element of each tuple assert rear_extract([(1, 'Rash', 21), (2, 'Varsha', 20), (3, 'Kil', 19)]) == [21, 20, 19] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def rear_extract(test_list): return [x[-1] for x in test_list] ```
Mbpp/273
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in two tuples and subtracts the elements of the first tuple by the elements of the second tuple with the same index assert substract_elements((10, 4, 5), (2, 5, 18)) == (8, -1, -13) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def substract_elements(test_tup1, test_tup2): return tuple(x - y for x, y in zip(test_tup1, test_tup2)) ```
Mbpp/274
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function that takes in a positive integer n and finds the sum of even index binomial coefficients assert even_binomial_Coeff_Sum(4) == 8 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import math def even_binomial_Coeff_Sum( n): return 1 << (n - 1) ```
Mbpp/276
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in the radius and height of a cylinder and returns the the volume assert math.isclose(volume_cylinder(10,5), 1570.7500000000002, rel_tol=0.001) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import math def volume_cylinder(r,h): return math.pi * r * r * h ```
Mbpp/277
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in a dictionary and integer n and filters the dictionary to only include entries with values greater than or equal to n assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},170)=={'Cierra Vega': 175, 'Alden Cantrell': 180, 'Pierre Cox': 190} ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def dict_filter(dict1, n): return {key : value for (key, value) in dict1.items() if value >=n} ```
Mbpp/278
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the number of elements that occurs before the tuple element in the given tuple assert count_first_elements((1, 5, 7, (4, 6), 10) ) == 3 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def count_first_elements(test_tup): for count, ele in enumerate(test_tup): if isinstance(ele, tuple): break return count ```
Mbpp/279
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the nth decagonal number assert is_num_decagonal(3) == 27 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def is_num_decagonal(n): return 4 * n * n - 3 * n ```
Mbpp/280
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in an array and element and returns a tuple containing a boolean that indicates if the element is in the array and the index position of the element (or -1 if the element is not found) assert sequential_search([11,23,58,31,56,77,43,12,65,19],31) == (True, 3) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def sequential_search(dlist, item): return item in dlist, (dlist.index(item) if item in dlist else -1) ```
Mbpp/281
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to check if the elements of a given list are unique or not assert all_unique([1,2,3]) == True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def all_unique(test_list): return len(test_list) == len(set(test_list)) ```
Mbpp/282
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to subtract two lists element-wise assert sub_list([1, 2, 3],[4,5,6])==[-3,-3,-3] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def sub_list(nums1,nums2): return [num1 - num2 for num1, num2 in zip(nums1, nums2)] ```
Mbpp/283
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function takes in an integer and check whether the frequency of each digit in the integer is less than or equal to the digit itself assert validate(1234) == True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def validate(n): digits = [int(digit) for digit in str(n)] return all(digit >= digits.count(digit) for digit in digits) ```
Mbpp/284
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in a list and element and checks whether all items in the list are equal to the given element assert check_element(["green", "orange", "black", "white"],'blue')==False ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def check_element(list1, element): return all(v == element for v in list1) ```
Mbpp/285
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that checks whether a string contains the 'a' character followed by two or three 'b' characters assert text_match_two_three("ac")==(False) ``` ### 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_two_three(text): patterns = 'ab{2,3}' return re.search(patterns, text) is not None ```
Mbpp/286
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the largest sum of a contiguous array in the modified array which is formed by repeating the given array k times assert max_sub_array_sum_repeated([10, 20, -30, -1], 4, 3) == 30 ``` ### 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_repeated(a, n, k): modifed = a * k pre = 0 # dp[i-1] res = modifed[0] for n in modifed: pre = max(pre + n, n) res = max(pre, res) return res ```
Mbpp/287
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function takes in an integer n and returns the sum of squares of first n even natural numbers assert square_Sum(2) == 20 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def square_Sum(n): return 2 * n * (n + 1) * (2 * n + 1) /3 ```
Mbpp/290
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the list of maximum length in a list of lists assert max_length([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17]) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def max_length(list1): return max([(len(x), x) for x in list1], key=lambda x: x[0]) ```
Mbpp/292
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find quotient of two numbers (rounded down to the nearest integer) assert find(10,3) == 3 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find(n,m): return n // m ```
Mbpp/293
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the third side of a right angled triangle assert otherside_rightangle(7,8)==10.63014581273465 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import math def otherside_rightangle(w,h): return math.sqrt(w * w + h * h) ```
Mbpp/294
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the maximum value in a given heterogeneous list assert max_val(['Python', 3, 2, 4, 5, 'version'])==5 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def max_val(listval): max_val = max(i for i in listval if isinstance(i, int)) return max_val ```
Mbpp/296
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to count inversions in an array assert get_Inv_Count([1,20,6,4,5]) == 5 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def get_Inv_Count(arr): # consider use merge sort, but for simplicity, use brute force inv_count = 0 for i in range(len(arr)): for j in range(i + 1, len(arr)): if (arr[i] > arr[j]): inv_count += 1 return inv_count ```
Mbpp/297
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to flatten a given nested list structure assert flatten_list([0, 10, [20, 30], 40, 50, [60, 70, 80], [90, 100, 110, 120]])==[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def flatten_list(list1): result = [] for item in list1: if isinstance(item, list): result.extend(flatten_list(item)) else: result.append(item) return result ```
Mbpp/299
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to calculate the maximum aggregate from the list of tuples assert max_aggregate([('Juan Whelan',90),('Sabah Colley',88),('Peter Nichols',7),('Juan Whelan',122),('Sabah Colley',84)])==('Juan Whelan', 212) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python from collections import defaultdict def max_aggregate(stdata): temp = defaultdict(int) for name, marks in stdata: temp[name] += marks return max(temp.items(), key=lambda x: x[1]) ```
Mbpp/300
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the count of all binary sequences of length 2n such that sum of first n bits is same as sum of last n bits assert math.isclose(count_binary_seq(1), 2.0, rel_tol=0.001) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def count_binary_seq(n): nCr = 1 res = 1 for r in range(1, n + 1): nCr = (nCr * (n + 1 - r)) / r res += nCr * nCr return res ```
Mbpp/301
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the depth of a dictionary assert dict_depth({'a':1, 'b': {'c': {'d': {}}}})==4 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def dict_depth_aux(d): if isinstance(d, dict): return 1 + (max(map(dict_depth_aux, d.values())) if d else 0) return 0 def dict_depth(d): return dict_depth_aux(d) ```
Mbpp/305
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to return two words from a list of words starting with letter 'p' assert start_withp(["Python PHP", "Java JavaScript", "c c++"])==('Python', 'PHP') ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import re def start_withp(words): for w in words: m = re.match("(P\w+)\W(P\w+)", w) if m: return m.groups() ```
Mbpp/306
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the maximum sum of increasing subsequence from prefix until ith index and also including a given kth element which is after i, i assert max_sum_increasing_subseq([1, 101, 2, 3, 100, 4, 5 ], 7, 4, 6) == 11 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def max_sum_increasing_subseq(a, n, index, k): dp = [[0 for _ in range(n)] for _ in range(n)] for i in range(n): if a[i] > a[0]: dp[0][i] = a[i] + a[0] else: dp[0][i] = a[i] for i in range(1, n): for j in range(n): if a[j] > a[i] and j > i: if dp[i - 1][i] + a[j] > dp[i - 1][j]: dp[i][j] = dp[i - 1][i] + a[j] else: dp[i][j] = dp[i - 1][j] else: dp[i][j] = dp[i - 1][j] return dp[index][k] ```
Mbpp/308
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the specified number of largest products from two given lists, selecting one factor from each list assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],3)==[60, 54, 50] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def large_product(nums1, nums2, N): result = sorted([x*y for x in nums1 for y in nums2], reverse=True)[:N] return result ```
Mbpp/309
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find the maximum of two numbers assert maximum(5,10) == 10 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def maximum(a,b): return max(a, b) ```
Mbpp/310
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to convert a given string to a tuple of characters assert string_to_tuple("python 3.0")==('p', 'y', 't', 'h', 'o', 'n', '3', '.', '0') ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def string_to_tuple(str1): result = tuple(x for x in str1 if not x.isspace()) return result ```
Mbpp/311
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to set the left most unset bit assert set_left_most_unset_bit(10) == 14 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def set_left_most_unset_bit(n): if not (n & (n + 1)): return n pos, temp, count = 0, n, 0 while temp: if not (temp & 1): pos = count count += 1 temp >>= 1 return (n | (1 << (pos))) ```
Mbpp/312
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the volume of a cone assert math.isclose(volume_cone(5,12), 314.15926535897927, rel_tol=0.001) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import math def volume_cone(r,h): return (1.0 / 3) * math.pi * r * r * h ```
Mbpp/388
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find the highest power of 2 that is less than or equal to n assert highest_Power_of_2(10) == 8 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def highest_Power_of_2(n): i = 0 while ((1 << i) <= n): i += 1 return (1 << (i - 1)) ```
Mbpp/389
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the n'th lucas number assert find_lucas(9) == 76 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find_lucas(n): if (n == 0): return 2 if (n == 1): return 1 return find_lucas(n - 1) + find_lucas(n - 2) ```
Mbpp/390
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to apply a given format string to all of the elements in a list assert add_string([1,2,3,4],'temp{0}')==['temp1', 'temp2', 'temp3', 'temp4'] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def add_string(list_, string): return [string.format(i) for i in list_] ```
Mbpp/391
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to convert more than one list to nested dictionary assert convert_list_dictionary(["S001", "S002", "S003", "S004"],["Adina Park", "Leyton Marsh", "Duncan Boyle", "Saim Richards"] ,[85, 98, 89, 92])==[{'S001': {'Adina Park': 85}}, {'S002': {'Leyton Marsh': 98}}, {'S003': {'Duncan Boyle': 89}}, {'S004': {'Saim Richards': 92}}] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def convert_list_dictionary(l1, l2, l3): result = [{x: {y: z}} for (x, y, z) in zip(l1, l2, l3)] return result ```
Mbpp/392
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the maximum sum possible by using the given equation f(n) = max( (f(n/2) + f(n/3) + f(n/4) + f(n/5)), n) assert get_max_sum(60) == 106 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def get_max_sum (n): # if n = 0, f(0) = max(5(f(0), 0)), so f(0) = 5f(0) or f(0) = 0, for both cases f(0) = 0 res = [0] for i in range(1, n + 1): res.append(max(res[i // 2] + res[i // 3] + res[i // 4] + res[i // 5], i)) return res[n] ```
Mbpp/394
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to check if given tuple contains no duplicates assert check_distinct((1, 4, 5, 6, 1, 4)) == False ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def check_distinct(test_tup): return len(test_tup) == len(set(test_tup)) ```
Mbpp/395
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 non-repeated character in a given string assert first_non_repeating_character("abcabc") == None ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def first_non_repeating_character(str1): for ch in str1: if str1.count(ch) == 1: return ch return None ```
Mbpp/397
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 three numbers assert median_numbers(25,55,65)==55.0 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def median_numbers(a,b,c): return sorted([a,b,c])[1] ```
Mbpp/398
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to compute the sum of digits of each number of a given list assert sum_of_digits([10,2,56])==14 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def sum_of_digits(nums): return sum(int(el) for n in nums for el in str(n) if el.isdigit()) ```
Mbpp/404
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find the minimum of two numbers assert minimum(1,2) == 1 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def minimum(a,b): return min(a,b) ```
Mbpp/405
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to check whether an element exists within a tuple assert check_tuplex(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),'r')==True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def check_tuplex(tuplex, element): return element in tuplex ```
Mbpp/406
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find whether the parity of a given number is odd assert find_Parity(12) == False ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find_Parity(x): return x % 2 != 0 ```
Mbpp/409
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the minimum product from the pairs of tuples within a given list assert min_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==8 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def min_product_tuple(list1): return min(x * y for x, y in list1) ```
Mbpp/410
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the minimum value in a given heterogeneous list assert min_val(['Python', 3, 2, 4, 5, 'version'])==2 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def min_val(listval): min_val = min(i for i in listval if isinstance(i, int)) return min_val ```
Mbpp/412
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to remove odd numbers from a given list assert remove_odd([1,2,3]) == [2] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def remove_odd(l): return [i for i in l if i % 2 == 0] ```
Mbpp/413
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to extract the nth element from a given list of tuples assert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,0)==['Greyson Fulton', 'Brady Kent', 'Wyatt Knott', 'Beau Turnbull'] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def extract_nth_element(list1, n): return [x[n] for x in list1] ```
Mbpp/414
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to check whether any value in a sequence exists in a sequence or not assert overlapping([1,2,3,4,5],[6,7,8,9]) == False ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def overlapping(list1,list2): return any(v in list2 for v in list1) ```
Mbpp/415
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find a pair with highest product from a given array of integers assert max_Product([1,2,3,4,7,0,8,4]) == (7,8) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def max_Product(arr): pairs = [(a, b) for a in arr for b in arr if a != b] return max(pairs, key=lambda x: x[0] * x[1]) ```
Mbpp/418
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find the element of a list having maximum length assert Find_Max([['A'],['A','B'],['A','B','C']]) == ['A','B','C'] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def Find_Max(lst): return max(lst, key = len) ```
Mbpp/419
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to round every number of a given list of numbers and print the total sum multiplied by the length of the list assert round_and_sum([22.4, 4.0, -16.22, -9.10, 11.00, -12.22, 14.20, -5.20, 17.50])==243 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def round_and_sum(list1): l = len(list1) return sum([round(i) for i in list1]) * l ```
Mbpp/420
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find the cube sum of first n even natural numbers assert cube_Sum(2) == 72 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def cube_Sum(n): return 2 * (n ** 2) * ((n + 1) ** 2) ```
Mbpp/421
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to concatenate each element of tuple by the delimiter assert concatenate_tuple(("ID", "is", 4, "UTS") ) == 'ID-is-4-UTS' ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def concatenate_tuple(test_tup): delim = "-" res = ''.join([str(ele) + delim for ele in test_tup]) res = res[ : len(res) - len(delim)] return (str(res)) ```
Mbpp/422
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find the average of cubes of first n natural numbers assert find_Average_Of_Cube(2) == 4.5 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find_Average_Of_Cube(n): return sum([(i ** 3) for i in range(1, n + 1)]) / n ```
Mbpp/424
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to extract only the rear index element of each string in the given tuple assert extract_rear(('Mers', 'for', 'Vers') ) == ['s', 'r', 's'] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def extract_rear(test_tuple): return [ele[-1] for ele in test_tuple] ```
Mbpp/425
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to count the number of sublists containing a particular element assert count_element_in_list([[1, 3], [5, 7], [1, 11], [1, 15, 7]],1)==3 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def count_element_in_list(list1, x): return sum(x in sublist for sublist in list1) ```
Mbpp/426
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to filter odd numbers assert filter_oddnumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def filter_oddnumbers(nums): return [n for n in nums if n % 2 == 1] ```
Mbpp/427
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format assert change_date_format("2026-01-02") == '02-01-2026' ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import re def change_date_format(dt): return re.sub(r'(\d{4})-(\d{1,2})-(\d{1,2})', '\\3-\\2-\\1', dt) ```
Mbpp/428
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to sort the given array by using shell sort assert shell_sort([12, 23, 4, 5, 3, 2, 12, 81, 56, 95]) == [2, 3, 4, 5, 12, 12, 23, 56, 81, 95] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def shell_sort(my_list): gap = len(my_list) // 2 while gap > 0: for i in range(gap, len(my_list)): current_item = my_list[i] j = i while j >= gap and my_list[j - gap] > current_item: my_list[j] = my_list[j - gap] j -= gap my_list[j] = current_item gap //= 2 return my_list ```
Mbpp/429
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to extract the elementwise and tuples from the given two tuples assert and_tuples((10, 4, 6, 9), (5, 2, 3, 3)) == (0, 0, 2, 1) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def and_tuples(test_tup1, test_tup2): return tuple(x & y for x, y in zip(test_tup1, test_tup2)) ```
Mbpp/430
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the directrix of a parabola assert parabola_directrix(5,3,2)==-198 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def parabola_directrix(a, b, c): return ((int)(c - ((b * b) + 1) * 4 * a )) ```
Mbpp/432
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the median length of a trapezium assert median_trapezium(15,25,35)==20 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def median_trapezium(base1,base2,height): return (base1 + base2) / 2 ```
Mbpp/433
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to check whether the entered number is greater than the elements of the given array assert check_greater([1, 2, 3, 4, 5], 4) == False ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def check_greater(arr, number): return all(number > el for el in arr) ```
Mbpp/435
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 of a given number assert last_Digit(123) == 3 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def last_Digit(n) : if n < 0: n = -n return n % 10 ```
Mbpp/436
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to return the negative numbers in a list assert neg_nos([-1,4,5,-6]) == [-1,-6] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def neg_nos(list1): return [i for i in list1 if i < 0] ```
Mbpp/437
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to remove odd characters in a string assert remove_odd("python")==("yhn") ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def remove_odd(str1): return str1[1::2] ```