task_id
int32
3
974
text
stringlengths
40
171
code
stringlengths
30
1.33k
test_list
sequencelengths
3
3
test_setup_code
stringclasses
2 values
challenge_test_list
sequencelengths
0
3
277
Write a function to filter a dictionary based on values.
def dict_filter(dict,n): result = {key:value for (key, value) in dict.items() if value >=n} return result
[ "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}", "assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},180)=={ 'Alden Cantrell': 180, 'Pierre Cox': 190}", "assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},190)=={ 'Pierre Cox': 190}" ]
[]
889
Write a function to reverse each list in a given list of lists.
def reverse_list_lists(lists): for l in lists: l.sort(reverse = True) return lists
[ "assert reverse_list_lists([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])==[[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9], [16, 15, 14, 13]]", "assert reverse_list_lists([[1,2],[2,3],[3,4]])==[[2,1],[3,2],[4,3]]", "assert reverse_list_lists([[10,20],[30,40]])==[[20,10],[40,30]]" ]
[]
105
Write a python function to count true booleans in the given list.
def count(lst): return sum(lst)
[ "assert count([True,False,True]) == 2", "assert count([False,False]) == 0", "assert count([True,True,True]) == 3" ]
[]
253
Write a python function to count integers from a given list.
def count_integer(list1): ctr = 0 for i in list1: if isinstance(i, int): ctr = ctr + 1 return ctr
[ "assert count_integer([1,2,'abc',1.2]) == 2", "assert count_integer([1,2,3]) == 3", "assert count_integer([1,1.2,4,5.1]) == 2" ]
[]
401
Write a function to perform index wise addition of tuple elements in the given two nested tuples.
def add_nested_tuples(test_tup1, test_tup2): res = tuple(tuple(a + b for a, b in zip(tup1, tup2)) for tup1, tup2 in zip(test_tup1, test_tup2)) return (res)
[ "assert add_nested_tuples(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((7, 10), (7, 14), (3, 10), (8, 13))", "assert add_nested_tuples(((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))) == ((9, 12), (9, 16), (5, 12), (10, 15))", "assert add_nested_tuples(((3, 5), (6, 7), (4, 11), (3, 12)), ((8, 9), (5, 11), (3, 3), (9, 5))) == ((11, 14), (11, 18), (7, 14), (12, 17))" ]
[]
555
Write a python function to find the difference between sum of cubes of first n natural numbers and the sum of first n natural numbers.
def difference(n) : S = (n*(n + 1))//2; res = S*(S-1); return res;
[ "assert difference(3) == 30", "assert difference(5) == 210", "assert difference(2) == 6" ]
[]
863
Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.
def find_longest_conseq_subseq(arr, n): ans = 0 count = 0 arr.sort() v = [] v.append(arr[0]) for i in range(1, n): if (arr[i] != arr[i - 1]): v.append(arr[i]) for i in range(len(v)): if (i > 0 and v[i] == v[i - 1] + 1): count += 1 else: count = 1 ans = max(ans, count) return ans
[ "assert find_longest_conseq_subseq([1, 2, 2, 3], 4) == 3", "assert find_longest_conseq_subseq([1, 9, 3, 10, 4, 20, 2], 7) == 4", "assert find_longest_conseq_subseq([36, 41, 56, 35, 44, 33, 34, 92, 43, 32, 42], 11) == 5" ]
[]
122
Write a function to find n’th smart number.
MAX = 3000 def smartNumber(n): primes = [0] * MAX result = [] for i in range(2, MAX): if (primes[i] == 0): primes[i] = 1 j = i * 2 while (j < MAX): primes[j] -= 1 if ( (primes[j] + 3) == 0): result.append(j) j = j + i result.sort() return result[n - 1]
[ "assert smartNumber(1) == 30", "assert smartNumber(50) == 273", "assert smartNumber(1000) == 2664" ]
[]
326
Write a function to get the word with most number of occurrences in the given strings list.
from collections import defaultdict def most_occurrences(test_list): temp = defaultdict(int) for sub in test_list: for wrd in sub.split(): temp[wrd] += 1 res = max(temp, key=temp.get) return (str(res))
[ "assert most_occurrences([\"UTS is best for RTF\", \"RTF love UTS\", \"UTS is best\"] ) == 'UTS'", "assert most_occurrences([\"Its been a great year\", \"this year is so worse\", \"this year is okay\"] ) == 'year'", "assert most_occurrences([\"Families can be reunited\", \"people can be reunited\", \"Tasks can be achieved \"] ) == 'can'" ]
[]
163
Write a function to calculate the area of a regular polygon.
from math import tan, pi def area_polygon(s,l): area = s * (l ** 2) / (4 * tan(pi / s)) return area
[ "assert area_polygon(4,20)==400.00000000000006", "assert area_polygon(10,15)==1731.1969896610804", "assert area_polygon(9,7)==302.90938549487214" ]
[]
884
Write a python function to check whether all the bits are within a given range or not.
def all_Bits_Set_In_The_Given_Range(n,l,r): num = ((1 << r) - 1) ^ ((1 << (l - 1)) - 1) new_num = n & num if (num == new_num): return True return False
[ "assert all_Bits_Set_In_The_Given_Range(10,2,1) == True ", "assert all_Bits_Set_In_The_Given_Range(5,2,4) == False", "assert all_Bits_Set_In_The_Given_Range(22,2,3) == True " ]
[]
166
Write a python function to count the pairs with xor as an even number.
def find_even_Pair(A,N): evenPair = 0 for i in range(0,N): for j in range(i+1,N): if ((A[i] ^ A[j]) % 2 == 0): evenPair+=1 return evenPair;
[ "assert find_even_Pair([5,4,7,2,1],5) == 4", "assert find_even_Pair([7,2,8,1,0,5,11],7) == 9", "assert find_even_Pair([1,2,3],3) == 1" ]
[]
409
Write a function to find the minimum product from the pairs of tuples within a given list.
def min_product_tuple(list1): result_min = min([abs(x * y) for x, y in list1] ) return result_min
[ "assert min_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==8", "assert min_product_tuple([(10,20), (15,2), (5,10)] )==30", "assert min_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==100" ]
[]
693
Write a function to remove multiple spaces in a string by using regex.
import re def remove_multiple_spaces(text1): return (re.sub(' +',' ',text1))
[ "assert remove_multiple_spaces('Google Assistant') == 'Google Assistant'", "assert remove_multiple_spaces('Quad Core') == 'Quad Core'", "assert remove_multiple_spaces('ChromeCast Built-in') == 'ChromeCast Built-in'" ]
[]
654
Write a function to find the perimeter of a rectangle.
def rectangle_perimeter(l,b): perimeter=2*(l+b) return perimeter
[ "assert rectangle_perimeter(10,20)==60", "assert rectangle_perimeter(10,5)==30", "assert rectangle_perimeter(4,2)==12" ]
[]
572
Write a python function to remove two duplicate numbers from a given number of lists.
def two_unique_nums(nums): return [i for i in nums if nums.count(i)==1]
[ "assert two_unique_nums([1,2,3,2,3,4,5]) == [1, 4, 5]", "assert two_unique_nums([1,2,3,2,4,5]) == [1, 3, 4, 5]", "assert two_unique_nums([1,2,3,4,5]) == [1, 2, 3, 4, 5]" ]
[]
184
Write a function to find all the values in a list that are greater than a specified number.
def greater_specificnum(list,num): greater_specificnum=all(x >= num for x in list) return greater_specificnum
[ "assert greater_specificnum([220, 330, 500],200)==True", "assert greater_specificnum([12, 17, 21],20)==False", "assert greater_specificnum([1,2,3,4],10)==False" ]
[]
786
Write a function to locate the right insertion point for a specified value in sorted order.
import bisect def right_insertion(a, x): i = bisect.bisect_right(a, x) return i
[ "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" ]
[]
676
Write a function to remove everything except alphanumeric characters from the given string by using regex.
import re def remove_extra_char(text1): pattern = re.compile('[\W_]+') return (pattern.sub('', text1))
[ "assert remove_extra_char('**//Google Android// - 12. ') == 'GoogleAndroid12'", "assert remove_extra_char('****//Google Flutter//*** - 36. ') == 'GoogleFlutter36'", "assert remove_extra_char('**//Google Firebase// - 478. ') == 'GoogleFirebase478'" ]
[]
27
Write a python function to remove all digits from a list of strings.
import re def remove(list): pattern = '[0-9]' list = [re.sub(pattern, '', i) for i in list] return list
[ "assert remove(['4words', '3letters', '4digits']) == ['words', 'letters', 'digits']", "assert remove(['28Jan','12Jan','11Jan']) == ['Jan','Jan','Jan']", "assert remove(['wonder1','wonder2','wonder3']) == ['wonder','wonder','wonder']" ]
[]
25
Write a python function to find the product of non-repeated elements in a given array.
def find_Product(arr,n): arr.sort() prod = 1 for i in range(0,n,1): if (arr[i - 1] != arr[i]): prod = prod * arr[i] return prod;
[ "assert find_Product([1,1,2,3],4) == 6", "assert find_Product([1,2,3,1,1],5) == 6", "assert find_Product([1,1,4,5,6],5) == 120" ]
[ "assert find_Product([1,1,4,5,6,5,7,1,1,3,4],11) == 2520" ]
695
Write a function to check if each element of the second tuple is greater than its corresponding index in the first tuple.
def check_greater(test_tup1, test_tup2): res = all(x < y for x, y in zip(test_tup1, test_tup2)) return (res)
[ "assert check_greater((10, 4, 5), (13, 5, 18)) == True", "assert check_greater((1, 2, 3), (2, 1, 4)) == False", "assert check_greater((4, 5, 6), (5, 6, 7)) == True" ]
[]
602
Write a python function to find the first repeated character in a given string.
def first_repeated_char(str1): for index,c in enumerate(str1): if str1[:index+1].count(c) > 1: return c return "None"
[ "assert first_repeated_char(\"abcabc\") == \"a\"", "assert first_repeated_char(\"abc\") == \"None\"", "assert first_repeated_char(\"123123\") == \"1\"" ]
[]
245
Write a function to find the maximum sum of bi-tonic sub-sequence for the given array.
def max_sum(arr, n): MSIBS = arr[:] for i in range(n): 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, n + 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
[ "assert max_sum([1, 15, 51, 45, 33, 100, 12, 18, 9], 9) == 194", "assert max_sum([80, 60, 30, 40, 20, 10], 6) == 210", "assert max_sum([2, 3 ,14, 16, 21, 23, 29, 30], 8) == 138" ]
[]
289
Write a python function to calculate the number of odd days in a given year.
def odd_Days(N): hund1 = N // 100 hund4 = N // 400 leap = N >> 2 ordd = N - leap if (hund1): ordd += hund1 leap -= hund1 if (hund4): ordd -= hund4 leap += hund4 days = ordd + leap * 2 odd = days % 7 return odd
[ "assert odd_Days(100) == 5", "assert odd_Days(50) ==6", "assert odd_Days(75) == 2" ]
[]
637
Write a function to check whether the given amount has no profit and no loss
def noprofit_noloss(actual_cost,sale_amount): if(sale_amount == actual_cost): return True else: return False
[ "assert noprofit_noloss(1500,1200)==False", "assert noprofit_noloss(100,100)==True", "assert noprofit_noloss(2000,5000)==False" ]
[]
610
Write a python function to remove the k'th element from a given list.
def remove_kth_element(list1, L): return list1[:L-1] + list1[L:]
[ "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 remove_kth_element([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10],5)==[10,10,15,19, 18, 17, 26, 26, 17, 18, 10]" ]
[]
335
Write a function to find the sum of arithmetic progression.
def ap_sum(a,n,d): total = (n * (2 * a + (n - 1) * d)) / 2 return total
[ "assert ap_sum(1,5,2)==25", "assert ap_sum(2,6,4)==72", "assert ap_sum(1,4,5)==34" ]
[]
872
Write a function to check if a nested list is a subset of another nested list.
def check_subset(list1,list2): return all(map(list1.__contains__,list2))
[ "assert check_subset([[1, 3], [5, 7], [9, 11], [13, 15, 17]] ,[[1, 3],[13,15,17]])==True", "assert check_subset([[1, 2], [2, 3], [3, 4], [5, 6]],[[3, 4], [5, 6]])==True", "assert check_subset([[[1, 2], [2, 3]], [[3, 4], [5, 7]]],[[[3, 4], [5, 6]]])==False" ]
[]
763
Write a python function to find the minimum difference between any two elements in a given array.
def find_Min_Diff(arr,n): arr = sorted(arr) diff = 10**20 for i in range(n-1): if arr[i+1] - arr[i] < diff: diff = arr[i+1] - arr[i] return diff
[ "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" ]
[]
226
Write a python function to remove the characters which have odd index values of a given string.
def odd_values_string(str): result = "" for i in range(len(str)): if i % 2 == 0: result = result + str[i] return result
[ "assert odd_values_string('abcdef') == 'ace'", "assert odd_values_string('python') == 'pto'", "assert odd_values_string('data') == 'dt'" ]
[]
412
Write a python function to remove odd numbers from a given list.
def remove_odd(l): for i in l: if i % 2 != 0: l.remove(i) return l
[ "assert remove_odd([1,2,3]) == [2]", "assert remove_odd([2,4,6]) == [2,4,6]", "assert remove_odd([10,20,3]) == [10,20]" ]
[]
149
Write a function to find the longest subsequence such that the difference between adjacents is one for the given array.
def longest_subseq_with_diff_one(arr, n): dp = [1 for i in range(n)] for i in range(n): for j in range(i): if ((arr[i] == arr[j]+1) or (arr[i] == arr[j]-1)): dp[i] = max(dp[i], dp[j]+1) result = 1 for i in range(n): if (result < dp[i]): result = dp[i] return result
[ "assert longest_subseq_with_diff_one([1, 2, 3, 4, 5, 3, 2], 7) == 6", "assert longest_subseq_with_diff_one([10, 9, 4, 5, 4, 8, 6], 7) == 3", "assert longest_subseq_with_diff_one([1, 2, 3, 2, 3, 7, 2, 1], 8) == 7" ]
[]
829
Write a function to find out the second most repeated (or frequent) string in the given sequence.
from collections import Counter def second_frequent(input): dict = Counter(input) value = sorted(dict.values(), reverse=True) second_large = value[1] for (key, val) in dict.items(): if val == second_large: return (key)
[ "assert second_frequent(['aaa','bbb','ccc','bbb','aaa','aaa']) == 'bbb'", "assert second_frequent(['abc','bcd','abc','bcd','bcd','bcd']) == 'abc'", "assert second_frequent(['cdma','gsm','hspa','gsm','cdma','cdma']) == 'gsm'" ]
[]
715
Write a function to convert the given string of integers into a tuple.
def str_to_tuple(test_str): res = tuple(map(int, test_str.split(', '))) return (res)
[ "assert str_to_tuple(\"1, -5, 4, 6, 7\") == (1, -5, 4, 6, 7)", "assert str_to_tuple(\"1, 2, 3, 4, 5\") == (1, 2, 3, 4, 5)", "assert str_to_tuple(\"4, 6, 9, 11, 13, 14\") == (4, 6, 9, 11, 13, 14)" ]
[]
63
Write a function to find the maximum difference between available pairs in the given tuple list.
def max_difference(test_list): temp = [abs(b - a) for a, b in test_list] res = max(temp) return (res)
[ "assert max_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 7", "assert max_difference([(4, 6), (2, 17), (9, 13), (11, 12)]) == 15", "assert max_difference([(12, 35), (21, 27), (13, 23), (41, 22)]) == 23" ]
[]
109
Write a python function to find the count of rotations of a binary string with odd value.
def odd_Equivalent(s,n): count=0 for i in range(0,n): if (s[i] == '1'): count = count + 1 return count
[ "assert odd_Equivalent(\"011001\",6) == 3", "assert odd_Equivalent(\"11011\",5) == 4", "assert odd_Equivalent(\"1010\",4) == 2" ]
[]
626
Write a python function to find the largest triangle that can be inscribed in the semicircle.
def triangle_area(r) : if r < 0 : return -1 return r * r
[ "assert triangle_area(0) == 0", "assert triangle_area(-1) == -1", "assert triangle_area(2) == 4" ]
[]
47
Write a python function to find the last digit when factorial of a divides factorial of b.
def compute_Last_Digit(A,B): variable = 1 if (A == B): return 1 elif ((B - A) >= 5): return 0 else: for i in range(A + 1,B + 1): variable = (variable * (i % 10)) % 10 return variable % 10
[ "assert compute_Last_Digit(2,4) == 2", "assert compute_Last_Digit(6,8) == 6", "assert compute_Last_Digit(1,2) == 2" ]
[ "assert compute_Last_Digit(3,7) == 0", "assert compute_Last_Digit(20,23) == 6", "assert compute_Last_Digit(1021,1024) == 4" ]
411
Write a function to convert the given snake case string to camel case string by using regex.
import re def snake_to_camel(word): return ''.join(x.capitalize() or '_' for x in word.split('_'))
[ "assert snake_to_camel('android_tv') == 'AndroidTv'", "assert snake_to_camel('google_pixel') == 'GooglePixel'", "assert snake_to_camel('apple_watch') == 'AppleWatch'" ]
[]
168
Write a python function to find the frequency of a number in a given array.
def frequency(a,x): count = 0 for i in a: if i == x: count += 1 return count
[ "assert frequency([1,2,3],4) == 0", "assert frequency([1,2,2,3,3,3,4],3) == 3", "assert frequency([0,1,2,3,1,2],1) == 2" ]
[]
932
Write a function to remove duplicate words from a given list of strings.
def remove_duplic_list(l): temp = [] for x in l: if x not in temp: temp.append(x) return temp
[ "assert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\"])==['Python', 'Exercises', 'Practice', 'Solution']", "assert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\",\"Java\"])==['Python', 'Exercises', 'Practice', 'Solution', 'Java']", "assert remove_duplic_list([\"Python\", \"Exercises\", \"Practice\", \"Solution\", \"Exercises\",\"C++\",\"C\",\"C++\"])==['Python', 'Exercises', 'Practice', 'Solution','C++','C']" ]
[]
91
Write a function to check if a substring is present in a given list of string values.
def find_substring(str1, sub_str): if any(sub_str in s for s in str1): return True return False
[ "assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ack\")==True", "assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"abc\")==False", "assert find_substring([\"red\", \"black\", \"white\", \"green\", \"orange\"],\"ange\")==True" ]
[]
138
Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.
def is_Sum_Of_Powers_Of_Two(n): if (n % 2 == 1): return False else: return True
[ "assert is_Sum_Of_Powers_Of_Two(10) == True", "assert is_Sum_Of_Powers_Of_Two(7) == False", "assert is_Sum_Of_Powers_Of_Two(14) == True" ]
[]
479
Write a python function to find the first digit of a given number.
def first_Digit(n) : while n >= 10: n = n / 10; return int(n)
[ "assert first_Digit(123) == 1", "assert first_Digit(456) == 4", "assert first_Digit(12) == 1" ]
[]
452
Write a function that gives loss amount if the given amount has loss else return none.
def loss_amount(actual_cost,sale_amount): if(sale_amount > actual_cost): amount = sale_amount - actual_cost return amount else: return None
[ "assert loss_amount(1500,1200)==None", "assert loss_amount(100,200)==100", "assert loss_amount(2000,5000)==3000" ]
[]
787
Write a function that matches a string that has an a followed by three 'b'.
import re def text_match_three(text): patterns = 'ab{3}?' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
[ "assert text_match_three(\"ac\")==('Not matched!')", "assert text_match_three(\"dc\")==('Not matched!')", "assert text_match_three(\"abbbba\")==('Found a match!')" ]
[]
470
Write a function to find the pairwise addition of the elements of the given tuples.
def add_pairwise(test_tup): res = tuple(i + j for i, j in zip(test_tup, test_tup[1:])) return (res)
[ "assert add_pairwise((1, 5, 7, 8, 10)) == (6, 12, 15, 18)", "assert add_pairwise((2, 6, 8, 9, 11)) == (8, 14, 17, 20)", "assert add_pairwise((3, 7, 9, 10, 12)) == (10, 16, 19, 22)" ]
[]
314
Write a function to find out the maximum sum such that no two chosen numbers are adjacent for the given rectangular grid of dimension 2 x n.
def max_sum_rectangular_grid(grid, n) : incl = max(grid[0][0], grid[1][0]) excl = 0 for i in range(1, n) : excl_new = max(excl, incl) incl = excl + max(grid[0][i], grid[1][i]) excl = excl_new return max(excl, incl)
[ "assert max_sum_rectangular_grid([ [1, 4, 5], [2, 0, 0 ] ], 3) == 7", "assert max_sum_rectangular_grid([ [ 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10] ], 5) == 24", "assert max_sum_rectangular_grid([ [7, 9, 11, 15, 19], [21, 25, 28, 31, 32] ], 5) == 81" ]
[]
800
Write a function to remove all whitespaces from a string.
import re def remove_all_spaces(text): return (re.sub(r'\s+', '',text))
[ "assert remove_all_spaces('python program')==('pythonprogram')", "assert remove_all_spaces('python programming language')==('pythonprogramminglanguage')", "assert remove_all_spaces('python program')==('pythonprogram')" ]
[]
383
Write a python function to toggle all odd bits of a given number.
def even_bit_toggle_number(n) : res = 0; count = 0; temp = n while(temp > 0 ) : if (count % 2 == 0) : res = res | (1 << count) count = count + 1 temp >>= 1 return n ^ res
[ "assert even_bit_toggle_number(10) == 15", "assert even_bit_toggle_number(20) == 1", "assert even_bit_toggle_number(30) == 11" ]
[]
293
Write a function to find the third side of a right angled triangle.
import math def otherside_rightangle(w,h): s=math.sqrt((w*w)+(h*h)) return s
[ "assert otherside_rightangle(7,8)==10.63014581273465", "assert otherside_rightangle(3,4)==5", "assert otherside_rightangle(7,15)==16.55294535724685" ]
[]
641
Write a function to find the nth nonagonal number.
def is_nonagonal(n): return int(n * (7 * n - 5) / 2)
[ "assert is_nonagonal(10) == 325", "assert is_nonagonal(15) == 750", "assert is_nonagonal(18) == 1089" ]
[]
102
Write a function to convert snake case string to camel case string.
def snake_to_camel(word): import re return ''.join(x.capitalize() or '_' for x in word.split('_'))
[ "assert snake_to_camel('python_program')=='PythonProgram'", "assert snake_to_camel('python_language')==('PythonLanguage')", "assert snake_to_camel('programming_language')==('ProgrammingLanguage')" ]
[]
221
Write a python function to find the first even number in a given list of numbers.
def first_even(nums): first_even = next((el for el in nums if el%2==0),-1) return first_even
[ "assert first_even ([1, 3, 5, 7, 4, 1, 6, 8]) == 4", "assert first_even([2, 3, 4]) == 2", "assert first_even([5, 6, 7]) == 6" ]
[]
640
Write a function to remove the parenthesis area in a string.
import re def remove_parenthesis(items): for item in items: return (re.sub(r" ?\([^)]+\)", "", item))
[ "assert remove_parenthesis([\"python (chrome)\"])==(\"python\")", "assert remove_parenthesis([\"string(.abc)\"])==(\"string\")", "assert remove_parenthesis([\"alpha(num)\"])==(\"alpha\")" ]
[]
756
Write a function that matches a string that has an a followed by zero or one 'b'.
import re def text_match_zero_one(text): patterns = 'ab?' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
[ "assert text_match_zero_one(\"ac\")==('Found a match!')", "assert text_match_zero_one(\"dc\")==('Not matched!')", "assert text_match_zero_one(\"abbbba\")==('Found a match!')" ]
[]
909
Write a function to find the previous palindrome of a specified number.
def previous_palindrome(num): for x in range(num-1,0,-1): if str(x) == str(x)[::-1]: return x
[ "assert previous_palindrome(99)==88", "assert previous_palindrome(1221)==1111", "assert previous_palindrome(120)==111" ]
[]
146
Write a function to find the ascii value of total characters in a string.
def ascii_value_string(str1): for i in range(len(str1)): return ord(str1[i])
[ "assert ascii_value_string(\"python\")==112", "assert ascii_value_string(\"Program\")==80", "assert ascii_value_string(\"Language\")==76" ]
[]
961
Write a function to convert a roman numeral to an integer.
def roman_to_int(s): rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} int_val = 0 for i in range(len(s)): if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]: int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]] else: int_val += rom_val[s[i]] return int_val
[ "assert roman_to_int('MMMCMLXXXVI')==3986", "assert roman_to_int('MMMM')==4000", "assert roman_to_int('C')==100" ]
[]
588
Write a python function to find the difference between largest and smallest value in a given array.
def big_diff(nums): diff= max(nums)-min(nums) return diff
[ "assert big_diff([1,2,3,4]) == 3", "assert big_diff([4,5,12]) == 8", "assert big_diff([9,2,3]) == 7" ]
[]
413
Write a function to extract the nth element from a given list of tuples.
def extract_nth_element(list1, n): result = [x[n] for x in list1] return result
[ "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']", "assert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,2)==[99, 96, 94, 98]", "assert extract_nth_element([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)],1)==[98, 97, 91, 94]" ]
[]
172
Write a function to find the occurence of characters 'std' in the given string 1. list item 1. list item 1. list item 2. list item 2. list item 2. list item
def count_occurance(s): count=0 for i in range(len(s)): if (s[i]== 's' and s[i+1]=='t' and s[i+2]== 'd'): count = count + 1 return count
[ "assert count_occurance(\"letstdlenstdporstd\") == 3", "assert count_occurance(\"truststdsolensporsd\") == 1", "assert count_occurance(\"makestdsostdworthit\") == 2" ]
[]
851
Write a python function to find sum of inverse of divisors.
def Sum_of_Inverse_Divisors(N,Sum): ans = float(Sum)*1.0 /float(N); return round(ans,2);
[ "assert Sum_of_Inverse_Divisors(6,12) == 2", "assert Sum_of_Inverse_Divisors(9,13) == 1.44", "assert Sum_of_Inverse_Divisors(1,4) == 4" ]
[]
861
Write a function to find all anagrams of a string in a given list of strings using lambda function.
from collections import Counter def anagram_lambda(texts,str): result = list(filter(lambda x: (Counter(str) == Counter(x)), texts)) return result
[ "assert anagram_lambda([\"bcda\", \"abce\", \"cbda\", \"cbea\", \"adcb\"],\"abcd\")==['bcda', 'cbda', 'adcb']", "assert anagram_lambda([\"recitals\",\" python\"], \"articles\" )==[\"recitals\"]", "assert anagram_lambda([\" keep\",\" abcdef\",\" xyz\"],\" peek\")==[\" keep\"]" ]
[]
544
Write a function to flatten the tuple list to a string.
def flatten_tuple(test_list): res = ' '.join([idx for tup in test_list for idx in tup]) return (res)
[ "assert flatten_tuple([('1', '4', '6'), ('5', '8'), ('2', '9'), ('1', '10')]) == '1 4 6 5 8 2 9 1 10'", "assert flatten_tuple([('2', '3', '4'), ('6', '9'), ('3', '2'), ('2', '11')]) == '2 3 4 6 9 3 2 2 11'", "assert flatten_tuple([('14', '21', '9'), ('24', '19'), ('12', '29'), ('23', '17')]) == '14 21 9 24 19 12 29 23 17'" ]
[]
901
Write a function to find the smallest multiple of the first n numbers.
def smallest_multiple(n): if (n<=2): return n i = n * 2 factors = [number for number in range(n, 1, -1) if number * 2 > n] while True: for a in factors: if i % a != 0: i += n break if (a == factors[-1] and i % a == 0): return i
[ "assert smallest_multiple(13)==360360", "assert smallest_multiple(2)==2", "assert smallest_multiple(1)==1" ]
[]
893
Write a python function to get the last element of each sublist.
def Extract(lst): return [item[-1] for item in lst]
[ "assert Extract([[1, 2, 3], [4, 5], [6, 7, 8, 9]]) == [3, 5, 9]", "assert Extract([['x', 'y', 'z'], ['m'], ['a', 'b'], ['u', 'v']]) == ['z', 'm', 'b', 'v']", "assert Extract([[1, 2, 3], [4, 5]]) == [3, 5]" ]
[]
819
Write a function to count the frequency of consecutive duplicate elements in a given list of numbers.
def count_duplic(lists): element = [] frequency = [] if not lists: return element running_count = 1 for i in range(len(lists)-1): if lists[i] == lists[i+1]: running_count += 1 else: frequency.append(running_count) element.append(lists[i]) running_count = 1 frequency.append(running_count) element.append(lists[i+1]) return element,frequency
[ "assert count_duplic([1,2,2,2,4,4,4,5,5,5,5])==([1, 2, 4, 5], [1, 3, 3, 4])", "assert count_duplic([2,2,3,1,2,6,7,9])==([2, 3, 1, 2, 6, 7, 9], [2, 1, 1, 1, 1, 1, 1])", "assert count_duplic([2,1,5,6,8,3,4,9,10,11,8,12])==([2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])" ]
[]
770
Write a python function to find the sum of fourth power of first n odd natural numbers.
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
[ "assert odd_Num_Sum(2) == 82", "assert odd_Num_Sum(3) == 707", "assert odd_Num_Sum(4) == 3108" ]
[]
275
Write a python function to find the position of the last removed element from the given array.
import math as mt def get_Position(a,n,m): for i in range(n): a[i] = (a[i] // m + (a[i] % m != 0)) result,maxx = -1,-1 for i in range(n - 1,-1,-1): if (maxx < a[i]): maxx = a[i] result = i return result + 1
[ "assert get_Position([2,5,4],3,2) == 2", "assert get_Position([4,3],2,2) == 2", "assert get_Position([1,2,3,4],4,1) == 4" ]
[]
669
Write a function to check whether the given ip address is valid or not using regex.
import re regex = '''^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$''' def check_IP(Ip): if(re.search(regex, Ip)): return ("Valid IP address") else: return ("Invalid IP address")
[ "assert check_IP(\"192.168.0.1\") == 'Valid IP address'", "assert check_IP(\"110.234.52.124\") == 'Valid IP address'", "assert check_IP(\"366.1.2.2\") == 'Invalid IP address'" ]
[]
223
Write a function to check for majority element in the given sorted array.
def is_majority(arr, n, x): i = binary_search(arr, 0, n-1, x) if i == -1: return False if ((i + n//2) <= (n -1)) and arr[i + n//2] == x: return True else: return False def binary_search(arr, low, high, x): if high >= low: mid = (low + high)//2 if (mid == 0 or x > arr[mid-1]) and (arr[mid] == x): return mid elif x > arr[mid]: return binary_search(arr, (mid + 1), high, x) else: return binary_search(arr, low, (mid -1), x) return -1
[ "assert is_majority([1, 2, 3, 3, 3, 3, 10], 7, 3) == True", "assert is_majority([1, 1, 2, 4, 4, 4, 6, 6], 8, 4) == False", "assert is_majority([1, 1, 1, 2, 2], 5, 1) == True" ]
[]
599
Write a function to find sum and average of first n natural numbers.
def sum_average(number): total = 0 for value in range(1, number + 1): total = total + value average = total / number return (total,average)
[ "assert sum_average(10)==(55, 5.5)", "assert sum_average(15)==(120, 8.0)", "assert sum_average(20)==(210, 10.5)" ]
[]
776
Write a function to count those characters which have vowels as their neighbors in the given string.
def count_vowels(test_str): res = 0 vow_list = ['a', 'e', 'i', 'o', 'u'] for idx in range(1, len(test_str) - 1): if test_str[idx] not in vow_list and (test_str[idx - 1] in vow_list or test_str[idx + 1] in vow_list): res += 1 if test_str[0] not in vow_list and test_str[1] in vow_list: res += 1 if test_str[-1] not in vow_list and test_str[-2] in vow_list: res += 1 return (res)
[ "assert count_vowels('bestinstareels') == 7", "assert count_vowels('partofthejourneyistheend') == 12", "assert count_vowels('amazonprime') == 5" ]
[]
40
Write a function to find frequency of the elements in a given list of lists using collections module.
from collections import Counter from itertools import chain def freq_element(nums): result = Counter(chain.from_iterable(nums)) return result
[ "assert freq_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]])==({2: 3, 1: 2, 5: 2, 3: 1, 4: 1, 6: 1, 7: 1, 9: 1})", "assert freq_element([[1,2,3,4],[5,6,7,8],[9,10,11,12]])==({1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1, 12: 1})", "assert freq_element([[15,20,30,40],[80,90,100,110],[30,30,80,90]])==({30: 3, 80: 2, 90: 2, 15: 1, 20: 1, 40: 1, 100: 1, 110: 1})" ]
[]
885
Write a python function to check whether the two given strings are isomorphic to each other or not.
def is_Isomorphic(str1,str2): dict_str1 = {} dict_str2 = {} for i, value in enumerate(str1): dict_str1[value] = dict_str1.get(value,[]) + [i] for j, value in enumerate(str2): dict_str2[value] = dict_str2.get(value,[]) + [j] if sorted(dict_str1.values()) == sorted(dict_str2.values()): return True else: return False
[ "assert is_Isomorphic(\"paper\",\"title\") == True", "assert is_Isomorphic(\"ab\",\"ba\") == True", "assert is_Isomorphic(\"ab\",\"aa\") == False" ]
[]
281
Write a python function to check if the elements of a given list are unique or not.
def all_unique(test_list): if len(test_list) > len(set(test_list)): return False return True
[ "assert all_unique([1,2,3]) == True", "assert all_unique([1,2,1,2]) == False", "assert all_unique([1,2,3,4,5]) == True" ]
[]
718
Write a function to create a list taking alternate elements from another given list.
def alternate_elements(list1): result=[] for item in list1[::2]: result.append(item) return result
[ "assert alternate_elements([\"red\", \"black\", \"white\", \"green\", \"orange\"])==['red', 'white', 'orange']", "assert alternate_elements([2, 0, 3, 4, 0, 2, 8, 3, 4, 2])==[2, 3, 0, 8, 4]", "assert alternate_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9]" ]
[]
101
Write a function to find the kth element in the given array.
def kth_element(arr, n, k): for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] == arr[j+1], arr[j] return arr[k-1]
[ "assert kth_element([12,3,5,7,19], 5, 2) == 3", "assert kth_element([17,24,8,23], 4, 3) == 8", "assert kth_element([16,21,25,36,4], 5, 4) == 36" ]
[]
656
Write a python function to find the minimum sum of absolute differences of two arrays.
def find_Min_Sum(a,b,n): a.sort() b.sort() sum = 0 for i in range(n): sum = sum + abs(a[i] - b[i]) return sum
[ "assert find_Min_Sum([3,2,1],[2,1,3],3) == 0", "assert find_Min_Sum([1,2,3],[4,5,6],3) == 9", "assert find_Min_Sum([4,1,8,7],[2,3,6,5],4) == 6" ]
[]
106
Write a function to add the given list to the given tuples.
def add_lists(test_list, test_tup): res = tuple(list(test_tup) + test_list) return (res)
[ "assert add_lists([5, 6, 7], (9, 10)) == (9, 10, 5, 6, 7)", "assert add_lists([6, 7, 8], (10, 11)) == (10, 11, 6, 7, 8)", "assert add_lists([7, 8, 9], (11, 12)) == (11, 12, 7, 8, 9)" ]
[]
661
Write a function to find the maximum sum that can be formed which has no three consecutive elements present.
def max_sum_of_three_consecutive(arr, n): sum = [0 for k in range(n)] if n >= 1: sum[0] = arr[0] if n >= 2: sum[1] = arr[0] + arr[1] if n > 2: sum[2] = max(sum[1], max(arr[1] + arr[2], arr[0] + arr[2])) for i in range(3, n): sum[i] = max(max(sum[i-1], sum[i-2] + arr[i]), arr[i] + arr[i-1] + sum[i-3]) return sum[n-1]
[ "assert max_sum_of_three_consecutive([100, 1000, 100, 1000, 1], 5) == 2101", "assert max_sum_of_three_consecutive([3000, 2000, 1000, 3, 10], 5) == 5013", "assert max_sum_of_three_consecutive([1, 2, 3, 4, 5, 6, 7, 8], 8) == 27" ]
[]
895
Write a function to find the maximum sum of subsequences of given array with no adjacent elements.
def max_sum_subseq(A): n = len(A) if n == 1: return A[0] look_up = [None] * n look_up[0] = A[0] look_up[1] = max(A[0], A[1]) for i in range(2, n): look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i]) look_up[i] = max(look_up[i], A[i]) return look_up[n - 1]
[ "assert max_sum_subseq([1, 2, 9, 4, 5, 0, 4, 11, 6]) == 26", "assert max_sum_subseq([1, 2, 9, 5, 6, 0, 5, 12, 7]) == 28", "assert max_sum_subseq([1, 3, 10, 5, 6, 0, 6, 14, 21]) == 44" ]
[]
344
Write a python function to find number of elements with odd factors in a given range.
def count_Odd_Squares(n,m): return int(m**0.5) - int((n-1)**0.5)
[ "assert count_Odd_Squares(5,100) == 8", "assert count_Odd_Squares(8,65) == 6", "assert count_Odd_Squares(2,5) == 1" ]
[]
193
Write a function to remove the duplicates from the given tuple.
def remove_tuple(test_tup): res = tuple(set(test_tup)) return (res)
[ "assert remove_tuple((1, 3, 5, 2, 3, 5, 1, 1, 3)) == (1, 2, 3, 5)", "assert remove_tuple((2, 3, 4, 4, 5, 6, 6, 7, 8, 8)) == (2, 3, 4, 5, 6, 7, 8)", "assert remove_tuple((11, 12, 13, 11, 11, 12, 14, 13)) == (11, 12, 13, 14)" ]
[]
241
Write a function to generate a 3d array having each element as '*'.
def array_3d(m,n,o): array_3d = [[ ['*' for col in range(m)] for col in range(n)] for row in range(o)] return array_3d
[ "assert array_3d(6,4,3)==[[['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']]]", "assert array_3d(5,3,4)==[[['*', '*', '*', '*', '*'], ['*', '*', '*', '*','*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'],['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']]]", "assert array_3d(1,2,3)==[[['*'],['*']],[['*'],['*']],[['*'],['*']]]" ]
[]
732
Write a function to replace all occurrences of spaces, commas, or dots with a colon.
import re def replace_specialchar(text): return (re.sub("[ ,.]", ":", text))
[ "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:reshma:ram:rahim')" ]
[]
436
Write a python function to print negative numbers in a list.
def neg_nos(list1): for num in list1: if num < 0: return num
[ "assert neg_nos([-1,4,5,-6]) == -1,-6", "assert neg_nos([-1,-2,3,4]) == -1,-2", "assert neg_nos([-7,-6,8,9]) == -7,-6" ]
[]
608
Write a python function to find nth bell number.
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]
[ "assert bell_Number(2) == 2", "assert bell_Number(3) == 5", "assert bell_Number(4) == 15" ]
[]
266
Write a function to find the lateral surface area of a cube.
def lateralsurface_cube(l): LSA = 4 * (l * l) return LSA
[ "assert lateralsurface_cube(5)==100", "assert lateralsurface_cube(9)==324", "assert lateralsurface_cube(10)==400" ]
[]
370
Write a function to sort a tuple by its float element.
def float_sort(price): float_sort=sorted(price, key=lambda x: float(x[1]), reverse=True) return float_sort
[ "assert float_sort([('item1', '12.20'), ('item2', '15.10'), ('item3', '24.5')])==[('item3', '24.5'), ('item2', '15.10'), ('item1', '12.20')] ", "assert float_sort([('item1', '15'), ('item2', '10'), ('item3', '20')])==[('item3', '20'), ('item1', '15'), ('item2', '10')] ", "assert float_sort([('item1', '5'), ('item2', '10'), ('item3', '14')])==[('item3', '14'), ('item2', '10'), ('item1', '5')] " ]
[]
920
Write a function to remove all tuples with all none values in the given tuple list.
def remove_tuple(test_list): res = [sub for sub in test_list if not all(ele == None for ele in sub)] return (str(res))
[ "assert remove_tuple([(None, 2), (None, None), (3, 4), (12, 3), (None, )] ) == '[(None, 2), (3, 4), (12, 3)]'", "assert remove_tuple([(None, None), (None, None), (3, 6), (17, 3), (None,1 )] ) == '[(3, 6), (17, 3), (None, 1)]'", "assert remove_tuple([(1, 2), (2, None), (3, None), (24, 3), (None, None )] ) == '[(1, 2), (2, None), (3, None), (24, 3)]'" ]
[]
591
Write a python function to interchange the first and last elements in a list.
def swap_List(newList): size = len(newList) temp = newList[0] newList[0] = newList[size - 1] newList[size - 1] = temp return newList
[ "assert swap_List([12, 35, 9, 56, 24]) == [24, 35, 9, 56, 12]", "assert swap_List([1, 2, 3]) == [3, 2, 1]", "assert swap_List([4, 5, 6]) == [6, 5, 4]" ]
[]
936
Write a function to re-arrange the given tuples based on the given ordered list.
def re_arrange_tuples(test_list, ord_list): temp = dict(test_list) res = [(key, temp[key]) for key in ord_list] return (res)
[ "assert re_arrange_tuples([(4, 3), (1, 9), (2, 10), (3, 2)], [1, 4, 2, 3]) == [(1, 9), (4, 3), (2, 10), (3, 2)]", "assert re_arrange_tuples([(5, 4), (2, 10), (3, 11), (4, 3)], [3, 4, 2, 3]) == [(3, 11), (4, 3), (2, 10), (3, 11)]", "assert re_arrange_tuples([(6, 3), (3, 8), (5, 7), (2, 4)], [2, 5, 3, 6]) == [(2, 4), (5, 7), (3, 8), (6, 3)]" ]
[]
947
Write a python function to find the length of the shortest word.
def len_log(list1): min=len(list1[0]) for i in list1: if len(i)<min: min=len(i) return min
[ "assert len_log([\"win\",\"lose\",\"great\"]) == 3", "assert len_log([\"a\",\"ab\",\"abc\"]) == 1", "assert len_log([\"12\",\"12\",\"1234\"]) == 2" ]
[]
406
Write a python function to find the parity of a given number.
def find_Parity(x): y = x ^ (x >> 1); y = y ^ (y >> 2); y = y ^ (y >> 4); y = y ^ (y >> 8); y = y ^ (y >> 16); if (y & 1): return ("Odd Parity"); return ("Even Parity");
[ "assert find_Parity(12) == \"Even Parity\"", "assert find_Parity(7) == \"Odd Parity\"", "assert find_Parity(10) == \"Even Parity\"" ]
[]
974
Write a function to find the minimum total path sum in the given triangle.
def min_sum_path(A): memo = [None] * len(A) n = len(A) - 1 for i in range(len(A[n])): memo[i] = A[n][i] for i in range(len(A) - 2, -1,-1): for j in range( len(A[i])): memo[j] = A[i][j] + min(memo[j], memo[j + 1]) return memo[0]
[ "assert min_sum_path([[ 2 ], [3, 9 ], [1, 6, 7 ]]) == 6", "assert min_sum_path([[ 2 ], [3, 7 ], [8, 5, 6 ]]) == 10 ", "assert min_sum_path([[ 3 ], [6, 4 ], [5, 2, 7 ]]) == 9" ]
[]
397
Write a function to find the median of three specific numbers.
def median_numbers(a,b,c): if a > b: if a < c: median = a elif b > c: median = b else: median = c else: if a > c: median = a elif b < c: median = b else: median = c return median
[ "assert median_numbers(25,55,65)==55.0", "assert median_numbers(20,10,30)==20.0", "assert median_numbers(15,45,75)==45.0" ]
[]
566
Write a function to get the sum of a non-negative integer.
def sum_digits(n): if n == 0: return 0 else: return n % 10 + sum_digits(int(n / 10))
[ "assert sum_digits(345)==12", "assert sum_digits(12)==3", "assert sum_digits(97)==16" ]
[]