Dataset Viewer
Auto-converted to Parquet Duplicate
id
stringlengths
21
23
content
stringlengths
181
2.9k
mbpp_sanitized_data_602
Write a python function to find the first repeated character in a given string. assert first_repeated_char("abcabc") == "a" assert first_repeated_char("abc") == None assert first_repeated_char("123123") == "1" def first_repeated_char(str1): for index,c in enumerate(str1): if str1[:index+1].count(c) > 1: ret...
mbpp_sanitized_data_603
Write a function to get all lucid numbers smaller than or equal to a given integer. assert get_ludic(10) == [1, 2, 3, 5, 7] assert get_ludic(25) == [1, 2, 3, 5, 7, 11, 13, 17, 23, 25] assert get_ludic(45) == [1, 2, 3, 5, 7, 11, 13, 17, 23, 25, 29, 37, 41, 43] def get_ludic(n): ludics = [] for i in range(1, n + 1): ...
mbpp_sanitized_data_604
Write a function to reverse words seperated by spaces in a given string. assert reverse_words("python program")==("program python") assert reverse_words("java language")==("language java") assert reverse_words("indian man")==("man indian") def reverse_words(s): return ' '.join(reversed(s.split()))
mbpp_sanitized_data_605
Write a function to check if the given integer is a prime number. assert prime_num(13)==True assert prime_num(7)==True assert prime_num(-1010)==False def prime_num(num): if num >=1: for i in range(2, num//2): if (num % i) == 0: return False else: return True else: ...
mbpp_sanitized_data_606
Write a function to convert degrees to radians. assert radian_degree(90)==1.5707963267948966 assert radian_degree(60)==1.0471975511965976 assert radian_degree(120)==2.0943951023931953 import math def radian_degree(degree): radian = degree*(math.pi/180) return radian
mbpp_sanitized_data_607
Write a function to search a string for a regex pattern. The function should return the matching subtring, a start index and an end index. assert find_literals('The quick brown fox jumps over the lazy dog.', 'fox') == ('fox', 16, 19) assert find_literals('Its been a very crazy procedure right', 'crazy') == ('crazy', 16...
mbpp_sanitized_data_608
Write a python function to find nth bell number. assert bell_Number(2) == 2 assert bell_Number(3) == 5 assert bell_Number(4) == 15 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...
mbpp_sanitized_data_610
Write a python function which takes a list and returns a list with the same elements, but the k'th element removed. assert remove_kth_element([1,1,2,3,4,4,5,1],3)==[1, 1, 3, 4, 4, 5, 1] assert remove_kth_element([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4],4)==[0, 0, 1, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4] assert re...
mbpp_sanitized_data_611
Write a function which given a matrix represented as a list of lists returns the max of the n'th column. assert max_of_nth([[5, 6, 7], [1, 3, 5], [8, 9, 19]], 2) == 19 assert max_of_nth([[6, 7, 8], [2, 4, 6], [9, 10, 20]], 1) == 10 assert max_of_nth([[7, 8, 9], [3, 5, 7], [10, 11, 21]], 1) == 11 def max_of_nth(test_lis...
mbpp_sanitized_data_612
Write a python function which takes a list of lists, where each sublist has two elements, and returns a list of two lists where the first list has the first element of each sublist and the second one has the second. assert merge([['x', 'y'], ['a', 'b'], ['m', 'n']]) == [['x', 'a', 'm'], ['y', 'b', 'n']] assert merge([[...
mbpp_sanitized_data_614
Write a function to find the cumulative sum of all the values that are present in the given tuple list. assert cummulative_sum([(1, 3), (5, 6, 7), (2, 6)]) == 30 assert cummulative_sum([(2, 4), (6, 7, 8), (3, 7)]) == 37 assert cummulative_sum([(3, 5), (7, 8, 9), (4, 8)]) == 44 def cummulative_sum(test_list): res = su...
mbpp_sanitized_data_615
Write a function which takes a tuple of tuples and returns the average value for each tuple as a list. assert average_tuple(((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4)))==[30.5, 34.25, 27.0, 23.25] assert average_tuple(((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3)))== [25.5, -18.0, 3.7...
mbpp_sanitized_data_616
Write a function which takes two tuples of the same length and performs the element wise modulo. assert tuple_modulo((10, 4, 5, 6), (5, 6, 7, 5)) == (0, 4, 5, 1) assert tuple_modulo((11, 5, 6, 7), (6, 7, 8, 6)) == (5, 5, 6, 1) assert tuple_modulo((12, 6, 7, 8), (7, 8, 9, 7)) == (5, 6, 7, 1) def tuple_modulo(test_tup1, ...
mbpp_sanitized_data_617
Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane. assert min_Jumps((3,4),11)==3.5 assert min_Jumps((3,4),0)==0 assert min_Jumps((11,14),11)==1 def min_Jumps(steps, d): (a, b) = steps temp = a a = min(a, b) b = max(tem...
mbpp_sanitized_data_618
Write a function to divide two lists element wise. assert div_list([4,5,6],[1, 2, 3])==[4.0,2.5,2.0] assert div_list([3,2],[1,4])==[3.0, 0.5] assert div_list([90,120],[50,70])==[1.8, 1.7142857142857142] def div_list(nums1,nums2): result = map(lambda x, y: x / y, nums1, nums2) return list(result)
mbpp_sanitized_data_619
Write a function to move all the numbers to the end of the given string. assert move_num('I1love143you55three3000thousand') == 'Iloveyouthreethousand1143553000' assert move_num('Avengers124Assemble') == 'AvengersAssemble124' assert move_num('Its11our12path13to14see15things16do17things') == 'Itsourpathtoseethingsdothing...
mbpp_sanitized_data_620
Write a function to find the size of the largest subset of a list of numbers so that every pair is divisible. assert largest_subset([ 1, 3, 6, 13, 17, 18 ]) == 4 assert largest_subset([10, 5, 3, 15, 20]) == 3 assert largest_subset([18, 1, 3, 6, 13, 17]) == 4 def largest_subset(a): n = len(a) dp = [0 for i in range(n)...
mbpp_sanitized_data_622
Write a function to find the median of two sorted lists of same size. assert get_median([1, 12, 15, 26, 38], [2, 13, 17, 30, 45], 5) == 16.0 assert get_median([2, 4, 8, 9], [7, 13, 19, 28], 4) == 8.5 assert get_median([3, 6, 14, 23, 36, 42], [2, 18, 27, 39, 49, 55], 6) == 25.0 def get_median(arr1, arr2, n): i = 0 j...
mbpp_sanitized_data_623
Write a function to compute the n-th power of each number in a list. assert nth_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2)==[1, 4, 9, 16, 25, 36, 49, 64, 81, 100] assert nth_nums([10,20,30],3)==([1000, 8000, 27000]) assert nth_nums([12,15],5)==([248832, 759375]) def nth_nums(nums,n): nth_nums = list(map(lambda x: x ** n,...
mbpp_sanitized_data_624
Write a python function to convert a given string to uppercase. assert is_upper("person") =="PERSON" assert is_upper("final") == "FINAL" assert is_upper("Valid") == "VALID" def is_upper(string): return (string.upper())
mbpp_sanitized_data_625
Write a python function to interchange the first and last element in a given list. assert swap_List([1,2,3]) == [3,2,1] assert swap_List([1,2,3,4,4]) == [4,2,3,4,1] assert swap_List([4,5,6]) == [6,5,4] def swap_List(newList): size = len(newList) temp = newList[0] newList[0] = newList[size - 1] newLi...
mbpp_sanitized_data_626
Write a python function to find the area of the largest triangle that can be inscribed in a semicircle with a given radius. assert triangle_area(-1) == None assert triangle_area(0) == 0 assert triangle_area(2) == 4 def triangle_area(r) : if r < 0 : return None return r * r
mbpp_sanitized_data_627
Write a python function to find the smallest missing number from a sorted list of natural numbers. assert find_First_Missing([0,1,2,3]) == 4 assert find_First_Missing([0,1,2,6,9]) == 3 assert find_First_Missing([2,3,5,8,9]) == 0 def find_First_Missing(array,start=0,end=None): if end is None: end = len(array) ...
mbpp_sanitized_data_628
Write a function to replace all spaces in the given string with '%20'. assert replace_spaces("My Name is Dawood") == 'My%20Name%20is%20Dawood' assert replace_spaces("I am a Programmer") == 'I%20am%20a%20Programmer' assert replace_spaces("I love Coding") == 'I%20love%20Coding' def replace_spaces(string): return string...
mbpp_sanitized_data_629
Write a python function to find even numbers from a list of numbers. assert Split([1,2,3,4,5]) == [2,4] assert Split([4,5,6,7,8,0,1]) == [4,6,8,0] assert Split ([8,12,15,19]) == [8,12] def Split(list): return [num for num in list if num % 2 == 0]
mbpp_sanitized_data_630
Write a function to extract all the adjacent coordinates of the given coordinate tuple. assert get_coordinates((3, 4)) == [[2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5]] assert get_coordinates((4, 5)) ==[[3, 4], [3, 5], [3, 6], [4, 4], [4, 5], [4, 6], [5, 4], [5, 5], [5, 6]] assert get_coordina...
mbpp_sanitized_data_631
Write a function to replace whitespaces with an underscore and vice versa in a given string. assert replace_spaces('Jumanji The Jungle') == 'Jumanji_The_Jungle' assert replace_spaces('The_Avengers') == 'The Avengers' assert replace_spaces('Fast and Furious') == 'Fast_and_Furious' def replace_spaces(text): return "".j...
mbpp_sanitized_data_632
Write a python function to move all zeroes to the end of the given list. assert move_zero([1,0,2,0,3,4]) == [1,2,3,4,0,0] assert move_zero([2,3,2,0,0,4,0,5,0]) == [2,3,2,4,5,0,0,0,0] assert move_zero([0,1,0,1,1]) == [1,1,1,0,0] def move_zero(num_list): a = [0 for i in range(num_list.count(0))] x = [i for i in n...
mbpp_sanitized_data_633
Write a python function to find the sum of xor of all pairs of numbers in the given list. assert pair_xor_Sum([5,9,7,6],4) == 47 assert pair_xor_Sum([7,3,5],3) == 12 assert pair_xor_Sum([7,3],2) == 4 def pair_xor_Sum(arr,n) : ans = 0 for i in range(0,n) : for j in range(i + 1,n) : a...
mbpp_sanitized_data_635
Write a function to sort the given list. assert heap_sort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] assert heap_sort([25, 35, 22, 85, 14, 65, 75, 25, 58])==[14, 22, 25, 25, 35, 58, 65, 75, 85] assert heap_sort( [7, 1, 9, 5])==[1,5,7,9] import heapq as hq def heap_sort(iterable): h = [] for...
mbpp_sanitized_data_637
Write a function to check whether the given amount has no profit and no loss assert noprofit_noloss(1500,1200)==False assert noprofit_noloss(100,100)==True assert noprofit_noloss(2000,5000)==False def noprofit_noloss(actual_cost,sale_amount): if(sale_amount == actual_cost): return True else: return False
mbpp_sanitized_data_638
Write a function to calculate the wind chill index rounded to the next integer given the wind velocity in km/h and a temperature in celsius. assert wind_chill(120,35)==40 assert wind_chill(40,20)==19 assert wind_chill(10,8)==6 import math def wind_chill(v,t): windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0...
mbpp_sanitized_data_639
Write a function to sum the length of the names of a given list of names after removing the names that start with a lowercase letter. assert sample_nam(['sally', 'Dylan', 'rebecca', 'Diana', 'Joanne', 'keith'])==16 assert sample_nam(["php", "res", "Python", "abcd", "Java", "aaa"])==10 assert sample_nam(["abcd", "Python...
mbpp_sanitized_data_640
Write a function to remove the parenthesis and what is inbetween them from a string. assert remove_parenthesis(["python (chrome)"])==("python") assert remove_parenthesis(["string(.abc)"])==("string") assert remove_parenthesis(["alpha(num)"])==("alpha") import re def remove_parenthesis(items): for item in items: re...
mbpp_sanitized_data_641
Write a function to find the nth nonagonal number. assert is_nonagonal(10) == 325 assert is_nonagonal(15) == 750 assert is_nonagonal(18) == 1089 def is_nonagonal(n): return int(n * (7 * n - 5) / 2)
mbpp_sanitized_data_643
Write a function that checks if a strings contains 'z', except at the start and end of the word. assert text_match_wordz_middle("pythonzabc.")==True assert text_match_wordz_middle("zxyabc.")==False assert text_match_wordz_middle(" lang .")==False import re def text_match_wordz_middle(text): return bool(re.sea...
mbpp_sanitized_data_644
Write a python function to reverse an array upto a given position. assert reverse_Array_Upto_K([1, 2, 3, 4, 5, 6],4) == [4, 3, 2, 1, 5, 6] assert reverse_Array_Upto_K([4, 5, 6, 7], 2) == [5, 4, 6, 7] assert reverse_Array_Upto_K([9, 8, 7, 6, 5],3) == [7, 8, 9, 6, 5] def reverse_Array_Upto_K(input, k): return (input[k...
mbpp_sanitized_data_720
Write a function to add a dictionary to the tuple. The output should be a tuple. assert add_dict_to_tuple((4, 5, 6), {"MSAM" : 1, "is" : 2, "best" : 3} ) == (4, 5, 6, {'MSAM': 1, 'is': 2, 'best': 3}) assert add_dict_to_tuple((1, 2, 3), {"UTS" : 2, "is" : 3, "Worst" : 4} ) == (1, 2, 3, {'UTS': 2, 'is': 3, 'Worst': 4}) a...
mbpp_sanitized_data_721
Given a square matrix of size N*N given as a list of lists, where each cell is associated with a specific cost. A path is defined as a specific sequence of cells that starts from the top-left cell move only right or down and ends on bottom right cell. We want to find a path with the maximum average over all existing pa...
mbpp_sanitized_data_722
The input is given as - a dictionary with a student name as a key and a tuple of float (student_height, student_weight) as a value, - minimal height, - minimal weight. Write a function to filter students that have height and weight above the minimum. assert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9,...
mbpp_sanitized_data_723
The input is defined as two lists of the same length. Write a function to count indices where the lists have the same values. assert count_same_pair([1, 2, 3, 4, 5, 6, 7, 8],[2, 2, 3, 1, 2, 6, 7, 9])==4 assert count_same_pair([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==11 a...
mbpp_sanitized_data_724
Write a function that takes base and power as arguments and calculate the sum of all digits of the base to the specified power. assert power_base_sum(2,100)==115 assert power_base_sum(8,10)==37 assert power_base_sum(8,15)==62 assert power_base_sum(3,3)==9 def power_base_sum(base, power): return sum([int(i) for i in...
mbpp_sanitized_data_725
Write a function to extract values between quotation marks " " of the given string. assert extract_quotation('Cortex "A53" Based "multi" tasking "Processor"') == ['A53', 'multi', 'Processor'] assert extract_quotation('Cast your "favorite" entertainment "apps"') == ['favorite', 'apps'] assert extract_quotation('Watch co...
mbpp_sanitized_data_726
Write a function that takes as input a tuple of numbers (t_1,...,t_{N+1}) and returns a tuple of length N where the i-th element of the tuple is equal to t_i * t_{i+1}. assert multiply_elements((1, 5, 7, 8, 10)) == (5, 35, 56, 80) assert multiply_elements((2, 4, 5, 6, 7)) == (8, 20, 30, 42) assert multiply_elements((12...
mbpp_sanitized_data_728
Write a function takes as input two lists [a_1,...,a_n], [b_1,...,b_n] and returns [a_1+b_1,...,a_n+b_n]. assert sum_list([10,20,30],[15,25,35])==[25,45,65] assert sum_list([1,2,3],[5,6,7])==[6,8,10] assert sum_list([15,20,30],[15,45,75])==[30,65,105] def sum_list(lst1,lst2): res_list = [lst1[i] + lst2[i] for i in ra...
mbpp_sanitized_data_730
Write a function to remove consecutive duplicates of a given list. assert consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4 ])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4] assert consecutive_duplicates([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10])==[10, 15, 19, 18, 17, 26, 17, 18, 10] assert consecutive_...
mbpp_sanitized_data_731
Write a function to find the lateral surface area of a cone given radius r and the height h. assert lateralsurface_cone(5,12)==204.20352248333654 assert lateralsurface_cone(10,15)==566.3586699569488 assert lateralsurface_cone(19,17)==1521.8090132193388 import math def lateralsurface_cone(r,h): l = math.sqrt(r * r + h...
mbpp_sanitized_data_732
Write a function to replace all occurrences of spaces, commas, or dots with a colon. assert replace_specialchar('Python language, Programming language.')==('Python:language::Programming:language:') assert replace_specialchar('a b c,d e f')==('a:b:c:d:e:f') assert replace_specialchar('ram reshma,ram rahim')==('ram:reshm...
mbpp_sanitized_data_733
Write a function to find the index of the first occurrence of a given number in a sorted array. assert find_first_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 1 assert find_first_occurrence([2, 3, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 2 assert find_first_occurrence([2, 4, 1, 5, 6, 6, 8, 9, 9, 9], 6) == 4 def find_first_oc...
mbpp_sanitized_data_734
Write a python function to find sum of products of all possible sublists of a given list. https://www.geeksforgeeks.org/sum-of-products-of-all-possible-subarrays/ assert sum_Of_Subarray_Prod([1,2,3]) == 20 assert sum_Of_Subarray_Prod([1,2]) == 5 assert sum_Of_Subarray_Prod([1,2,3,4]) == 84 def sum_Of_Subarray_Prod(arr)...
mbpp_sanitized_data_735
Write a python function to toggle bits of the number except the first and the last bit. https://www.geeksforgeeks.org/toggle-bits-number-expect-first-last-bits/ assert toggle_middle_bits(9) == 15 assert toggle_middle_bits(10) == 12 assert toggle_middle_bits(11) == 13 assert toggle_middle_bits(0b1000001) == 0b1111111 as...
mbpp_sanitized_data_736
Write a function to locate the left insertion point for a specified value in sorted order. https://www.w3resource.com/python-exercises/data-structures-and-algorithms/python-data-structure-exercise-24.php assert left_insertion([1,2,4,5],6)==4 assert left_insertion([1,2,4,5],3)==2 assert left_insertion([1,2,4,5],7)==4 im...
mbpp_sanitized_data_737
Write a function to check whether the given string is starting with a vowel or not using regex. assert check_str("annie") assert not check_str("dawood") assert check_str("Else") import re regex = '^[aeiouAEIOU][A-Za-z0-9_]*' def check_str(string): return re.search(regex, string)
mbpp_sanitized_data_738
Write a function to calculate the geometric sum of n-1. https://www.w3resource.com/python-exercises/data-structures-and-algorithms/python-recursion-exercise-9.php assert geometric_sum(7) == 1.9921875 assert geometric_sum(4) == 1.9375 assert geometric_sum(8) == 1.99609375 def geometric_sum(n): if n < 0: return 0 ...
mbpp_sanitized_data_739
Write a python function to find the index of smallest triangular number with n digits. https://www.geeksforgeeks.org/index-of-smallest-triangular-number-with-n-digits/ assert find_Index(2) == 4 assert find_Index(3) == 14 assert find_Index(4) == 45 import math def find_Index(n): x = math.sqrt(2 * math.pow(10,(n - ...
mbpp_sanitized_data_740
Write a function to convert the given tuple to a key-value dictionary using adjacent elements. https://www.geeksforgeeks.org/python-convert-tuple-to-adjacent-pair-dictionary/ assert tuple_to_dict((1, 5, 7, 10, 13, 5)) == {1: 5, 7: 10, 13: 5} assert tuple_to_dict((1, 2, 3, 4, 5, 6)) == {1: 2, 3: 4, 5: 6} assert tuple_to...
mbpp_sanitized_data_741
Write a python function to check whether all the characters are same or not. assert all_Characters_Same("python") == False assert all_Characters_Same("aaa") == True assert all_Characters_Same("data") == False def all_Characters_Same(s) : n = len(s) for i in range(1,n) : if s[i] != s[0] : ret...
mbpp_sanitized_data_742
Write a function to caluclate the area of a tetrahedron. assert area_tetrahedron(3)==15.588457268119894 assert area_tetrahedron(20)==692.8203230275509 assert area_tetrahedron(10)==173.20508075688772 import math def area_tetrahedron(side): area = math.sqrt(3)*(side*side) return area
mbpp_sanitized_data_743
Write a function to rotate a given list by specified number of items to the right direction. https://www.geeksforgeeks.org/python-program-right-rotate-list-n/ assert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],3)==[8, 9, 10, 1, 2, 3, 4, 5, 6, 7] assert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2)==[9, 10, 1, 2, 3, ...
mbpp_sanitized_data_744
Write a function to check if the given tuple has any none value or not. assert check_none((10, 4, 5, 6, None)) == True assert check_none((7, 8, 9, 11, 14)) == False assert check_none((1, 2, 3, 4, None)) == True def check_none(test_tup): res = any(map(lambda ele: ele is None, test_tup)) return res
mbpp_sanitized_data_745
Write a function to find numbers within a given range from startnum ti endnum where every number is divisible by every digit it contains. https://www.w3resource.com/python-exercises/lambda/python-lambda-exercise-24.php assert divisible_by_digits(1,22)==[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22] assert divisible_by_dig...
mbpp_sanitized_data_746
Write a function to find area of a sector. The function takes the radius and angle as inputs. Function should return None if the angle is larger than 360 degrees. assert sector_area(4,45)==6.283185307179586 assert sector_area(9,45)==31.808625617596654 assert sector_area(9,361)==None import math def sector_area(r,a): ...
mbpp_sanitized_data_747
Write a function to find the longest common subsequence for the given three string sequence. https://www.geeksforgeeks.org/lcs-longest-common-subsequence-three-strings/ assert lcs_of_three('AGGT12', '12TXAYB', '12XBA') == 2 assert lcs_of_three('Reels', 'Reelsfor', 'ReelsforReels') == 5 assert lcs_of_three('abcd1e2', 'b...
mbpp_sanitized_data_748
Write a function to put spaces between words starting with capital letters in a given string. assert capital_words_spaces("Python") == 'Python' assert capital_words_spaces("PythonProgrammingExamples") == 'Python Programming Examples' assert capital_words_spaces("GetReadyToBeCodingFreak") == 'Get Ready To Be Coding Frea...
mbpp_sanitized_data_749
Write a function to sort a given list of strings of numbers numerically. https://www.geeksforgeeks.org/python-sort-numeric-strings-in-a-list/ assert sort_numeric_strings( ['4','12','45','7','0','100','200','-12','-500'])==[-500, -12, 0, 4, 7, 12, 45, 100, 200] assert sort_numeric_strings(['2','3','8','4','7','9','8','2...
mbpp_sanitized_data_750
Write a function to add the given tuple to the given list. assert add_tuple([5, 6, 7], (9, 10)) == [5, 6, 7, 9, 10] assert add_tuple([6, 7, 8], (10, 11)) == [6, 7, 8, 10, 11] assert add_tuple([7, 8, 9], (11, 12)) == [7, 8, 9, 11, 12] def add_tuple(test_list, test_tup): test_list += test_tup return test_list
mbpp_sanitized_data_751
Write a function to check if the given array represents min heap or not. https://www.geeksforgeeks.org/how-to-check-if-a-given-array-represents-a-binary-heap/ assert check_min_heap([1, 2, 3, 4, 5, 6]) == True assert check_min_heap([2, 3, 4, 5, 10, 15]) == True assert check_min_heap([2, 10, 4, 5, 3, 15]) == False def ch...
mbpp_sanitized_data_752
Write a function to find the nth jacobsthal number. https://www.geeksforgeeks.org/jacobsthal-and-jacobsthal-lucas-numbers/ 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341, 683, 1365, 2731, ... assert jacobsthal_num(5) == 11 assert jacobsthal_num(2) == 1 assert jacobsthal_num(4) == 5 assert jacobsthal_num(13) == 2731 def jacobs...
mbpp_sanitized_data_753
Write a function to find minimum k records from tuple list. https://www.geeksforgeeks.org/python-find-minimum-k-records-from-tuple-list/ - in this case a verbatim copy of test cases assert min_k([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2) == [('Akash', 2), ('Akshat', 4)] assert min_k([('Sanjeev', ...
mbpp_sanitized_data_754
We say that an element is common for lists l1, l2, l3 if it appears in all three lists under the same index. Write a function to find common elements from three lists. The function should return a list. assert extract_index_list([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7])==[1, 7] assert extract_i...
mbpp_sanitized_data_755
Write a function to find the second smallest number in a list. assert second_smallest([1, 2, -8, -2, 0, -2])==-2 assert second_smallest([1, 1, -0.5, 0, 2, -2, -2])==-0.5 assert second_smallest([2,2])==None assert second_smallest([2,2,2])==None def second_smallest(numbers): unique_numbers = list(set(numbers)) unique...
mbpp_sanitized_data_756
Write a function that matches a string that has an 'a' followed by one or more 'b's. https://www.w3resource.com/python-exercises/re/python-re-exercise-3.php assert text_match_zero_one("ac")==False assert text_match_zero_one("dc")==False assert text_match_zero_one("abbbba")==True assert text_match_zero_one("dsabbbba")==...
mbpp_sanitized_data_757
Write a function to count the pairs of reverse strings in the given string list. https://www.geeksforgeeks.org/python-program-to-count-the-pairs-of-reverse-strings/ assert count_reverse_pairs(["julia", "best", "tseb", "for", "ailuj"])== 2 assert count_reverse_pairs(["geeks", "best", "for", "skeeg"]) == 1 assert count_r...
mbpp_sanitized_data_758
Write a function to count lists within a list. The function should return a dictionary where every list is converted to a tuple and the value of such tuple is the number of its occurencies in the original list. assert unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]] )=={(1, 3): 2, (5, 7): 2, (13,...
mbpp_sanitized_data_759
Write a function to check whether a given string is a decimal number with a precision of 2. assert is_decimal('123.11')==True assert is_decimal('e666.86')==False assert is_decimal('3.124587')==False assert is_decimal('1.11')==True assert is_decimal('1.1.11')==False def is_decimal(num): import re dnumre = re.com...
mbpp_sanitized_data_760
Write a python function to check whether a list of numbers contains only one distinct element or not. assert unique_Element([1,1,1]) == True assert unique_Element([1,2,1,2]) == False assert unique_Element([1,2,3,4,5]) == False def unique_Element(arr): s = set(arr) return len(s) == 1
mbpp_sanitized_data_762
Write a function to check whether the given month number contains 30 days or not. Months are given as number from 1 to 12. assert check_monthnumber_number(6)==True assert check_monthnumber_number(2)==False assert check_monthnumber_number(12)==False def check_monthnumber_number(monthnum3): return monthnum3==4 or month...
mbpp_sanitized_data_763
Write a python function to find the minimum difference between any two elements in a given array. https://www.geeksforgeeks.org/find-minimum-difference-pair/ assert find_min_diff((1,5,3,19,18,25),6) == 1 assert find_min_diff((4,3,2,6),4) == 1 assert find_min_diff((30,5,20,9),4) == 4 def find_min_diff(arr,n): arr =...
mbpp_sanitized_data_764
Write a python function to count number of digits in a given string. assert number_ctr('program2bedone') == 1 assert number_ctr('3wonders') == 1 assert number_ctr('123') == 3 assert number_ctr('3wond-1ers2') == 3 def number_ctr(str): number_ctr= 0 for i in range(len(str)): if str[i] >= '0' and str...
mbpp_sanitized_data_765
Write a function to find nth polite number. geeksforgeeks.org/n-th-polite-number/ assert is_polite(7) == 11 assert is_polite(4) == 7 assert is_polite(9) == 13 import math def is_polite(n): n = n + 1 return (int)(n+(math.log((n + math.log(n, 2)), 2)))
mbpp_sanitized_data_766
Write a function to return a list of all pairs of consecutive items in a given list. assert pair_wise([1,1,2,3,3,4,4,5])==[(1, 1), (1, 2), (2, 3), (3, 3), (3, 4), (4, 4), (4, 5)] assert pair_wise([1,5,7,9,10])==[(1, 5), (5, 7), (7, 9), (9, 10)] assert pair_wise([5,1,9,7,10])==[(5, 1), (1, 9), (9, 7), (7, 10)] assert pa...
mbpp_sanitized_data_767
Write a python function to count the number of pairs whose sum is equal to ‘sum’. The funtion gets as input a list of numbers and the sum, assert get_pairs_count([1,1,1,1],2) == 6 assert get_pairs_count([1,5,7,-1,5],6) == 3 assert get_pairs_count([1,-2,3],1) == 1 assert get_pairs_count([-1,-2,3],-3) == 1 def get_pairs_...
mbpp_sanitized_data_769
Write a python function to get the difference between two lists. assert (Diff([10, 15, 20, 25, 30, 35, 40], [25, 40, 35])) == [10, 20, 30, 15] assert (Diff([1,2,3,4,5], [6,7,1])) == [2,3,4,5,6,7] assert (Diff([1,2,3], [6,7,1])) == [2,3,6,7] def Diff(li1,li2): return list(set(li1)-set(li2)) + list(set(li2)-set(li1))...
mbpp_sanitized_data_770
Write a python function to find the sum of fourth power of first n odd natural numbers. assert odd_num_sum(2) == 82 assert odd_num_sum(3) == 707 assert odd_num_sum(4) == 3108 def odd_num_sum(n) : j = 0 sm = 0 for i in range(1,n + 1) : j = (2*i-1) sm = sm + (j*j*j*j) return sm
mbpp_sanitized_data_771
Write a function to check if the given expression is balanced or not. https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/ assert check_expression("{()}[{}]") == True assert check_expression("{()}[{]") == False assert check_expression("{()}[{}][]({})") == True from collections import deque def...
mbpp_sanitized_data_772
Write a function to remove all the words with k length in the given string. assert remove_length('The person is most value tet', 3) == 'person is most value' assert remove_length('If you told me about this ok', 4) == 'If you me about ok' assert remove_length('Forces of darkeness is come into the play', 4) == 'Forces of...
mbpp_sanitized_data_773
Write a function to find the occurrence and position of the substrings within a string. Return None if there is no match. assert occurance_substring('python programming, python language','python')==('python', 0, 6) assert occurance_substring('python programming,programming language','programming')==('programming', 7, 1...
mbpp_sanitized_data_775
Write a python function to check whether every odd index contains odd numbers of a given list. assert odd_position([2,1,4,3,6,7,6,3]) == True assert odd_position([4,1,2]) == True assert odd_position([1,2,3]) == False def odd_position(nums): return all(nums[i]%2==i%2 for i in range(len(nums)))
mbpp_sanitized_data_776
Write a function to count those characters which have vowels as their neighbors in the given string. assert count_vowels('bestinstareels') == 7 assert count_vowels('partofthejourneyistheend') == 12 assert count_vowels('amazonprime') == 5 def count_vowels(test_str): res = 0 vow_list = ['a', 'e', 'i', 'o', 'u'] for...
mbpp_sanitized_data_777
Write a python function to find the sum of non-repeated elements in a given list. assert find_sum([1,2,3,1,1,4,5,6]) == 21 assert find_sum([1,10,9,4,2,10,10,45,4]) == 71 assert find_sum([12,10,9,45,2,10,10,45,10]) == 78 def find_sum(arr): arr.sort() sum = arr[0] for i in range(len(arr)-1): if (a...
mbpp_sanitized_data_778
Write a function to pack consecutive duplicates of a given list elements into sublists. assert pack_consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4])==[[0, 0], [1], [2], [3], [4, 4], [5], [6, 6, 6], [7], [8], [9], [4, 4]] assert pack_consecutive_duplicates([10, 10, 15, 19, 18, 18, 17, 26, 26, 17,...
mbpp_sanitized_data_779
Write a function to count the number of lists within a list. The function should return a dictionary, where every list is turned to a tuple, and the value of the tuple is the number of its occurrences. assert unique_sublists([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]])=={(1, 3): 2, (5, 7): 2, (13, 15, 17): ...
mbpp_sanitized_data_780
Write a function to find the combinations of sums with tuples in the given tuple list. https://www.geeksforgeeks.org/python-combinations-of-sum-with-tuples-in-tuple-list/ assert find_combinations([(2, 4), (6, 7), (5, 1), (6, 10)]) == [(8, 11), (7, 5), (8, 14), (11, 8), (12, 17), (11, 11)] assert find_combinations([(3, ...
mbpp_sanitized_data_781
Write a python function to check whether the count of divisors is even. https://www.w3resource.com/python-exercises/basic/python-basic-1-exercise-24.php assert count_divisors(10) assert not count_divisors(100) assert count_divisors(125) import math def count_divisors(n) : count = 0 for i in range(1, (int)(mat...
mbpp_sanitized_data_782
Write a python function to find the sum of all odd length subarrays. https://www.geeksforgeeks.org/sum-of-all-odd-length-subarrays/ assert odd_length_sum([1,2,4]) == 14 assert odd_length_sum([1,2,1,2]) == 15 assert odd_length_sum([1,7]) == 8 def odd_length_sum(arr): Sum = 0 l = len(arr) for i in range(l): ...
mbpp_sanitized_data_783
Write a function to convert rgb color to hsv color. https://www.geeksforgeeks.org/program-change-rgb-color-model-hsv-color-model/ assert rgb_to_hsv(255, 255, 255)==(0, 0.0, 100.0) assert rgb_to_hsv(0, 215, 0)==(120.0, 100.0, 84.31372549019608) assert rgb_to_hsv(10, 215, 110)==(149.26829268292684, 95.34883720930233, 84....
mbpp_sanitized_data_784
Write a function to find the product of first even and odd number of a given list. assert mul_even_odd([1,3,5,7,4,1,6,8])==4 assert mul_even_odd([1,2,3,4,5,6,7,8,9,10])==2 assert mul_even_odd([1,5,7,9,10])==10 def mul_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el fo...
mbpp_sanitized_data_785
Write a function to convert tuple string to integer tuple. assert tuple_str_int("(7, 8, 9)") == (7, 8, 9) assert tuple_str_int("(1, 2, 3)") == (1, 2, 3) assert tuple_str_int("(4, 5, 6)") == (4, 5, 6) assert tuple_str_int("(7, 81, 19)") == (7, 81, 19) def tuple_str_int(test_str): res = tuple(int(num) for num in test_s...
mbpp_sanitized_data_786
Write a function to locate the right insertion point for a specified value in sorted order. assert right_insertion([1,2,4,5],6)==4 assert right_insertion([1,2,4,5],3)==2 assert right_insertion([1,2,4,5],7)==4 import bisect def right_insertion(a, x): return bisect.bisect_right(a, x)
mbpp_sanitized_data_787
Write a function that matches a string that has an a followed by three 'b'. assert not text_match_three("ac") assert not text_match_three("dc") assert text_match_three("abbbba") assert text_match_three("caacabbbba") import re def text_match_three(text): patterns = 'ab{3}?' return re.search(patterns, te...
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
6