task_id
int32
11
510
text
stringlengths
37
191
code
stringlengths
37
1.33k
test_list
sequence
test_setup_code
stringclasses
2 values
challenge_test_list
sequence
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'" ]
[]
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]" ]
[]
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]" ]
[]
414
Write a python function to check whether the value exists in a sequence or not.
def overlapping(list1,list2): c=0 d=0 for i in list1: c+=1 for i in list2: d+=1 for i in range(0,c): for j in range(0,d): if(list1[i]==list2[j]): return 1 return 0
[ "assert overlapping([1,2,3,4,5],[6,7,8,9]) == False", "assert overlapping([1,2,3],[4,5,6]) == False", "assert overlapping([1,4,5],[1,4,5]) == True" ]
[]
415
Write a python function to find a pair with highest product from a given array of integers.
def max_Product(arr): arr_len = len(arr) if (arr_len < 2): return ("No pairs exists") x = arr[0]; y = arr[1] for i in range(0,arr_len): for j in range(i + 1,arr_len): if (arr[i] * arr[j] > x * y): x = arr[i]; y = arr[j] return x,y
[ "assert max_Product([1,2,3,4,7,0,8,4]) == (7,8)", "assert max_Product([0,-1,-2,-4,5,0,-6]) == (-4,-6)", "assert max_Product([1,2,3]) == (2,3)" ]
[]
416
Write a function to find the maximum sum we can make by dividing number in three parts recursively and summing them up together for the given number.
MAX = 1000000 def breakSum(n): dp = [0]*(n+1) dp[0] = 0 dp[1] = 1 for i in range(2, n+1): dp[i] = max(dp[int(i/2)] + dp[int(i/3)] + dp[int(i/4)], i); return dp[n]
[ "assert breakSum(12) == 13", "assert breakSum(24) == 27", "assert breakSum(23) == 23" ]
[]
417
Write a function to find common first element in given list of tuple.
def group_tuples(Input): out = {} for elem in Input: try: out[elem[0]].extend(elem[1:]) except KeyError: out[elem[0]] = list(elem) return [tuple(values) for values in out.values()]
[ "assert group_tuples([('x', 'y'), ('x', 'z'), ('w', 't')]) == [('x', 'y', 'z'), ('w', 't')]", "assert group_tuples([('a', 'b'), ('a', 'c'), ('d', 'e')]) == [('a', 'b', 'c'), ('d', 'e')]", "assert group_tuples([('f', 'g'), ('f', 'g'), ('h', 'i')]) == [('f', 'g', 'g'), ('h', 'i')]" ]
[]
418
Write a python function to find the sublist having maximum length.
def Find_Max(lst): maxList = max((x) for x in lst) return maxList
[ "assert Find_Max([['A'],['A','B'],['A','B','C']]) == ['A','B','C']", "assert Find_Max([[1],[1,2],[1,2,3]]) == [1,2,3]", "assert Find_Max([[1,1],[1,2,3],[1,5,6,1]]) == [1,5,6,1]" ]
[]
419
Write a function to round every number of a given list of numbers and print the total sum multiplied by the length of the list.
def round_and_sum(list1): lenght=len(list1) round_and_sum=sum(list(map(round,list1))* lenght) return round_and_sum
[ "assert round_and_sum([22.4, 4.0, -16.22, -9.10, 11.00, -12.22, 14.20, -5.20, 17.50])==243", "assert round_and_sum([5,2,9,24.3,29])==345", "assert round_and_sum([25.0,56.7,89.2])==513" ]
[]
420
Write a python function to find the cube sum of first n even natural numbers.
def cube_Sum(n): sum = 0 for i in range(1,n + 1): sum += (2*i)*(2*i)*(2*i) return sum
[ "assert cube_Sum(2) == 72", "assert cube_Sum(3) == 288", "assert cube_Sum(4) == 800" ]
[]
421
Write a function to concatenate each element of tuple by the delimiter.
def concatenate_tuple(test_tup): delim = "-" res = ''.join([str(ele) + delim for ele in test_tup]) res = res[ : len(res) - len(delim)] return (str(res))
[ "assert concatenate_tuple((\"ID\", \"is\", 4, \"UTS\") ) == 'ID-is-4-UTS'", "assert concatenate_tuple((\"QWE\", \"is\", 4, \"RTY\") ) == 'QWE-is-4-RTY'", "assert concatenate_tuple((\"ZEN\", \"is\", 4, \"OP\") ) == 'ZEN-is-4-OP'" ]
[]
422
Write a python function to find the average of cubes of first n natural numbers.
def find_Average_Of_Cube(n): sum = 0 for i in range(1, n + 1): sum += i * i * i return round(sum / n, 6)
[ "assert find_Average_Of_Cube(2) == 4.5", "assert find_Average_Of_Cube(3) == 12", "assert find_Average_Of_Cube(1) == 1" ]
[]
423
Write a function to solve gold mine problem.
def get_maxgold(gold, m, n): goldTable = [[0 for i in range(n)] for j in range(m)] for col in range(n-1, -1, -1): for row in range(m): if (col == n-1): right = 0 else: right = goldTable[row][col+1] if (row == 0 or col == n-1): right_up = 0 else: right_up = goldTable[row-1][col+1] if (row == m-1 or col == n-1): right_down = 0 else: right_down = goldTable[row+1][col+1] goldTable[row][col] = gold[row][col] + max(right, right_up, right_down) res = goldTable[0][0] for i in range(1, m): res = max(res, goldTable[i][0]) return res
[ "assert get_maxgold([[1, 3, 1, 5],[2, 2, 4, 1],[5, 0, 2, 3],[0, 6, 1, 2]],4,4)==16", "assert get_maxgold([[10,20],[30,40]],2,2)==70", "assert get_maxgold([[4,9],[3,7]],2,2)==13" ]
[]
424
Write a function to extract only the rear index element of each string in the given tuple.
def extract_rear(test_tuple): res = list(sub[len(sub) - 1] for sub in test_tuple) return (res)
[ "assert extract_rear(('Mers', 'for', 'Vers') ) == ['s', 'r', 's']", "assert extract_rear(('Avenge', 'for', 'People') ) == ['e', 'r', 'e']", "assert extract_rear(('Gotta', 'get', 'go') ) == ['a', 't', 'o']" ]
[]
425
Write a function to count the number of sublists containing a particular element.
def count_element_in_list(list1, x): ctr = 0 for i in range(len(list1)): if x in list1[i]: ctr+= 1 return ctr
[ "assert count_element_in_list([[1, 3], [5, 7], [1, 11], [1, 15, 7]],1)==3", "assert count_element_in_list([['A', 'B'], ['A', 'C'], ['A', 'D', 'E'], ['B', 'C', 'D']],'A')==3", "assert count_element_in_list([['A', 'B'], ['A', 'C'], ['A', 'D', 'E'], ['B', 'C', 'D']],'E')==1" ]
[]
426
Write a function to filter odd numbers using lambda function.
def filter_oddnumbers(nums): odd_nums = list(filter(lambda x: x%2 != 0, nums)) return odd_nums
[ "assert filter_oddnumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9]", "assert filter_oddnumbers([10,20,45,67,84,93])==[45,67,93]", "assert filter_oddnumbers([5,7,9,8,6,4,3])==[5,7,9,3]" ]
[]
427
Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format by using regex.
import re def change_date_format(dt): return re.sub(r'(\d{4})-(\d{1,2})-(\d{1,2})', '\\3-\\2-\\1', dt)
[ "assert change_date_format(\"2026-01-02\") == '02-01-2026'", "assert change_date_format(\"2020-11-13\") == '13-11-2020'", "assert change_date_format(\"2021-04-26\") == '26-04-2021'" ]
[]
428
Write a function to sort the given array by using shell sort.
def shell_sort(my_list): gap = len(my_list) // 2 while gap > 0: for i in range(gap, len(my_list)): current_item = my_list[i] j = i while j >= gap and my_list[j - gap] > current_item: my_list[j] = my_list[j - gap] j -= gap my_list[j] = current_item gap //= 2 return my_list
[ "assert shell_sort([12, 23, 4, 5, 3, 2, 12, 81, 56, 95]) == [2, 3, 4, 5, 12, 12, 23, 56, 81, 95]", "assert shell_sort([24, 22, 39, 34, 87, 73, 68]) == [22, 24, 34, 39, 68, 73, 87]", "assert shell_sort([32, 30, 16, 96, 82, 83, 74]) == [16, 30, 32, 74, 82, 83, 96]" ]
[]
429
Write a function to extract the elementwise and tuples from the given two tuples.
def and_tuples(test_tup1, test_tup2): res = tuple(ele1 & ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res)
[ "assert and_tuples((10, 4, 6, 9), (5, 2, 3, 3)) == (0, 0, 2, 1)", "assert and_tuples((1, 2, 3, 4), (5, 6, 7, 8)) == (1, 2, 3, 0)", "assert and_tuples((8, 9, 11, 12), (7, 13, 14, 17)) == (0, 9, 10, 0)" ]
[]
430
Write a function to find the directrix of a parabola.
def parabola_directrix(a, b, c): directrix=((int)(c - ((b * b) + 1) * 4 * a )) return directrix
[ "assert parabola_directrix(5,3,2)==-198", "assert parabola_directrix(9,8,4)==-2336", "assert parabola_directrix(2,4,6)==-130" ]
[]
431
Write a function that takes two lists and returns true if they have at least one common element.
def common_element(list1, list2): result = False for x in list1: for y in list2: if x == y: result = True return result
[ "assert common_element([1,2,3,4,5], [5,6,7,8,9])==True", "assert common_element([1,2,3,4,5], [6,7,8,9])==None", "assert common_element(['a','b','c'], ['d','b','e'])==True" ]
[]
432
Write a function to find the median of a trapezium.
def median_trapezium(base1,base2,height): median = 0.5 * (base1+ base2) return median
[ "assert median_trapezium(15,25,35)==20", "assert median_trapezium(10,20,30)==15", "assert median_trapezium(6,9,4)==7.5" ]
[]
433
Write a function to check whether the entered number is greater than the elements of the given array.
def check_greater(arr, number): arr.sort() if number > arr[-1]: return ('Yes, the entered number is greater than those in the array') else: return ('No, entered number is less than those in the array')
[ "assert check_greater([1, 2, 3, 4, 5], 4) == 'No, entered number is less than those in the array'", "assert check_greater([2, 3, 4, 5, 6], 8) == 'Yes, the entered number is greater than those in the array'", "assert check_greater([9, 7, 4, 8, 6, 1], 11) == 'Yes, the entered number is greater than those in the array'" ]
[]
434
Write a function that matches a string that has an a followed by one or more b's.
import re def text_match_one(text): patterns = 'ab+?' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
[ "assert text_match_one(\"ac\")==('Not matched!')", "assert text_match_one(\"dc\")==('Not matched!')", "assert text_match_one(\"abba\")==('Found a match!')" ]
[]
435
Write a python function to find the last digit of a given number.
def last_Digit(n) : return (n % 10)
[ "assert last_Digit(123) == 3", "assert last_Digit(25) == 5", "assert last_Digit(30) == 0" ]
[]
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" ]
[]
437
Write a function to remove odd characters in a string.
def remove_odd(str1): str2 = '' for i in range(1, len(str1) + 1): if(i % 2 == 0): str2 = str2 + str1[i - 1] return str2
[ "assert remove_odd(\"python\")==(\"yhn\")", "assert remove_odd(\"program\")==(\"rga\")", "assert remove_odd(\"language\")==(\"agae\")" ]
[]
438
Write a function to count bidirectional tuple pairs.
def count_bidirectional(test_list): res = 0 for idx in range(0, len(test_list)): for iidx in range(idx + 1, len(test_list)): if test_list[iidx][0] == test_list[idx][1] and test_list[idx][1] == test_list[iidx][0]: res += 1 return (str(res))
[ "assert count_bidirectional([(5, 6), (1, 2), (6, 5), (9, 1), (6, 5), (2, 1)] ) == '3'", "assert count_bidirectional([(5, 6), (1, 3), (6, 5), (9, 1), (6, 5), (2, 1)] ) == '2'", "assert count_bidirectional([(5, 6), (1, 2), (6, 5), (9, 2), (6, 5), (2, 1)] ) == '4'" ]
[]
439
Write a function to convert a list of multiple integers into a single integer.
def multiple_to_single(L): x = int("".join(map(str, L))) return x
[ "assert multiple_to_single([11, 33, 50])==113350", "assert multiple_to_single([-1,2,3,4,5,6])==-123456", "assert multiple_to_single([10,15,20,25])==10152025" ]
[]
440
Write a function to find all adverbs and their positions in a given sentence.
import re def find_adverb_position(text): for m in re.finditer(r"\w+ly", text): return (m.start(), m.end(), m.group(0))
[ "assert find_adverb_position(\"clearly!! we can see the sky\")==(0, 7, 'clearly')", "assert find_adverb_position(\"seriously!! there are many roses\")==(0, 9, 'seriously')", "assert find_adverb_position(\"unfortunately!! sita is going to home\")==(0, 13, 'unfortunately')" ]
[]
441
Write a function to find the surface area of a cube.
def surfacearea_cube(l): surfacearea= 6*l*l return surfacearea
[ "assert surfacearea_cube(5)==150", "assert surfacearea_cube(3)==54", "assert surfacearea_cube(10)==600" ]
[]
442
Write a function to find the ration of positive numbers in an array of integers.
from array import array def positive_count(nums): n = len(nums) n1 = 0 for x in nums: if x > 0: n1 += 1 else: None return round(n1/n,2)
[ "assert positive_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8])==0.54", "assert positive_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==0.69", "assert positive_count([2, 4, -6, -9, 11, -12, 14, -5, 17])==0.56" ]
[]
443
Write a python function to find the largest negative number from the given list.
def largest_neg(list1): max = list1[0] for x in list1: if x < max : max = x return max
[ "assert largest_neg([1,2,3,-4,-6]) == -6", "assert largest_neg([1,2,3,-8,-9]) == -9", "assert largest_neg([1,2,3,4,-1]) == -1" ]
[]
444
Write a function to trim each tuple by k in the given tuple list.
def trim_tuple(test_list, K): res = [] for ele in test_list: N = len(ele) res.append(tuple(list(ele)[K: N - K])) return (str(res))
[ "assert trim_tuple([(5, 3, 2, 1, 4), (3, 4, 9, 2, 1),(9, 1, 2, 3, 5), (4, 8, 2, 1, 7)], 2) == '[(2,), (9,), (2,), (2,)]'", "assert trim_tuple([(5, 3, 2, 1, 4), (3, 4, 9, 2, 1), (9, 1, 2, 3, 5), (4, 8, 2, 1, 7)], 1) == '[(3, 2, 1), (4, 9, 2), (1, 2, 3), (8, 2, 1)]'", "assert trim_tuple([(7, 8, 4, 9), (11, 8, 12, 4),(4, 1, 7, 8), (3, 6, 9, 7)], 1) == '[(8, 4), (8, 12), (1, 7), (6, 9)]'" ]
[]
445
Write a function to perform index wise multiplication of tuple elements in the given two tuples.
def index_multiplication(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 index_multiplication(((1, 3), (4, 5), (2, 9), (1, 10)),((6, 7), (3, 9), (1, 1), (7, 3)) ) == ((6, 21), (12, 45), (2, 9), (7, 30))", "assert index_multiplication(((2, 4), (5, 6), (3, 10), (2, 11)),((7, 8), (4, 10), (2, 2), (8, 4)) ) == ((14, 32), (20, 60), (6, 20), (16, 44))", "assert index_multiplication(((3, 5), (6, 7), (4, 11), (3, 12)),((8, 9), (5, 11), (3, 3), (9, 5)) ) == ((24, 45), (30, 77), (12, 33), (27, 60))" ]
[]
446
Write a python function to count the occurence of all elements of list in a tuple.
from collections import Counter def count_Occurrence(tup, lst): count = 0 for item in tup: if item in lst: count+= 1 return count
[ "assert count_Occurrence(('a', 'a', 'c', 'b', 'd'),['a', 'b'] ) == 3", "assert count_Occurrence((1, 2, 3, 1, 4, 6, 7, 1, 4),[1, 4, 7]) == 6", "assert count_Occurrence((1,2,3,4,5,6),[1,2]) == 2" ]
[]
447
Write a function to find cubes of individual elements in a list using lambda function.
def cube_nums(nums): cube_nums = list(map(lambda x: x ** 3, nums)) return cube_nums
[ "assert cube_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]", "assert cube_nums([10,20,30])==([1000, 8000, 27000])", "assert cube_nums([12,15])==([1728, 3375])" ]
[]
448
Write a function to calculate the sum of perrin numbers.
def cal_sum(n): a = 3 b = 0 c = 2 if (n == 0): return 3 if (n == 1): return 3 if (n == 2): return 5 sum = 5 while (n > 2): d = a + b sum = sum + d a = b b = c c = d n = n-1 return sum
[ "assert cal_sum(9) == 49", "assert cal_sum(10) == 66", "assert cal_sum(11) == 88" ]
[]
449
Write a python function to check whether the triangle is valid or not if 3 points are given.
def check_Triangle(x1,y1,x2,y2,x3,y3): a = (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)) if a == 0: return ('No') else: return ('Yes')
[ "assert check_Triangle(1,5,2,5,4,6) == 'Yes'", "assert check_Triangle(1,1,1,4,1,5) == 'No'", "assert check_Triangle(1,1,1,1,1,1) == 'No'" ]
[]
450
Write a function to extract specified size of strings from a give list of string values.
def extract_string(str, l): result = [e for e in str if len(e) == l] return result
[ "assert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,8)==['practice', 'solution']", "assert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,6)==['Python']", "assert extract_string(['Python', 'list', 'exercises', 'practice', 'solution'] ,9)==['exercises']" ]
[]
451
Write a function to remove all whitespaces from the given string using regex.
import re def remove_whitespaces(text1): return (re.sub(r'\s+', '',text1))
[ "assert remove_whitespaces(' Google Flutter ') == 'GoogleFlutter'", "assert remove_whitespaces(' Google Dart ') == 'GoogleDart'", "assert remove_whitespaces(' iOS Swift ') == 'iOSSwift'" ]
[]
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" ]
[]
453
Write a python function to find the sum of even factors of a number.
import math def sumofFactors(n) : if (n % 2 != 0) : return 0 res = 1 for i in range(2, (int)(math.sqrt(n)) + 1) : count = 0 curr_sum = 1 curr_term = 1 while (n % i == 0) : count= count + 1 n = n // i if (i == 2 and count == 1) : curr_sum = 0 curr_term = curr_term * i curr_sum = curr_sum + curr_term res = res * curr_sum if (n >= 2) : res = res * (1 + n) return res
[ "assert sumofFactors(18) == 26", "assert sumofFactors(30) == 48", "assert sumofFactors(6) == 8" ]
[]
454
Write a function that matches a word containing 'z'.
import re def text_match_wordz(text): patterns = '\w*z.\w*' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
[ "assert text_match_wordz(\"pythonz.\")==('Found a match!')", "assert text_match_wordz(\"xyz.\")==('Found a match!')", "assert text_match_wordz(\" lang .\")==('Not matched!')" ]
[]
455
Write a function to check whether the given month number contains 31 days or not.
def check_monthnumb_number(monthnum2): if(monthnum2==1 or monthnum2==3 or monthnum2==5 or monthnum2==7 or monthnum2==8 or monthnum2==10 or monthnum2==12): return True else: return False
[ "assert check_monthnumb_number(5)==True", "assert check_monthnumb_number(2)==False", "assert check_monthnumb_number(6)==False" ]
[]
456
Write a function to reverse strings in a given list of string values.
def reverse_string_list(stringlist): result = [x[::-1] for x in stringlist] return result
[ "assert reverse_string_list(['Red', 'Green', 'Blue', 'White', 'Black'])==['deR', 'neerG', 'eulB', 'etihW', 'kcalB']", "assert reverse_string_list(['john','amal','joel','george'])==['nhoj','lama','leoj','egroeg']", "assert reverse_string_list(['jack','john','mary'])==['kcaj','nhoj','yram']" ]
[]
457
Write a python function to find the sublist having minimum length.
def Find_Min(lst): minList = min((x) for x in lst) return minList
[ "assert Find_Min([[1],[1,2],[1,2,3]]) == [1]", "assert Find_Min([[1,1],[1,1,1],[1,2,7,8]]) == [1,1]", "assert Find_Min([['x'],['x','y'],['x','y','z']]) == ['x']" ]
[]
458
Write a function to find the area of a rectangle.
def rectangle_area(l,b): area=l*b return area
[ "assert rectangle_area(10,20)==200", "assert rectangle_area(10,5)==50", "assert rectangle_area(4,2)==8" ]
[]
459
Write a function to remove uppercase substrings from a given string by using regex.
import re def remove_uppercase(str1): remove_upper = lambda text: re.sub('[A-Z]', '', text) result = remove_upper(str1) return (result)
[ "assert remove_uppercase('cAstyoUrFavoRitETVshoWs') == 'cstyoravoitshos'", "assert remove_uppercase('wAtchTheinTernEtrAdIo') == 'wtchheinerntrdo'", "assert remove_uppercase('VoicESeaRchAndreComMendaTionS') == 'oiceachndreomendaion'" ]
[]
460
Write a python function to get the first element of each sublist.
def Extract(lst): return [item[0] for item in lst]
[ "assert Extract([[1, 2], [3, 4, 5], [6, 7, 8, 9]]) == [1, 3, 6]", "assert Extract([[1,2,3],[4, 5]]) == [1,4]", "assert Extract([[9,8,1],[1,2]]) == [9,1]" ]
[]
461
Write a python function to count the upper case characters in a given string.
def upper_ctr(str): upper_ctr = 0 for i in range(len(str)): if str[i] >= 'A' and str[i] <= 'Z': upper_ctr += 1 return upper_ctr
[ "assert upper_ctr('PYthon') == 1", "assert upper_ctr('BigData') == 1", "assert upper_ctr('program') == 0" ]
[]
462
Write a function to find all possible combinations of the elements of a given list.
def combinations_list(list1): if len(list1) == 0: return [[]] result = [] for el in combinations_list(list1[1:]): result += [el, el+[list1[0]]] return result
[ "assert combinations_list(['orange', 'red', 'green', 'blue'])==[[], ['orange'], ['red'], ['red', 'orange'], ['green'], ['green', 'orange'], ['green', 'red'], ['green', 'red', 'orange'], ['blue'], ['blue', 'orange'], ['blue', 'red'], ['blue', 'red', 'orange'], ['blue', 'green'], ['blue', 'green', 'orange'], ['blue', 'green', 'red'], ['blue', 'green', 'red', 'orange']]", "assert combinations_list(['red', 'green', 'blue', 'white', 'black', 'orange'])==[[], ['red'], ['green'], ['green', 'red'], ['blue'], ['blue', 'red'], ['blue', 'green'], ['blue', 'green', 'red'], ['white'], ['white', 'red'], ['white', 'green'], ['white', 'green', 'red'], ['white', 'blue'], ['white', 'blue', 'red'], ['white', 'blue', 'green'], ['white', 'blue', 'green', 'red'], ['black'], ['black', 'red'], ['black', 'green'], ['black', 'green', 'red'], ['black', 'blue'], ['black', 'blue', 'red'], ['black', 'blue', 'green'], ['black', 'blue', 'green', 'red'], ['black', 'white'], ['black', 'white', 'red'], ['black', 'white', 'green'], ['black', 'white', 'green', 'red'], ['black', 'white', 'blue'], ['black', 'white', 'blue', 'red'], ['black', 'white', 'blue', 'green'], ['black', 'white', 'blue', 'green', 'red'], ['orange'], ['orange', 'red'], ['orange', 'green'], ['orange', 'green', 'red'], ['orange', 'blue'], ['orange', 'blue', 'red'], ['orange', 'blue', 'green'], ['orange', 'blue', 'green', 'red'], ['orange', 'white'], ['orange', 'white', 'red'], ['orange', 'white', 'green'], ['orange', 'white', 'green', 'red'], ['orange', 'white', 'blue'], ['orange', 'white', 'blue', 'red'], ['orange', 'white', 'blue', 'green'], ['orange', 'white', 'blue', 'green', 'red'], ['orange', 'black'], ['orange', 'black', 'red'], ['orange', 'black', 'green'], ['orange', 'black', 'green', 'red'], ['orange', 'black', 'blue'], ['orange', 'black', 'blue', 'red'], ['orange', 'black', 'blue', 'green'], ['orange', 'black', 'blue', 'green', 'red'], ['orange', 'black', 'white'], ['orange', 'black', 'white', 'red'], ['orange', 'black', 'white', 'green'], ['orange', 'black', 'white', 'green', 'red'], ['orange', 'black', 'white', 'blue'], ['orange', 'black', 'white', 'blue', 'red'], ['orange', 'black', 'white', 'blue', 'green'], ['orange', 'black', 'white', 'blue', 'green', 'red']]", "assert combinations_list(['red', 'green', 'black', 'orange'])==[[], ['red'], ['green'], ['green', 'red'], ['black'], ['black', 'red'], ['black', 'green'], ['black', 'green', 'red'], ['orange'], ['orange', 'red'], ['orange', 'green'], ['orange', 'green', 'red'], ['orange', 'black'], ['orange', 'black', 'red'], ['orange', 'black', 'green'], ['orange', 'black', 'green', 'red']]" ]
[]
463
Write a function to find the maximum product subarray of the given array.
def max_subarray_product(arr): n = len(arr) max_ending_here = 1 min_ending_here = 1 max_so_far = 0 flag = 0 for i in range(0, n): if arr[i] > 0: max_ending_here = max_ending_here * arr[i] min_ending_here = min (min_ending_here * arr[i], 1) flag = 1 elif arr[i] == 0: max_ending_here = 1 min_ending_here = 1 else: temp = max_ending_here max_ending_here = max (min_ending_here * arr[i], 1) min_ending_here = temp * arr[i] if (max_so_far < max_ending_here): max_so_far = max_ending_here if flag == 0 and max_so_far == 0: return 0 return max_so_far
[ "assert max_subarray_product([1, -2, -3, 0, 7, -8, -2]) == 112", "assert max_subarray_product([6, -3, -10, 0, 2]) == 180 ", "assert max_subarray_product([-2, -40, 0, -2, -3]) == 80" ]
[]
464
Write a function to check if all values are same in a dictionary.
def check_value(dict, n): result = all(x == n for x in dict.values()) return result
[ "assert check_value({'Cierra Vega': 12, 'Alden Cantrell': 12, 'Kierra Gentry': 12, 'Pierre Cox': 12},10)==False", "assert check_value({'Cierra Vega': 12, 'Alden Cantrell': 12, 'Kierra Gentry': 12, 'Pierre Cox': 12},12)==True", "assert check_value({'Cierra Vega': 12, 'Alden Cantrell': 12, 'Kierra Gentry': 12, 'Pierre Cox': 12},5)==False" ]
[]
465
Write a function to drop empty items from a given dictionary.
def drop_empty(dict1): dict1 = {key:value for (key, value) in dict1.items() if value is not None} return dict1
[ "assert drop_empty({'c1': 'Red', 'c2': 'Green', 'c3':None})=={'c1': 'Red', 'c2': 'Green'}", "assert drop_empty({'c1': 'Red', 'c2': None, 'c3':None})=={'c1': 'Red'}", "assert drop_empty({'c1': None, 'c2': 'Green', 'c3':None})=={ 'c2': 'Green'}" ]
[]
466
Write a function to find the peak element in the given array.
def find_peak_util(arr, low, high, n): mid = low + (high - low)/2 mid = int(mid) if ((mid == 0 or arr[mid - 1] <= arr[mid]) and (mid == n - 1 or arr[mid + 1] <= arr[mid])): return mid elif (mid > 0 and arr[mid - 1] > arr[mid]): return find_peak_util(arr, low, (mid - 1), n) else: return find_peak_util(arr, (mid + 1), high, n) def find_peak(arr, n): return find_peak_util(arr, 0, n - 1, n)
[ "assert find_peak([1, 3, 20, 4, 1, 0], 6) == 2", "assert find_peak([2, 3, 4, 5, 6], 5) == 4", "assert find_peak([8, 9, 11, 12, 14, 15], 6) == 5 " ]
[]
467
Write a python function to convert decimal number to octal number.
def decimal_to_Octal(deciNum): octalNum = 0 countval = 1; dNo = deciNum; while (deciNum!= 0): remainder= deciNum % 8; octalNum+= remainder*countval; countval= countval*10; deciNum //= 8; return (octalNum)
[ "assert decimal_to_Octal(10) == 12", "assert decimal_to_Octal(2) == 2", "assert decimal_to_Octal(33) == 41" ]
[]
468
Write a function to find the maximum product formed by multiplying numbers of an increasing subsequence of that array.
def max_product(arr, n ): mpis =[0] * (n) for i in range(n): mpis[i] = arr[i] for i in range(1, n): for j in range(i): if (arr[i] > arr[j] and mpis[i] < (mpis[j] * arr[i])): mpis[i] = mpis[j] * arr[i] return max(mpis)
[ "assert max_product([3, 100, 4, 5, 150, 6], 6) == 45000 ", "assert max_product([4, 42, 55, 68, 80], 5) == 50265600", "assert max_product([10, 22, 9, 33, 21, 50, 41, 60], 8) == 21780000 " ]
[]
469
Write a function to find the maximum profit earned from a maximum of k stock transactions
def max_profit(price, k): n = len(price) final_profit = [[None for x in range(n)] for y in range(k + 1)] for i in range(k + 1): for j in range(n): if i == 0 or j == 0: final_profit[i][j] = 0 else: max_so_far = 0 for x in range(j): curr_price = price[j] - price[x] + final_profit[i-1][x] if max_so_far < curr_price: max_so_far = curr_price final_profit[i][j] = max(final_profit[i][j-1], max_so_far) return final_profit[k][n-1]
[ "assert max_profit([1, 5, 2, 3, 7, 6, 4, 5], 3) == 10", "assert max_profit([2, 4, 7, 5, 4, 3, 5], 2) == 7", "assert max_profit([10, 6, 8, 4, 2], 2) == 2" ]
[]
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)" ]
[]
471
Write a python function to find remainder of array multiplication divided by n.
def find_remainder(arr, lens, n): mul = 1 for i in range(lens): mul = (mul * (arr[i] % n)) % n return mul % n
[ "assert find_remainder([ 100, 10, 5, 25, 35, 14 ],6,11) ==9", "assert find_remainder([1,1,1],3,1) == 0", "assert find_remainder([1,2,1],3,2) == 0" ]
[]
472
Write a python function to check whether the given list contains consecutive numbers or not.
def check_Consecutive(l): return sorted(l) == list(range(min(l),max(l)+1))
[ "assert check_Consecutive([1,2,3,4,5]) == True", "assert check_Consecutive([1,2,3,5,6]) == False", "assert check_Consecutive([1,2,1]) == False" ]
[]
473
Write a function to find the tuple intersection of elements in the given tuple list irrespective of their order.
def tuple_intersection(test_list1, test_list2): res = set([tuple(sorted(ele)) for ele in test_list1]) & set([tuple(sorted(ele)) for ele in test_list2]) return (res)
[ "assert tuple_intersection([(3, 4), (5, 6), (9, 10), (4, 5)] , [(5, 4), (3, 4), (6, 5), (9, 11)]) == {(4, 5), (3, 4), (5, 6)}", "assert tuple_intersection([(4, 1), (7, 4), (11, 13), (17, 14)] , [(1, 4), (7, 4), (16, 12), (10, 13)]) == {(4, 7), (1, 4)}", "assert tuple_intersection([(2, 1), (3, 2), (1, 3), (1, 4)] , [(11, 2), (2, 3), (6, 2), (1, 3)]) == {(1, 3), (2, 3)}" ]
[]
474
Write a function to replace characters in a string.
def replace_char(str1,ch,newch): str2 = str1.replace(ch, newch) return str2
[ "assert replace_char(\"polygon\",'y','l')==(\"pollgon\")", "assert replace_char(\"character\",'c','a')==(\"aharaater\")", "assert replace_char(\"python\",'l','a')==(\"python\")" ]
[]
475
Write a function to sort counter by value.
from collections import Counter def sort_counter(dict1): x = Counter(dict1) sort_counter=x.most_common() return sort_counter
[ "assert sort_counter({'Math':81, 'Physics':83, 'Chemistry':87})==[('Chemistry', 87), ('Physics', 83), ('Math', 81)]", "assert sort_counter({'Math':400, 'Physics':300, 'Chemistry':250})==[('Math', 400), ('Physics', 300), ('Chemistry', 250)]", "assert sort_counter({'Math':900, 'Physics':1000, 'Chemistry':1250})==[('Chemistry', 1250), ('Physics', 1000), ('Math', 900)]" ]
[]
476
Write a python function to find the sum of the largest and smallest value in a given array.
def big_sum(nums): sum= max(nums)+min(nums) return sum
[ "assert big_sum([1,2,3]) == 4", "assert big_sum([-1,2,3,4]) == 3", "assert big_sum([2,3,6]) == 8" ]
[]
477
Write a python function to convert the given string to lower case.
def is_lower(string): return (string.lower())
[ "assert is_lower(\"InValid\") == \"invalid\"", "assert is_lower(\"TruE\") == \"true\"", "assert is_lower(\"SenTenCE\") == \"sentence\"" ]
[]
478
Write a function to remove lowercase substrings from a given string.
import re def remove_lowercase(str1): remove_lower = lambda text: re.sub('[a-z]', '', text) result = remove_lower(str1) return result
[ "assert remove_lowercase(\"PYTHon\")==('PYTH')", "assert remove_lowercase(\"FInD\")==('FID')", "assert remove_lowercase(\"STRinG\")==('STRG')" ]
[]
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" ]
[]
480
Write a python function to find the maximum occurring character in a given string.
def get_max_occuring_char(str1): ASCII_SIZE = 256 ctr = [0] * ASCII_SIZE max = -1 ch = '' for i in str1: ctr[ord(i)]+=1; for i in str1: if max < ctr[ord(i)]: max = ctr[ord(i)] ch = i return ch
[ "assert get_max_occuring_char(\"data\") == \"a\"", "assert get_max_occuring_char(\"create\") == \"e\"", "assert get_max_occuring_char(\"brilliant girl\") == \"i\"" ]
[]
481
Write a function to determine if there is a subset of the given set with sum equal to the given sum.
def is_subset_sum(set, n, sum): if (sum == 0): return True if (n == 0): return False if (set[n - 1] > sum): return is_subset_sum(set, n - 1, sum) return is_subset_sum(set, n-1, sum) or is_subset_sum(set, n-1, sum-set[n-1])
[ "assert is_subset_sum([3, 34, 4, 12, 5, 2], 6, 9) == True", "assert is_subset_sum([3, 34, 4, 12, 5, 2], 6, 30) == False", "assert is_subset_sum([3, 34, 4, 12, 5, 2], 6, 15) == True" ]
[]
482
Write a function to find sequences of one upper case letter followed by lower case letters in the given string by using regex.
import re def match(text): pattern = '[A-Z]+[a-z]+$' if re.search(pattern, text): return('Yes') else: return('No')
[ "assert match(\"Geeks\") == 'Yes'", "assert match(\"geeksforGeeks\") == 'Yes'", "assert match(\"geeks\") == 'No'" ]
[]
483
Write a python function to find the first natural number whose factorial is divisible by x.
def first_Factorial_Divisible_Number(x): i = 1; fact = 1; for i in range(1,x): fact = fact * i if (fact % x == 0): break return i
[ "assert first_Factorial_Divisible_Number(10) == 5", "assert first_Factorial_Divisible_Number(15) == 5", "assert first_Factorial_Divisible_Number(5) == 4" ]
[]
484
Write a function to remove the matching tuples from the given two tuples.
def remove_matching_tuple(test_list1, test_list2): res = [sub for sub in test_list1 if sub not in test_list2] return (res)
[ "assert remove_matching_tuple([('Hello', 'dude'), ('How', 'are'), ('you', '?')], [('Hello', 'dude'), ('How', 'are')]) == [('you', '?')]", "assert remove_matching_tuple([('Part', 'of'), ('the', 'journey'), ('is ', 'end')], [('Journey', 'the'), ('is', 'end')]) == [('Part', 'of'), ('the', 'journey'), ('is ', 'end')]", "assert remove_matching_tuple([('Its', 'been'), ('a', 'long'), ('day', 'without')], [('a', 'long'), ('my', 'friend')]) == [('Its', 'been'), ('day', 'without')]" ]
[]
485
Write a function to find the largest palindromic number in the given array.
def is_palindrome(n) : divisor = 1 while (n / divisor >= 10) : divisor *= 10 while (n != 0) : leading = n // divisor trailing = n % 10 if (leading != trailing) : return False n = (n % divisor) // 10 divisor = divisor // 100 return True def largest_palindrome(A, n) : A.sort() for i in range(n - 1, -1, -1) : if (is_palindrome(A[i])) : return A[i] return -1
[ "assert largest_palindrome([1, 232, 54545, 999991], 4) == 54545", "assert largest_palindrome([1, 2, 3, 4, 5, 50], 6) == 5", "assert largest_palindrome([1, 3, 7, 9, 45], 5) == 9" ]
[]
486
Write a function to compute binomial probability for the given number.
def nCr(n, r): if (r > n / 2): r = n - r answer = 1 for i in range(1, r + 1): answer *= (n - r + i) answer /= i return answer def binomial_probability(n, k, p): return (nCr(n, k) * pow(p, k) * pow(1 - p, n - k))
[ "assert binomial_probability(10, 5, 1.0/3) == 0.13656454808718185", "assert binomial_probability(11, 6, 2.0/4) == 0.2255859375", "assert binomial_probability(12, 7, 3.0/5) == 0.227030335488" ]
[]
487
Write a function to sort a list of tuples in increasing order by the last element in each tuple.
def sort_tuple(tup): lst = len(tup) for i in range(0, lst): for j in range(0, lst-i-1): if (tup[j][-1] > tup[j + 1][-1]): temp = tup[j] tup[j]= tup[j + 1] tup[j + 1]= temp return tup
[ "assert sort_tuple([(1, 3), (3, 2), (2, 1)] ) == [(2, 1), (3, 2), (1, 3)]", "assert sort_tuple([(2, 4), (3, 3), (1, 1)] ) == [(1, 1), (3, 3), (2, 4)]", "assert sort_tuple([(3, 9), (6, 7), (4, 3)] ) == [(4, 3), (6, 7), (3, 9)]" ]
[]
488
Write a function to find the area of a pentagon.
import math def area_pentagon(a): area=(math.sqrt(5*(5+2*math.sqrt(5)))*pow(a,2))/4.0 return area
[ "assert area_pentagon(5)==43.01193501472417", "assert area_pentagon(10)==172.0477400588967", "assert area_pentagon(15)==387.10741513251753" ]
[]
489
Write a python function to find the frequency of the largest value in a given array.
def frequency_Of_Largest(n,arr): mn = arr[0] freq = 1 for i in range(1,n): if (arr[i] >mn): mn = arr[i] freq = 1 elif (arr[i] == mn): freq += 1 return freq
[ "assert frequency_Of_Largest(5,[1,2,3,4,4]) == 2", "assert frequency_Of_Largest(3,[5,6,5]) == 1", "assert frequency_Of_Largest(4,[2,7,7,7]) == 3" ]
[]
490
Write a function to extract all the pairs which are symmetric in the given tuple list.
def extract_symmetric(test_list): temp = set(test_list) & {(b, a) for a, b in test_list} res = {(a, b) for a, b in temp if a < b} return (res)
[ "assert extract_symmetric([(6, 7), (2, 3), (7, 6), (9, 8), (10, 2), (8, 9)] ) == {(8, 9), (6, 7)}", "assert extract_symmetric([(7, 8), (3, 4), (8, 7), (10, 9), (11, 3), (9, 10)] ) == {(9, 10), (7, 8)}", "assert extract_symmetric([(8, 9), (4, 5), (9, 8), (11, 10), (12, 4), (10, 11)] ) == {(8, 9), (10, 11)}" ]
[]
491
Write a function to find the sum of geometric progression series.
import math def sum_gp(a,n,r): total = (a * (1 - math.pow(r, n ))) / (1- r) return total
[ "assert sum_gp(1,5,2)==31", "assert sum_gp(1,5,4)==341", "assert sum_gp(2,6,3)==728" ]
[]
492
Write a function to search an element in the given array by using binary search.
def binary_search(item_list,item): first = 0 last = len(item_list)-1 found = False while( first<=last and not found): mid = (first + last)//2 if item_list[mid] == item : found = True else: if item < item_list[mid]: last = mid - 1 else: first = mid + 1 return found
[ "assert binary_search([1,2,3,5,8], 6) == False", "assert binary_search([7, 8, 9, 10, 13], 10) == True", "assert binary_search([11, 13, 14, 19, 22, 36], 23) == False" ]
[]
493
Write a function to calculate a grid of hexagon coordinates where function returns a list of lists containing 6 tuples of x, y point coordinates.
import math def calculate_polygons(startx, starty, endx, endy, radius): sl = (2 * radius) * math.tan(math.pi / 6) p = sl * 0.5 b = sl * math.cos(math.radians(30)) w = b * 2 h = 2 * sl startx = startx - w starty = starty - h endx = endx + w endy = endy + h origx = startx origy = starty xoffset = b yoffset = 3 * p polygons = [] row = 1 counter = 0 while starty < endy: if row % 2 == 0: startx = origx + xoffset else: startx = origx while startx < endx: p1x = startx p1y = starty + p p2x = startx p2y = starty + (3 * p) p3x = startx + b p3y = starty + h p4x = startx + w p4y = starty + (3 * p) p5x = startx + w p5y = starty + p p6x = startx + b p6y = starty poly = [ (p1x, p1y), (p2x, p2y), (p3x, p3y), (p4x, p4y), (p5x, p5y), (p6x, p6y), (p1x, p1y)] polygons.append(poly) counter += 1 startx += w starty += yoffset row += 1 return polygons
[ "assert calculate_polygons(1,1, 4, 4, 3)==[[(-5.0, -4.196152422706632), (-5.0, -0.7320508075688767), (-2.0, 1.0), (1.0, -0.7320508075688767), (1.0, -4.196152422706632), (-2.0, -5.928203230275509), (-5.0, -4.196152422706632)], [(1.0, -4.196152422706632), (1.0, -0.7320508075688767), (4.0, 1.0), (7.0, -0.7320508075688767), (7.0, -4.196152422706632), (4.0, -5.928203230275509), (1.0, -4.196152422706632)], [(7.0, -4.196152422706632), (7.0, -0.7320508075688767), (10.0, 1.0), (13.0, -0.7320508075688767), (13.0, -4.196152422706632), (10.0, -5.928203230275509), (7.0, -4.196152422706632)], [(-2.0, 1.0000000000000004), (-2.0, 4.464101615137755), (1.0, 6.196152422706632), (4.0, 4.464101615137755), (4.0, 1.0000000000000004), (1.0, -0.7320508075688767), (-2.0, 1.0000000000000004)], [(4.0, 1.0000000000000004), (4.0, 4.464101615137755), (7.0, 6.196152422706632), (10.0, 4.464101615137755), (10.0, 1.0000000000000004), (7.0, -0.7320508075688767), (4.0, 1.0000000000000004)], [(-5.0, 6.196152422706632), (-5.0, 9.660254037844387), (-2.0, 11.392304845413264), (1.0, 9.660254037844387), (1.0, 6.196152422706632), (-2.0, 4.464101615137755), (-5.0, 6.196152422706632)], [(1.0, 6.196152422706632), (1.0, 9.660254037844387), (4.0, 11.392304845413264), (7.0, 9.660254037844387), (7.0, 6.196152422706632), (4.0, 4.464101615137755), (1.0, 6.196152422706632)], [(7.0, 6.196152422706632), (7.0, 9.660254037844387), (10.0, 11.392304845413264), (13.0, 9.660254037844387), (13.0, 6.196152422706632), (10.0, 4.464101615137755), (7.0, 6.196152422706632)], [(-2.0, 11.392304845413264), (-2.0, 14.85640646055102), (1.0, 16.588457268119896), (4.0, 14.85640646055102), (4.0, 11.392304845413264), (1.0, 9.660254037844387), (-2.0, 11.392304845413264)], [(4.0, 11.392304845413264), (4.0, 14.85640646055102), (7.0, 16.588457268119896), (10.0, 14.85640646055102), (10.0, 11.392304845413264), (7.0, 9.660254037844387), (4.0, 11.392304845413264)]]", "assert calculate_polygons(5,4,7,9,8)==[[(-11.0, -9.856406460551018), (-11.0, -0.6188021535170058), (-3.0, 4.0), (5.0, -0.6188021535170058), (5.0, -9.856406460551018), (-3.0, -14.475208614068023), (-11.0, -9.856406460551018)], [(5.0, -9.856406460551018), (5.0, -0.6188021535170058), (13.0, 4.0), (21.0, -0.6188021535170058), (21.0, -9.856406460551018), (13.0, -14.475208614068023), (5.0, -9.856406460551018)], [(21.0, -9.856406460551018), (21.0, -0.6188021535170058), (29.0, 4.0), (37.0, -0.6188021535170058), (37.0, -9.856406460551018), (29.0, -14.475208614068023), (21.0, -9.856406460551018)], [(-3.0, 4.0), (-3.0, 13.237604307034012), (5.0, 17.856406460551018), (13.0, 13.237604307034012), (13.0, 4.0), (5.0, -0.6188021535170058), (-3.0, 4.0)], [(13.0, 4.0), (13.0, 13.237604307034012), (21.0, 17.856406460551018), (29.0, 13.237604307034012), (29.0, 4.0), (21.0, -0.6188021535170058), (13.0, 4.0)], [(-11.0, 17.856406460551018), (-11.0, 27.09401076758503), (-3.0, 31.712812921102035), (5.0, 27.09401076758503), (5.0, 17.856406460551018), (-3.0, 13.237604307034012), (-11.0, 17.856406460551018)], [(5.0, 17.856406460551018), (5.0, 27.09401076758503), (13.0, 31.712812921102035), (21.0, 27.09401076758503), (21.0, 17.856406460551018), (13.0, 13.237604307034012), (5.0, 17.856406460551018)], [(21.0, 17.856406460551018), (21.0, 27.09401076758503), (29.0, 31.712812921102035), (37.0, 27.09401076758503), (37.0, 17.856406460551018), (29.0, 13.237604307034012), (21.0, 17.856406460551018)], [(-3.0, 31.712812921102035), (-3.0, 40.95041722813605), (5.0, 45.569219381653056), (13.0, 40.95041722813605), (13.0, 31.712812921102035), (5.0, 27.09401076758503), (-3.0, 31.712812921102035)], [(13.0, 31.712812921102035), (13.0, 40.95041722813605), (21.0, 45.569219381653056), (29.0, 40.95041722813605), (29.0, 31.712812921102035), (21.0, 27.09401076758503), (13.0, 31.712812921102035)]]", "assert calculate_polygons(9,6,4,3,2)==[[(5.0, 2.5358983848622456), (5.0, 4.8452994616207485), (7.0, 6.0), (9.0, 4.8452994616207485), (9.0, 2.5358983848622456), (7.0, 1.3811978464829942), (5.0, 2.5358983848622456)], [(7.0, 6.0), (7.0, 8.309401076758503), (9.0, 9.464101615137753), (11.0, 8.309401076758503), (11.0, 6.0), (9.0, 4.8452994616207485), (7.0, 6.0)]]" ]
[]
494
Write a function to convert the given binary tuple to integer.
def binary_to_integer(test_tup): res = int("".join(str(ele) for ele in test_tup), 2) return (str(res))
[ "assert binary_to_integer((1, 1, 0, 1, 0, 0, 1)) == '105'", "assert binary_to_integer((0, 1, 1, 0, 0, 1, 0, 1)) == '101'", "assert binary_to_integer((1, 1, 0, 1, 0, 1)) == '53'" ]
[]
495
Write a function to remove lowercase substrings from a given string by using regex.
import re def remove_lowercase(str1): remove_lower = lambda text: re.sub('[a-z]', '', text) result = remove_lower(str1) return (result)
[ "assert remove_lowercase('KDeoALOklOOHserfLoAJSIskdsf') == 'KDALOOOHLAJSI'", "assert remove_lowercase('ProducTnamEstreAmIngMediAplAYer') == 'PTEAIMAAY'", "assert remove_lowercase('maNufacTuredbYSheZenTechNolOGIes') == 'NTYSZTNOGI'" ]
[]
496
Write a function to find the smallest integers from a given list of numbers using heap queue algorithm.
import heapq as hq def heap_queue_smallest(nums,n): smallest_nums = hq.nsmallest(n, nums) return smallest_nums
[ "assert heap_queue_smallest( [25, 35, 22, 85, 14, 65, 75, 25, 58],3)==[14, 22, 25] ", "assert heap_queue_smallest( [25, 35, 22, 85, 14, 65, 75, 25, 58],2)==[14, 22]", "assert heap_queue_smallest( [25, 35, 22, 85, 14, 65, 75, 22, 58],5)==[14, 22, 22, 25, 35]" ]
[]
497
Write a function to find the surface area of a cone.
import math def surfacearea_cone(r,h): l = math.sqrt(r * r + h * h) SA = math.pi * r * (r + l) return SA
[ "assert surfacearea_cone(5,12)==282.7433388230814", "assert surfacearea_cone(10,15)==880.5179353159282", "assert surfacearea_cone(19,17)==2655.923961165254" ]
[]
498
Write a python function to find gcd of two positive integers.
def gcd(x, y): gcd = 1 if x % y == 0: return y for k in range(int(y / 2), 0, -1): if x % k == 0 and y % k == 0: gcd = k break return gcd
[ "assert gcd(12, 17) == 1", "assert gcd(4,6) == 2", "assert gcd(2,9) == 1" ]
[]
499
Write a function to find the diameter of a circle.
def diameter_circle(r): diameter=2*r return diameter
[ "assert diameter_circle(10)==20", "assert diameter_circle(40)==80", "assert diameter_circle(15)==30" ]
[]
500
Write a function to concatenate all elements of the given list into a string.
def concatenate_elements(list): ans = ' ' for i in list: ans = ans+ ' '+i return (ans)
[ "assert concatenate_elements(['hello','there','have','a','rocky','day'] ) == ' hello there have a rocky day'", "assert concatenate_elements([ 'Hi', 'there', 'How','are', 'you'] ) == ' Hi there How are you'", "assert concatenate_elements([ 'Part', 'of', 'the','journey', 'is', 'end'] ) == ' Part of the journey is end'" ]
[]
501
Write a python function to find common divisor between two numbers in a given pair.
def ngcd(x,y): i=1 while(i<=x and i<=y): if(x%i==0 and y%i == 0): gcd=i; i+=1 return gcd; def num_comm_div(x,y): n = ngcd(x,y) result = 0 z = int(n**0.5) i = 1 while(i <= z): if(n % i == 0): result += 2 if(i == n/i): result-=1 i+=1 return result
[ "assert num_comm_div(2,4) == 2", "assert num_comm_div(2,8) == 2", "assert num_comm_div(12,24) == 6" ]
[]
502
Write a python function to find remainder of two numbers.
def find(n,m): r = n%m return (r)
[ "assert find(3,3) == 0", "assert find(10,3) == 1", "assert find(16,5) == 1" ]
[]
503
Write a function to add consecutive numbers of a given list.
def add_consecutive_nums(nums): result = [b+a for a, b in zip(nums[:-1], nums[1:])] return result
[ "assert add_consecutive_nums([1, 1, 3, 4, 4, 5, 6, 7])==[2, 4, 7, 8, 9, 11, 13]", "assert add_consecutive_nums([4, 5, 8, 9, 6, 10])==[9, 13, 17, 15, 16]", "assert add_consecutive_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[3, 5, 7, 9, 11, 13, 15, 17, 19]" ]
[]
504
Write a python function to find the cube sum of first n natural numbers.
def sum_Of_Series(n): sum = 0 for i in range(1,n + 1): sum += i * i*i return sum
[ "assert sum_Of_Series(5) == 225", "assert sum_Of_Series(2) == 9", "assert sum_Of_Series(3) == 36" ]
[]
505
Write a function to move all zeroes to the end of the given array.
def re_order(A): k = 0 for i in A: if i: A[k] = i k = k + 1 for i in range(k, len(A)): A[i] = 0 return A
[ "assert re_order([6, 0, 8, 2, 3, 0, 4, 0, 1]) == [6, 8, 2, 3, 4, 1, 0, 0, 0]", "assert re_order([4, 0, 2, 7, 0, 9, 0, 12, 0]) == [4, 2, 7, 9, 12, 0, 0, 0, 0]", "assert re_order([3, 11, 0, 74, 14, 0, 1, 0, 2]) == [3, 11, 74, 14, 1, 2, 0, 0, 0]" ]
[]
506
Write a function to calculate the permutation coefficient of given p(n, k).
def permutation_coefficient(n, k): P = [[0 for i in range(k + 1)] for j in range(n + 1)] for i in range(n + 1): for j in range(min(i, k) + 1): if (j == 0): P[i][j] = 1 else: P[i][j] = P[i - 1][j] + ( j * P[i - 1][j - 1]) if (j < k): P[i][j + 1] = 0 return P[n][k]
[ "assert permutation_coefficient(10, 2) == 90", "assert permutation_coefficient(10, 3) == 720", "assert permutation_coefficient(10, 1) == 10" ]
[]
507
Write a function to remove specific words from a given list.
def remove_words(list1, removewords): for word in list(list1): if word in removewords: list1.remove(word) return list1
[ "assert remove_words(['red', 'green', 'blue', 'white', 'black', 'orange'],['white', 'orange'])==['red', 'green', 'blue', 'black']", "assert remove_words(['red', 'green', 'blue', 'white', 'black', 'orange'],['black', 'orange'])==['red', 'green', 'blue', 'white']", "assert remove_words(['red', 'green', 'blue', 'white', 'black', 'orange'],['blue', 'white'])==['red', 'green', 'black', 'orange']" ]
[]
508
Write a function to check if the common elements between two given lists are in the same order or not.
def same_order(l1, l2): common_elements = set(l1) & set(l2) l1 = [e for e in l1 if e in common_elements] l2 = [e for e in l2 if e in common_elements] return l1 == l2
[ "assert same_order([\"red\",\"green\",\"black\",\"orange\"],[\"red\",\"pink\",\"green\",\"white\",\"black\"])==True", "assert same_order([\"red\",\"pink\",\"green\",\"white\",\"black\"],[\"white\",\"orange\",\"pink\",\"black\"])==False", "assert same_order([\"red\",\"green\",\"black\",\"orange\"],[\"red\",\"pink\",\"green\",\"white\",\"black\"])==True" ]
[]
509
Write a python function to find the average of odd numbers till a given odd number.
def average_Odd(n) : if (n%2==0) : return ("Invalid Input") return -1 sm =0 count =0 while (n>=1) : count=count+1 sm = sm + n n = n-2 return sm//count
[ "assert average_Odd(9) == 5", "assert average_Odd(5) == 3", "assert average_Odd(11) == 6" ]
[]
510
Write a function to find the number of subsequences having product smaller than k for the given non negative array.
def no_of_subsequences(arr, k): n = len(arr) dp = [[0 for i in range(n + 1)] for j in range(k + 1)] for i in range(1, k + 1): for j in range(1, n + 1): dp[i][j] = dp[i][j - 1] if arr[j - 1] <= i and arr[j - 1] > 0: dp[i][j] += dp[i // arr[j - 1]][j - 1] + 1 return dp[k][n]
[ "assert no_of_subsequences([1,2,3,4], 10) == 11", "assert no_of_subsequences([4,8,7,2], 50) == 9", "assert no_of_subsequences([5,6,7,8], 15) == 4" ]
[]