task_id
stringlengths
6
8
text
stringlengths
368
1.62k
Mbpp/2
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the shared elements from the given two lists assert set(similar_elements((3, 4, 5, 6),(5, 7, 4, 10))) == set((4, 5)) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def similar_elements(test_tup1, test_tup2): return tuple(set(test_tup1) & set(test_tup2)) ```
Mbpp/3
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to identify non-prime numbers assert is_not_prime(2) == False ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import math def is_not_prime(n): if n == 1: return True for i in range(2, int(math.sqrt(n))+1): if n % i == 0: return True return False ```
Mbpp/4
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the n largest integers from a given list of numbers, returned in descending order assert heap_queue_largest( [25, 35, 22, 85, 14, 65, 75, 22, 58],3)==[85, 75, 65] ``` ### 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_queue_largest(nums: list,n: int) -> list: largest_nums = hq.nlargest(n, nums) return largest_nums ```
Mbpp/6
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 two numbers differ at one bit position only or not assert differ_At_One_Bit_Pos(13,9) == True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def is_Power_Of_Two(x: int): return x > 0 and (x & (x - 1)) == 0 def differ_At_One_Bit_Pos(a: int,b: int): return is_Power_Of_Two(a ^ b) ```
Mbpp/7
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find all words which are at least 4 characters long in a string assert set(find_char_long('Please move back to stream')) == set(['Please', 'move', 'back', 'stream']) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import re def find_char_long(text): return (re.findall(r"\b\w{4,}\b", text)) ```
Mbpp/8
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find squares of individual elements in a list assert square_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[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 square_nums(nums): return [i**2 for i in nums] ```
Mbpp/9
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 number of rotations (greater than 0) required to get the same string assert find_Rotations("aaaa") == 1 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find_Rotations(s): n = len(s) s += s for i in range(1, n + 1): if s[i: i + n] == s[0: n]: return i return n ```
Mbpp/11
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to remove first and last occurrence of a given character from the string assert remove_Occ("hello","l") == "heo" ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def remove_Occ(s,ch): s = s.replace(ch, '', 1) s = s[::-1].replace(ch, '', 1)[::-1] return s ```
Mbpp/12
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to sort a given matrix in ascending order according to the sum of its rows assert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def sort_matrix(M): result = sorted(M, key=sum) return result ```
Mbpp/14
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find the volume of a triangular prism assert find_Volume(10,8,6) == 240 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find_Volume(l,b,h) : return ((l * b * h) / 2) ```
Mbpp/16
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to that returns true if the input string contains sequences of lowercase letters joined with an underscore and false otherwise assert text_lowercase_underscore("aab_cbbbc")==(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_lowercase_underscore(text): return bool(re.match('^[a-z]+(_[a-z]+)*$', text)) ```
Mbpp/17
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that returns the perimeter of a square given its side length as input assert square_perimeter(10)==40 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def square_perimeter(a): return 4*a ```
Mbpp/18
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to remove characters from the first string which are present in the second string assert remove_dirty_chars("probasscurve", "pros") == 'bacuve' ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def remove_dirty_chars(string, second_string): for char in second_string: string = string.replace(char, '') return string ```
Mbpp/19
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find whether a given array of integers contains any duplicate element assert test_duplicate(([1,2,3,4,5]))==False ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def test_duplicate(arraynums): return len(arraynums) != len(set(arraynums)) ```
Mbpp/20
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 number is woodball or not assert is_woodall(383) == True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def is_woodall(x): if not isinstance(x, int): return False if x <= 0 or x % 2 == 0: return False if (x == 1): return True x += 1 i = 0 while (x % 2 == 0): x /= 2 i += 1 if (i == x): return True return False ```
Mbpp/56
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to check if a given number is one less than twice its reverse assert check(70) == False ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def check(n): return n == 2 * int(str(n)[::-1]) - 1 ```
Mbpp/57
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find the largest number that can be formed with the given list of digits assert find_Max_Num([1,2,3]) == 321 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find_Max_Num(arr) : arr.sort(reverse = True) return int("".join(map(str,arr))) ```
Mbpp/58
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 two integers have opposite sign or not assert opposite_Signs(1,-2) == True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def opposite_Signs(x,y): return ((x ^ y) < 0) ```
Mbpp/59
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the nth octagonal number assert is_octagonal(5) == 65 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def is_octagonal(n): return 3 * n * n - 2 * n ```
Mbpp/61
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 substrings with the sum of digits equal to their length assert count_Substrings('112112') == 6 ``` ### 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 count_Substrings(s): n, count, sum = len(s), 0, 0 mp = defaultdict(lambda : 0) mp[0] += 1 for i in range(n): sum += ord(s[i]) - ord('0') count += mp[sum - i - 1] mp[sum - i - 1] += 1 return count ```
Mbpp/62
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find smallest number in a list assert smallest_num([10, 20, 1, 45, 99]) == 1 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def smallest_num(xs): assert len(xs) > 0, "invalid inputs" return min(xs) ```
Mbpp/63
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the maximum difference between available pairs in the given tuple list assert max_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 7 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def max_difference(test_list): return max(abs(a - b) for a, b in test_list) ```
Mbpp/64
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to sort a list of tuples using the second value of each tuple assert subject_marks([('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])==[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def subject_marks(subjectmarks): #subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]) subjectmarks.sort(key = lambda x: x[1]) return subjectmarks ```
Mbpp/65
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to flatten a list and sum all of its elements assert recursive_list_sum(([1, 2, [3,4],[5,6]]))==21 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def recursive_list_sum(data_list): total = 0 for element in data_list: if type(element) == type([]): total = total + recursive_list_sum(element) else: total = total + element return total ```
Mbpp/66
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 positive numbers in a list assert pos_count([1,-2,3,-4]) == 2 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def pos_count(l): return len([x for x in l if x > 0]) ```
Mbpp/67
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 ways to partition a set of Bell numbers 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/68
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 array is monotonic or not assert is_Monotonic([6, 5, 4, 4]) == True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def is_Monotonic(A): return all(a <= b for a, b in zip(A, A[1:])) or all(a >= b for a, b in zip(A, A[1:])) ```
Mbpp/69
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to check whether a list contains the given sublist or not assert is_sublist([2,4,3,5,7],[3,7])==False ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def is_sublist(l, s): if len(l) < len(s): return False return any(l[i:i+len(s)] == s for i in range(len(l)-len(s)+1)) ```
Mbpp/70
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find whether all the given tuples have equal length or not assert get_equal([(11, 22, 33), (44, 55, 66)]) == True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def get_equal(Input): return len(set(len(item) for item in Input)) == 1 ```
Mbpp/71
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to sort a list of elements assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def comb_sort(nums): n = len(nums) gap = n shrink = 1.3 swapped = True while gap > 1 or swapped: gap = int(gap / shrink) if gap < 1: gap = 1 swapped = False for i in range(n - gap): if nums[i] > nums[i + gap]: nums[i], nums[i + gap] = nums[i + gap], nums[i] swapped = True return nums ```
Mbpp/72
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 can be represented as the difference of two squares or not assert dif_Square(5) == True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def dif_Square(n): # see https://www.quora.com/Which-numbers-can-be-expressed-as-the-difference-of-two-squares return n % 4 != 2 ```
Mbpp/74
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to check whether it follows the sequence given in the patterns array assert is_samepatterns(["red","green","green"], ["a", "b", "b"])==True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def is_samepatterns(colors, patterns): if len(colors) != len(patterns): return False pattern_color_dict = {pattern: set() for pattern in patterns} for color, pattern in zip(colors, patterns): pattern_color_dict[pattern].add(color) return all(len(pattern_color_dict[pattern]) == 1 for pattern in patterns) ```
Mbpp/75
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find tuples which have all elements divisible by k from the given list of tuples assert find_tuples([(6, 24, 12), (7, 9, 6), (12, 18, 21)], 6) == [(6, 24, 12)] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find_tuples(test_list, K): res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)] return res ```
Mbpp/77
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find whether a number is divisible by 11 assert is_Diff (12345) == False ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def is_Diff(n): return n % 11 == 0 ```
Mbpp/79
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 length of the word is odd or not assert word_len("Hadoop") == False ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def word_len(s): return len(s) % 2 == 1 ```
Mbpp/80
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the nth tetrahedral number assert tetrahedral_number(5) == 35 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def tetrahedral_number(n): return (n * (n + 1) * (n + 2)) / 6 ```
Mbpp/82
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 sphere assert math.isclose(volume_sphere(10), 4188.790204786391, 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_sphere(r): return (4./3.) * math.pi * (r**3) ```
Mbpp/84
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the nth number in the newman conway sequence assert sequence(10) == 6 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def sequence(n): if n == 1 or n == 2: return 1 seq = [0] * (n + 1) seq[1] = seq[2] = 1 for i in range(3, n + 1): seq[i] = seq[seq[i - 1]] + seq[i - seq[i - 1]] return seq[n] ```
Mbpp/85
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 sphere assert math.isclose(surfacearea_sphere(10), 1256.6370614359173, 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 surfacearea_sphere(r): return 4 * math.pi * (r**2) ```
Mbpp/86
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find nth centered hexagonal number assert centered_hexagonal_number(10) == 271 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def centered_hexagonal_number(n): return 3 * n * (n - 1) + 1 ```
Mbpp/87
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to merge three dictionaries into a single dictionary assert merge_dictionaries_three({ "R": "Red", "B": "Black", "P": "Pink" }, { "G": "Green", "W": "White" },{ "O": "Orange", "W": "White", "B": "Black" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White', 'O': 'Orange'} ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import collections as ct def merge_dictionaries_three(dict1,dict2, dict3): merged_dict = dict(ct.ChainMap({},dict1,dict2,dict3)) return merged_dict ```
Mbpp/88
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to get the frequency of all the elements in a list, returned as a dictionary assert freq_count([10,10,10,10,20,20,20,20,40,40,50,50,30])==({10: 4, 20: 4, 40: 2, 50: 2, 30: 1}) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import collections def freq_count(list1): freq_count= collections.Counter(list1) return freq_count ```
Mbpp/89
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the closest smaller number than n assert closest_num(11) == 10 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def closest_num(N): return (N - 1) ```
Mbpp/90
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 word assert len_log(["python","PHP","bigdata"]) == 7 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def len_log(list1): return max(len(x) for x in list1) ```
Mbpp/91
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to check if a string is present as a substring in a given list of string values assert find_substring(["red", "black", "white", "green", "orange"],"ack")==True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find_substring(str1, sub_str): return any(sub_str in s for s in str1) ```
Mbpp/92
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 undulating or not assert is_undulating(1212121) == True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def is_undulating(n): digits = [int(digit) for digit in str(n)] if len(set(digits)) != 2: return False return all(a != b for a, b in zip(digits, digits[1:])) ```
Mbpp/93
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to calculate the value of 'a' to the power 'b' assert power(3,4) == 81 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def power(a, b): return a ** b ```
Mbpp/94
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Given a list of tuples, write a function that returns the first value of the tuple with the smallest second value assert index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]) == 'Varsha' ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python from operator import itemgetter def index_minimum(test_list): res = min(test_list, key = itemgetter(1))[0] return (res) ```
Mbpp/95
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 smallest list in a list of lists assert Find_Min_Length([[1],[1,2]]) == 1 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def Find_Min_Length(lst): minLength = min(len(x) for x in lst ) return minLength ```
Mbpp/96
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find the number of divisors of a given integer assert divisor(15) == 4 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def divisor(n): return sum(1 for i in range(1, n + 1) if n % i == 0) ```
Mbpp/97
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find frequency of each element in a flattened list of lists, returned in a dictionary assert frequency_lists([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]])=={1: 1, 2: 3, 3: 1, 4: 1, 5: 2, 6: 1, 7: 1, 8: 1, 9: 1} ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def frequency_lists(list1): list1 = [item for sublist in list1 for item in sublist] return {x: list1.count(x) for x in list1} ```
Mbpp/98
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to multiply all the numbers in a list and divide with the length of the list assert math.isclose(multiply_num((8, 2, 3, -1, 7)), -67.2, 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 multiply_num(numbers): from functools import reduce return reduce(lambda x, y: x * y, numbers) / len(numbers) ```
Mbpp/99
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to convert the given decimal number to its binary equivalent, represented as a string with no leading zeros assert decimal_to_binary(8) == '1000' ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def decimal_to_binary(n): return bin(n).replace("0b","") ```
Mbpp/100
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the next smallest palindrome of a specified integer, returned as an integer assert next_smallest_palindrome(99)==101 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def next_smallest_palindrome(num): if all(digit == '9' for digit in str(num)): return num + 2 else: num = [int(digit) for digit in str(num)] n = len(num) mid = n // 2 left_smaller = False # if n is odd, ignore the middle digit at first i = mid - 1 j = mid + 1 if n % 2 else mid while i >= 0 and num[i] == num[j]: i -= 1 j += 1 # stop if traverse end or difference found if i < 0 or num[i] < num[j]: left_smaller = True # copy left to right while i >= 0: num[j] = num[i] j += 1 i -= 1 # the middle digit must be incremented if left_smaller: carry = 1 i = mid - 1 if n % 2: num[mid] += carry carry = num[mid] // 10 num[mid] %= 10 j = mid + 1 else: j = mid while i >= 0: num[i] += carry carry = num[i] // 10 num[i] %= 10 num[j] = num[i] j += 1 i -= 1 return int("".join(map(str, num))) ```
Mbpp/101
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the kth element in the given array using 1-based indexing assert kth_element([12,3,5,7,19], 2) == 3 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def kth_element(arr, k): return arr[k-1] ```
Mbpp/102
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to convert a snake case string to camel case string assert snake_to_camel('python_program')=='PythonProgram' ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def snake_to_camel(word): return ''.join(x.capitalize() or '_' for x in word.split('_')) ```
Mbpp/103
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the Eulerian number a(n, m) assert eulerian_num(3, 1) == 4 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def eulerian_num(n, m): if (m >= n or n == 0): return 0 if (m == 0): return 1 return (n - m) * eulerian_num(n - 1, m - 1) + (m + 1) * eulerian_num(n - 1, m) ```
Mbpp/104
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/105
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to count true booleans in the given list assert count([True,False,True]) == 2 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def count(lst): return sum(lst) ```
Mbpp/106
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to append the given list to the given tuples assert add_lists([5, 6, 7], (9, 10)) == (9, 10, 5, 6, 7) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def add_lists(test_list, test_tup): return test_tup + tuple(test_list) ```
Mbpp/108
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to merge three lists into a single sorted list assert merge_sorted_list([25, 24, 15, 4, 5, 29, 110],[19, 20, 11, 56, 25, 233, 154],[24, 26, 54, 48])==[4, 5, 11, 15, 19, 20, 24, 24, 25, 25, 26, 29, 48, 54, 56, 110, 154, 233] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import heapq def merge_sorted_list(num1,num2,num3): return sorted(num1 + num2 + num3) ```
Mbpp/109
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find the number of numbers with an odd value when rotating a binary string the given number of times assert odd_Equivalent("011001",6) == 3 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def odd_Equivalent(s,n): count=0 for i in range(0,n): if (s[i] == '1'): count = count + 1 return count ```
Mbpp/111
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the common elements in given nested lists assert set(common_in_nested_lists([[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]]))==set([18, 12]) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def common_in_nested_lists(nestedlist): return list(set.intersection(*map(set, nestedlist))) ```
Mbpp/113
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to check if a string represents an integer or not assert check_integer("python")==False ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def check_integer(text): text = text.strip() if len(text) < 1: return None else: if text[0] in '+-': text = text[1:] return text.isdigit() ```
Mbpp/116
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to convert a given tuple of positive integers into a single integer assert tuple_to_int((1,2,3))==123 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def tuple_to_int(nums): return int(''.join(map(str,nums))) ```
Mbpp/118
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to convert a string to a list of strings split on the space character assert string_to_list("python programming")==['python','programming'] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def string_to_list(string): return string.split(" ") ```
Mbpp/119
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 that appears only once in a sorted array assert search([1,1,2,2,3]) == 3 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def search(arr): n = len(arr) XOR = 0 for i in range(n) : XOR = XOR ^ arr[i] return (XOR) ```
Mbpp/120
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the maximum absolute product between numbers in pairs of tuples within a given list assert max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==36 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def max_product_tuple(list1): return max(abs(x * y) for x, y in list1) ```
Mbpp/123
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to sum all amicable numbers from 1 to a specified number assert amicable_numbers_sum(999)==504 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def div_sum(num): res = 1 i = 2 while i * i <= num: if num % i == 0: res += i if i * i != num: res += num / i i += 1 return res def amicable_numbers_sum(limit): amicables = set() for num in range(2, limit + 1): if num in amicables: continue sum_fact = div_sum(num) sum_fact2 = div_sum(sum_fact) if num == sum_fact2 and num != sum_fact: amicables.add(num) amicables.add(sum_fact2) return sum(amicables) ```
Mbpp/124
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to get the angle of a complex number assert math.isclose(angle_complex(0,1j), 1.5707963267948966, 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 cmath def angle_complex(a,b): angle=cmath.phase(a+b) return angle ```
Mbpp/125
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string assert find_length("11000010001") == 6 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find_length(string): current_sum = 0 max_sum = 0 for c in string: current_sum += 1 if c == '0' else -1 if current_sum < 0: current_sum = 0 max_sum = max(current_sum, max_sum) return max_sum ```
Mbpp/126
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 common divisors of two given numbers assert sum(10,15) == 6 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python import math def sum(a,b): sum = 0 n = math.gcd(a, b) N = int(math.sqrt(n)) + 1 for i in range (1, N): if (n % i == 0): sum += i if (n / i != i): sum += (n / i) return sum ```
Mbpp/127
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to multiply two integers assert multiply_int(10,20)==200 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def multiply_int(x, y): return x * y ```
Mbpp/128
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find words that are longer than n characters from a given list of words assert long_words(3,"python is a programming language")==['python','programming','language'] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def long_words(n, s): return list(filter(lambda x: len(x) > n, s.split(' '))) ```
Mbpp/129
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to calculate whether the matrix is a magic square assert magic_square_test([[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]])==True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def magic_square_test(my_matrix): s = sum(my_matrix[0]) # row if any(sum(row) != s for row in my_matrix): return False # column if any(sum(row[i] for row in my_matrix) != s for i in range(len(my_matrix[0]))): return False # diagonal if sum(my_matrix[i][i] for i in range(len(my_matrix))) != s: return False # anti-diagonal if sum(my_matrix[i][len(my_matrix) - i - 1] for i in range(len(my_matrix))) != s: return False return True ```
Mbpp/130
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the item with maximum frequency in a given list assert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2])==2 ``` ### 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_occurrences(nums): d = defaultdict(int) for n in nums: d[n] += 1 return max(d, key=d.get) ```
Mbpp/131
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to reverse only the vowels of a given string (where y is not a vowel) assert reverse_vowels("Python") == "Python" ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def reverse_vowels(str1): is_vowel = lambda x: x in 'aeiouAEIOU' pos = [i for i, c in enumerate(str1) if is_vowel(c)] return ''.join(c if not is_vowel(c) else str1[pos.pop()] for c in str1) ```
Mbpp/132
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to convert a tuple to a string assert tup_string(('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's'))==("exercises") ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def tup_string(tup1): return ''.join(tup1) ```
Mbpp/133
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 the negative numbers of a given list of numbers assert sum_negativenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==-32 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def sum_negativenum(nums): return sum(x for x in nums if x < 0) ```
Mbpp/135
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the nth hexagonal number assert hexagonal_num(10) == 190 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def hexagonal_num(n): return n * (2 * n - 1) ```
Mbpp/137
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the ratio of zeroes to non-zeroes in an array of integers assert math.isclose(zero_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8]), 0.181818, 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 zero_count(nums): if all(x == 0 for x in nums): return float('inf') return sum(x == 0 for x in nums) / sum(x != 0 for x in nums) ```
Mbpp/138
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 can be represented as sum of non-zero powers of 2 or not assert is_Sum_Of_Powers_Of_Two(10) == True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def is_Sum_Of_Powers_Of_Two(n): return n > 0 and n % 2 == 0 ```
Mbpp/139
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the circumference of a circle assert math.isclose(circle_circumference(10), 62.830000000000005, 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 circle_circumference(r): return 2 * math.pi * r ```
Mbpp/140
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to flatten the list of lists into a single set of numbers assert set(extract_singly([(3, 4, 5), (4, 5, 7), (1, 4)])) == set([3, 4, 5, 7, 1]) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def extract_singly(test_list): return set([item for sublist in test_list for item in sublist]) ```
Mbpp/141
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to sort a list of elements assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def comb_sort(nums): n = len(nums) gap = n shrink = 1.3 swapped = True while gap > 1 or swapped: gap = int(gap / shrink) if gap < 1: gap = 1 swapped = False for i in range(n - gap): if nums[i] > nums[i + gap]: nums[i], nums[i + gap] = nums[i + gap], nums[i] swapped = True return nums ```
Mbpp/142
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to count number items that are identical in the same position of three given lists assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,9],[2,1,3,1,2,6,7,9])==3 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def count_samepair(list1,list2,list3): return sum(m == n == o for m, n, o in zip(list1,list2,list3)) ```
Mbpp/145
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 difference between any two elements in a given array assert max_Abs_Diff((2,1,5,3)) == 4 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def max_Abs_Diff(arr): return max(arr) - min(arr) ```
Mbpp/160
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that returns integers x and y that satisfy ax + by = n as a tuple, or return None if no solution exists assert find_solution(2, 3, 7) == (2, 1) ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find_solution(a, b, n): i = 0 while i * a <= n: if (n - (i * a)) % b == 0: return (i, (n - (i * a)) // b) i = i + 1 return None ```
Mbpp/161
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to remove all elements from a given list present in another list assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 4, 6, 8]) == [1, 3, 5, 7, 9, 10] ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def remove_elements(list1, list2): return [x for x in list1 if x not in list2] ```
Mbpp/162
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to calculate the sum (n - 2*i) from i=0 to n // 2, for instance n + (n-2) + (n-4) assert sum_series(6) == 12 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def sum_series(n): if n <= 0: return 0 return sum(n - 2 * i for i in range(n // 2 + 1)) ```
Mbpp/165
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 characters in a string that occur at the same position in the string as in the English alphabet (case insensitive) assert count_char_position("xbcefg") == 2 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def count_char_position(str1): return sum(ord(ch.lower()) - ord('a') == i for i, ch in enumerate(str1)) ```
Mbpp/166
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that counts the number of pairs of integers in a list that xor to an even number assert find_even_pair([5, 4, 7, 2, 1]) == 4 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def find_even_pair(A): if len(A) < 2: return 0 return sum((a ^ b) % 2 == 0 for i, a in enumerate(A) for b in A[i + 1:]) ```
Mbpp/167
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a python function to find the smallest power of 2 greater than or equal to n assert next_power_of_2(0) == 1 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def next_power_of_2(n): if n and not n & (n - 1): return n res = 1 while n != 0: n >>= 1 res <<= 1 return res; ```
Mbpp/168
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 occurrences of a number in a given list assert frequency([1,2,3], 4) == 0 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def frequency(a,x): return a.count(x) ```
Mbpp/170
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 numbers in a list within a range specified by two indices assert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 8, 10) == 29 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def sum_range_list(list1, m, n): return sum(list1[m : n + 1]) ```
Mbpp/171
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to find the perimeter of a regular pentagon from the length of its sides assert perimeter_pentagon(5) == 25 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def perimeter_pentagon(a): return 5 * a ```
Mbpp/172
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 occurence of the string 'std' in a given string assert count_occurance("letstdlenstdporstd") == 3 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def count_occurance(s): return s.count('std') ```
Mbpp/222
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function to check if all the elements in tuple have same data type or not assert check_type((5, 6, 7, 3, 5, 6) ) == True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def check_type(test_tuple): return all(isinstance(item, type(test_tuple[0])) for item in test_tuple) ```
Mbpp/223
Please provide a self-contained Python script that solves the following problem in a markdown code block: ``` Write a function that takes in a sorted array, its length (n), and an element and returns whether the element is the majority element in the given sorted array assert is_majority([1, 2, 3, 3, 3, 3, 10], 7, 3) == True ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python from bisect import bisect_left, bisect_right def is_majority(arr, n, x): if x not in arr: return False l = bisect_left(arr, x) r = bisect_right(arr, x) return r - l > n / 2 ```
Mbpp/224
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 set bits (binary digits with value 1) in a given number assert count_Set_Bits(2) == 1 ``` ### Answer: Below is a Python script with a self-contained function that solves the problem and passes corresponding tests: ```python def count_Set_Bits(n): return bin(n)[2:].count('1') ```
README.md exists but content is empty.
Downloads last month
36