task_id
int64
601
974
text
stringlengths
38
249
code
stringlengths
30
908
test_list
listlengths
3
3
test_setup_code
stringclasses
2 values
challenge_test_list
listlengths
0
0
633
Write a function to find the minimum number of elements that should be removed such that amax-amin<=k.
def check_Odd_Parity(x): parity = 0 while (x != 0): x = x & (x - 1) parity += 1 if (parity % 2 == 1): return True else: return False
[ "assert pass_validity(\"password\")==False", "assert pass_validity(\"Password@10\")==True", "assert pass_validity(\"password@10\")==False" ]
[]
812
Write a function to find the n-th power of individual elements in a list using lambda function.
def sort_dict_item(test_dict): res = {key: test_dict[key] for key in sorted(test_dict.keys(), key = lambda ele: ele[1] * ele[0])} return (res)
[ "assert rombus_area(10,20)==100", "assert rombus_area(10,5)==25", "assert rombus_area(4,2)==4" ]
[]
795
Write a function to count the elements in a list until an element is a tuple.
import math def find_Index(n): x = math.sqrt(2 * math.pow(10,(n - 1))); return round(x);
[ "assert first_odd([1,3,5]) == 1", "assert first_odd([2,4,1,3]) == 1", "assert first_odd ([8,9,1]) == 9" ]
[]
872
Write a function to check if the given string starts with a substring using regex.
def harmonic_sum(n): if n < 2: return 1 else: return 1 / n + (harmonic_sum(n - 1))
[ "assert sector_area(4,45)==6.285714285714286", "assert sector_area(9,45)==31.82142857142857", "assert sector_area(9,360)==None" ]
[]
883
Write a python function to toggle bits of the number except the first and the last bit.
def cummulative_sum(test_list): res = sum(map(sum, test_list)) return (res)
[ "assert check_valid((True, True, True, True) ) == True", "assert check_valid((True, False, True, True) ) == False", "assert check_valid((True, True, True, True) ) == True" ]
[]
823
Write a function to multiply the adjacent elements of the given tuple.
from math import tan, pi def perimeter_polygon(s,l): perimeter = s*l return perimeter
[ "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')" ]
[]
931
Write a python function to find the average of even numbers till a given even number.
def count_Char(str,x): count = 0 for i in range(len(str)): if (str[i] == x) : count += 1 n = 10 repititions = n // len(str) count = count * repititions l = n % len(str) for i in range(l): if (str[i] == x): count += 1 return...
[ "assert text_starta_endb(\"aabbbb\")==('Found a match!')", "assert text_starta_endb(\"aabAbbbc\")==('Not matched!')", "assert text_starta_endb(\"accddbbjjj\")==('Not matched!')" ]
[]
614
Write a python function to choose points from two ranges such that no point lies in both the ranges.
def Check_Vow(string, vowels): final = [each for each in string if each in vowels] return(len(final))
[ "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_dict((7, 8, 9, 10, 11, 12)) == {7: 8, 9: 10, 11: 12}" ]
[]
900
Write a function to access the initial and last data of the given tuple record.
def sum_nums(x, y,m,n): sum_nums= x + y if sum_nums in range(m, n): return 20 else: return sum_nums
[ "assert min_Jumps(3,4,11)==3.5", "assert min_Jumps(3,4,0)==0", "assert min_Jumps(11,14,11)==1" ]
[]
859
Write a function to check if one tuple is a subset of another tuple.
def check_min_heap(arr, i): if 2 * i + 2 > len(arr): return True left_child = (arr[i] <= arr[2 * i + 1]) and check_min_heap(arr, 2 * i + 1) right_child = (2 * i + 2 == len(arr)) or (arr[i] <= arr[2 * i + 2] and check_min_heap(arr, 2 * i + 2)) return l...
[ "assert check_expression(\"{()}[{}]\") == True", "assert check_expression(\"{()}[{]\") == False", "assert check_expression(\"{()}[{}][]({})\") == True" ]
[]
941
Write a python function to replace multiple occurence of character by single.
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): ...
[ "assert rearrange_numbs([-1, 2, -3, 5, 7, 8, 9, -10])==[2, 5, 7, 8, 9, -10, -3, -1]", "assert rearrange_numbs([10,15,14,13,-18,12,-20])==[10, 12, 13, 14, 15, -20, -18]", "assert rearrange_numbs([-20,20,-10,10,-30,30])==[10, 20, 30, -30, -20, -10]" ]
[]
785
Write a python function to check whether the word is present in a given sentence or not.
import math def wind_chill(v,t): windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16) return int(round(windchill, 0))
[ "assert exchange_elements([0,1,2,3,4,5])==[1, 0, 3, 2, 5, 4] ", "assert exchange_elements([5,6,7,8,9,10])==[6,5,8,7,10,9] ", "assert exchange_elements([25,35,45,55,75,95])==[35,25,55,45,95,75] " ]
[]
666
Write a python function to find the minimum difference between any two elements in a given array.
def area_trapezium(base1,base2,height): area = 0.5 * (base1 + base2) * height return area
[ "assert increasing_trend([1,2,3,4]) == True", "assert increasing_trend([4,3,2,1]) == False", "assert increasing_trend([0,1,4,9]) == True" ]
[]
860
Write a function to caluclate perimeter of a parallelogram.
def mul_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el for el in list1 if el%2!=0),-1) return (first_even*first_odd)
[ "assert remove_spaces(\"a b c\") == \"abc\"", "assert remove_spaces(\"1 2 3\") == \"123\"", "assert remove_spaces(\" b c\") == \"bc\"" ]
[]
930
Write a python function to find maximum possible value for the given periodic function.
def set_middle_bits(n): n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; return (n >> 1) ^ 1 def toggle_middle_bits(n): if (n == 1): return 1 return n ^ set_middle_bits(n)
[ "assert remove_similar_row([[(4, 5), (3, 2)], [(2, 2), (4, 6)], [(3, 2), (4, 5)]] ) == {((2, 2), (4, 6)), ((3, 2), (4, 5))}", "assert remove_similar_row([[(5, 6), (4, 3)], [(3, 3), (5, 7)], [(4, 3), (5, 6)]] ) == {((4, 3), (5, 6)), ((3, 3), (5, 7))}", "assert remove_similar_row([[(6, 7), (5, 4)], [(4, 4), (6, 8...
[]
925
Write a function to find the item with maximum occurrences in a given list.
def zip_list(list1,list2): result = list(map(list.__add__, list1, list2)) return result
[ "assert listify_list(['Red', 'Blue', 'Black', 'White', 'Pink'])==[['R', 'e', 'd'], ['B', 'l', 'u', 'e'], ['B', 'l', 'a', 'c', 'k'], ['W', 'h', 'i', 't', 'e'], ['P', 'i', 'n', 'k']]", "assert listify_list(['python'])==[['p', 'y', 't', 'h', 'o', 'n']]", "assert listify_list([' red ', 'green',' black', 'blue ',' o...
[]
835
Write a function to abbreviate 'road' as 'rd.' in a given string.
import sys def find_closet(A, B, C, p, q, r): diff = sys.maxsize res_i = 0 res_j = 0 res_k = 0 i = 0 j = 0 k = 0 while(i < p and j < q and k < r): minimum = min(A[i], min(B[j], C[k])) maximum = max(A[i], max(B[j], C[k])); if maximum-minimum < diff: res_i = i res_j = j re...
[ "assert max_sub_array_sum([-2, -3, 4, -1, -2, 1, 5, -3],8) == 5", "assert max_sub_array_sum([1, -2, 1, 1, -2, 1],6) == 2", "assert max_sub_array_sum([-1, -2, 3, 4, 5],5) == 3" ]
[]
758
Write a function to check if a triangle of positive area is possible with the given angles.
def access_key(ditionary,key): return list(ditionary)[key]
[ "assert arc_length(9,45)==3.5357142857142856", "assert arc_length(9,480)==None", "assert arc_length(5,270)==11.785714285714285" ]
[]
783
Write a python function to find sum of inverse of divisors.
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 lucky_num(10)==[1, 3, 7, 9, 13, 15, 21, 25, 31, 33] ", "assert lucky_num(5)==[1, 3, 7, 9, 13]", "assert lucky_num(8)==[1, 3, 7, 9, 13, 15, 21, 25]" ]
[]
798
Write a function to find the minimum number of platforms required for a railway/bus station.
def find_Sum(arr,n): arr.sort() sum = arr[0] for i in range(0,n-1): if (arr[i] != arr[i+1]): sum = sum + arr[i+1] return sum
[ "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" ]
[]
901
Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.
def filter_data(students,h,w): result = {k: s for k, s in students.items() if s[0] >=h and s[1] >=w} return result
[ "assert is_upper(\"person\") ==\"PERSON\"", "assert is_upper(\"final\") == \"FINAL\"", "assert is_upper(\"Valid\") == \"VALID\"" ]
[]
618
Write a python function to find the sum of all odd length subarrays.
def max_product(arr): arr_len = len(arr) if (arr_len < 2): return None 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 sum_Of_Subarray_Prod([1,2,3],3) == 20", "assert sum_Of_Subarray_Prod([1,2],2) == 5", "assert sum_Of_Subarray_Prod([1,2,3,4],4) == 84" ]
[]
956
Write a python function to find the minimum sum of absolute differences of two arrays.
def min_jumps(arr, n): jumps = [0 for i in range(n)] if (n == 0) or (arr[0] == 0): return float('inf') jumps[0] = 0 for i in range(1, n): jumps[i] = float('inf') for j in range(i): if (i <= j + arr[j]) and (jumps[j] != float('inf')): jumps[i] = min(jumps[i], jumps[j] + 1) break return j...
[ "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])" ]
[]
672
Write a function to count the most common character in a given string.
def even_position(nums): return all(nums[i]%2==i%2 for i in range(len(nums)))
[ "assert sum_Even(2,5) == 6", "assert sum_Even(3,8) == 18", "assert sum_Even(4,6) == 10" ]
[]
655
Write a python function to count the number of rotations required to generate a sorted array.
def are_Equal(arr1,arr2,n,m): if (n != m): return False arr1.sort() arr2.sort() for i in range(0,n - 1): if (arr1[i] != arr2[i]): return False return True
[ "assert add_dict({'a': 100, 'b': 200, 'c':300},{'a': 300, 'b': 200, 'd':400})==({'b': 400, 'd': 400, 'a': 400, 'c': 300}) ", "assert add_dict({'a': 500, 'b': 700, 'c':900},{'a': 500, 'b': 600, 'd':900})==({'b': 1300, 'd': 900, 'a': 1000, 'c': 900}) ", "assert add_dict({'a':900,'b':900,'d':900},{'a':900,'b':900,...
[]
602
Write a function to check if the given integer is a prime number.
from itertools import groupby def consecutive_duplicates(nums): return [key for key, group in groupby(nums)]
[ "assert recur_gcd(12,14) == 2", "assert recur_gcd(13,17) == 1", "assert recur_gcd(9, 3) == 3" ]
[]
875
Write a python function to check whether an array can be sorted or not by picking only the corner elements.
def all_Characters_Same(s) : n = len(s) for i in range(1,n) : if s[i] != s[0] : return False return True
[ "assert max_char(\"hello world\")==('l')", "assert max_char(\"hello \")==('l')", "assert max_char(\"python pr\")==('p')" ]
[]
915
Write a python function to print duplicants from a list of integers.
import re regex = '[a-zA-z0-9]$' def check_alphanumeric(string): if(re.search(regex, string)): return ("Accept") else: return ("Discard")
[ "assert extract_date(\"https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-norman-tells-author/\") == [('2016', '09', '02')]", "assert extract_date(\"https://www.indiatoday.in/movies/celebrities/story/wp/2020/11/03/odeof-sushant-singh-rajput-...
[]
952
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.
def float_to_tuple(test_str): res = tuple(map(float, test_str.split(', '))) return (res)
[ "assert count_variable(4,2,0,-2)==['p', 'p', 'p', 'p', 'q', 'q'] ", "assert count_variable(0,1,2,3)==['q', 'r', 'r', 's', 's', 's'] ", "assert count_variable(11,15,12,23)==['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'q', 'r', 'r',...
[]
830
Write a function to locate the right insertion point for a specified value in sorted order.
def Extract(lst): return [item[-1] for item in lst]
[ "assert is_Two_Alter(\"abab\") == True", "assert is_Two_Alter(\"aaaa\") == False", "assert is_Two_Alter(\"xyz\") == False" ]
[]
969
Write a function to move all the numbers in it to the given string.
def count_Rotation(arr,n): for i in range (1,n): if (arr[i] < arr[i - 1]): return i return 0
[ "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]" ]
[]
908
Write a python function to count the number of equal numbers from three given integers.
def concatenate_nested(test_tup1, test_tup2): res = test_tup1 + test_tup2 return (res)
[ "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.75]", "assert average_tuple( ((100, 100, 100, 120), (300, 450, 560, 450), (810, 800, 390, 32...
[]
734
Write a python function to find the sum of xor of all pairs of numbers in the given array.
import math def area_tetrahedron(side): area = math.sqrt(3)*(side*side) return area
[ "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 " ]
[]
959
Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm.
def first_odd(nums): first_odd = next((el for el in nums if el%2!=0),-1) return first_odd
[ "assert nth_super_ugly_number(12,[2,7,13,19])==32", "assert nth_super_ugly_number(10,[2,7,13,19])==26", "assert nth_super_ugly_number(100,[2,7,13,19])==5408" ]
[]
862
Write a function to remove duplicate words from a given list of strings.
def count_list(input_list): return (len(input_list))**2
[ "assert move_num('I1love143you55three3000thousand') == 'Iloveyouthreethousand1143553000'", "assert move_num('Avengers124Assemble') == 'AvengersAssemble124'", "assert move_num('Its11our12path13to14see15things16do17things') == 'Itsourpathtoseethingsdothings11121314151617'" ]
[]
628
Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.
def add_list(nums1,nums2): result = map(lambda x, y: x + y, nums1, nums2) return list(result)
[ "assert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,4,6,9,1,2])==2", "assert max_occurrences([1, 3,5, 7,1, 3,13, 15, 17,5, 7,9,1, 11])==1", "assert max_occurrences([1, 2, 3,2, 4, 5,1, 1, 1])==1" ]
[]
903
Write a python function to check whether an array contains only one distinct element or not.
import collections as ct def merge_dictionaries(dict1,dict2): merged_dict = dict(ct.ChainMap({}, dict1, dict2)) return merged_dict
[ "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" ]
[]
788
Write a function to find the sequences of one upper case letter followed by lower case letters.
def floor_Max(A,B,N): x = min(B - 1,N) return (A*x) // B
[ "assert min_jumps([1, 3, 6, 1, 0, 9], 6) == 3", "assert min_jumps([1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9], 11) == 3", "assert min_jumps([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 11) == 10" ]
[]
767
Write a python function to check whether the given two numbers have same number of digits or not.
def No_of_cubes(N,K): No = 0 No = (N - K + 1) No = pow(No, 3) return No
[ "assert get_odd_occurence([2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2], 13) == 5", "assert get_odd_occurence([1, 2, 3, 2, 3, 1, 3], 7) == 3", "assert get_odd_occurence([5, 7, 2, 7, 5, 2, 5], 7) == 5" ]
[]
919
Write a function to put spaces between words starting with capital letters in a given string by using regex.
class Node: def __init__(self, data): self.data = data self.left = None self.right = None def max_height(node): if node is None: return 0 ; else : left_height = max_height(node.left) right_height = max_height(node.right) if (left_height > right_height): return left_height+1 ...
[ "assert is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60},5)==True", "assert is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60},6)==True", "assert is_key_present({1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60},10)==False" ]
[]
806
Write a function to calculate the sum of series 1³+2³+3³+….+n³.
def lcopy(xs): return xs[:]
[ "assert string_length('python')==6", "assert string_length('program')==7", "assert string_length('language')==8" ]
[]
829
Write a python function to find sum of prime numbers between 1 to n.
def sum_Natural(n): sum = (n * (n + 1)) return int(sum) def sum_Even(l,r): return (sum_Natural(int(r / 2)) - sum_Natural(int((l - 1) / 2)))
[ "assert add_list([1, 2, 3],[4,5,6])==[5, 7, 9]", "assert add_list([1,2],[3,4])==[4,6]", "assert add_list([10,20],[50,70])==[60,90]" ]
[]
867
Write a function to print n-times a list using map function.
from collections import defaultdict def freq_element(test_tup): res = defaultdict(int) for ele in test_tup: res[ele] += 1 return (str(dict(res)))
[ "assert check_str(\"annie\") == 'Valid'", "assert check_str(\"dawood\") == 'Invalid'", "assert check_str(\"Else\") == 'Valid'" ]
[]
746
Write a python function to count the total set bits from 1 to n.
def check_greater(test_tup1, test_tup2): res = all(x < y for x, y in zip(test_tup1, test_tup2)) return (res)
[ "assert Check_Solution(2,0,2) == \"Yes\"", "assert Check_Solution(2,-5,2) == \"Yes\"", "assert Check_Solution(1,2,3) == \"No\"" ]
root = Node(1) root.left = Node(2) root.right = Node(3) root.left.left = Node(4) root.left.right = Node(5) root1 = Node(1); root1.left = Node(2); root1.right = Node(3); root1.left.left = Node(4); root1.right.left = Node(5); root1.right.right = Node(6); root1.right.right.right= Node(7); ro...
[]
687
Write a python function to find the first odd number in a given list of numbers.
def get_item(tup1,index): item = tup1[index] return item
[ "assert split_upperstring(\"PythonProgramLanguage\")==['Python','Program','Language']", "assert split_upperstring(\"PythonProgram\")==['Python','Program']", "assert split_upperstring(\"ProgrammingLanguage\")==['Programming','Language']" ]
[]
668
Write a function to locate the left insertion point for a specified value in sorted order.
def front_and_rear(test_tup): res = (test_tup[0], test_tup[-1]) return (res)
[ "assert find_fixed_point([-10, -1, 0, 3, 10, 11, 30, 50, 100],9) == 3", "assert find_fixed_point([1, 2, 3, 4, 5, 6, 7, 8],8) == -1", "assert find_fixed_point([0, 2, 5, 8, 17],5) == 0" ]
[]
774
Write a function to check whether the given month number contains 30 days or not.
def sum_even_odd(list1): first_even = next((el for el in list1 if el%2==0),-1) first_odd = next((el for el in list1 if el%2!=0),-1) return (first_even+first_odd)
[ "assert remove_duplicate([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])==[[10, 20], [30, 56, 25], [33], [40]] ", "assert remove_duplicate([\"a\", \"b\", \"a\", \"c\", \"c\"] )==[\"a\", \"b\", \"c\"]", "assert remove_duplicate([1, 3, 5, 6, 3, 5, 6, 1] )==[1, 3, 5, 6]" ]
[]
653
Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm.
from operator import eq def count_same_pair(nums1, nums2): result = sum(map(eq, nums1, nums2)) return result
[ "assert all_Characters_Same(\"python\") == False", "assert all_Characters_Same(\"aaa\") == True", "assert all_Characters_Same(\"data\") == False" ]
[]
964
Write a python function to remove spaces from a given string.
def sum_Square(n) : i = 1 while i*i <= n : j = 1 while (j*j <= n) : if (i*i+j*j == n) : return True j = j+1 i = i+1 return False
[ "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!')" ]
[]
861
Write a function to remove multiple spaces in a string.
def extract_unique(test_dict): res = list(sorted({ele for val in test_dict.values() for ele in val})) return res
[ "assert sum_of_odd_Factors(30) == 24", "assert sum_of_odd_Factors(18) == 13", "assert sum_of_odd_Factors(2) == 1" ]
[]
641
Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.
from collections import Counter def most_common_elem(s,a): most_common_elem=Counter(s).most_common(a) return most_common_elem
[ "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 content \"4k Ultra HD\" resolution with \"HDR 10\" Support') ...
[]
850
Write a function to count the number of unique lists within a list.
def check_monthnumber_number(monthnum3): if(monthnum3==4 or monthnum3==6 or monthnum3==9 or monthnum3==11): return True else: return False
[ "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): 1, (9, 11): 1}", "assert unique_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']])=={('green', 'orange'): 2, ('black',): 1, ('white',): 1}", "assert unique_sublists([[1,...
[]
610
Write a python function to remove negative numbers from a list.
import heapq def cheap_items(items,n): cheap_items = heapq.nsmallest(n, items, key=lambda s: s['price']) return cheap_items
[ "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]" ]
[]
623
Write a function to increment the numeric values in the given strings by k.
def count_alpha_dig_spl(string): alphabets=digits = special = 0 for i in range(len(string)): if(string[i].isalpha()): alphabets = alphabets + 1 elif(string[i].isdigit()): digits = digits + 1 else: special = special + 1 return (alphabets,digits,special)
[ "assert merge_dictionaries({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White'}", "assert merge_dictionaries({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" },{ \"O\": \"Orange\", \"W\": \"White\", \...
[]
620
Write a function to check for a number at the end of a string.
import math def sum_of_odd_Factors(n): res = 1 while n % 2 == 0: n = n // 2 for i in range(3,int(math.sqrt(n) + 1)): count = 0 curr_sum = 1 curr_term = 1 while n % i == 0: count+=1 n = n // i curr_term *= i ...
[ "assert int_to_roman(1)==(\"I\")", "assert int_to_roman(50)==(\"L\")", "assert int_to_roman(4)==(\"IV\")" ]
[]
831
Write a function to remove the nested record from the given tuple.
import re def road_rd(street): return (re.sub('Road$', 'Rd.', street))
[ "assert extract_unique({'msm' : [5, 6, 7, 8],'is' : [10, 11, 7, 5],'best' : [6, 12, 10, 8],'for' : [1, 2, 5]} ) == [1, 2, 5, 6, 7, 8, 10, 11, 12]", "assert extract_unique({'Built' : [7, 1, 9, 4],'for' : [11, 21, 36, 14, 9],'ISP' : [4, 1, 21, 39, 47],'TV' : [1, 32, 38]} ) == [1, 4, 7, 9, 11, 14, 21, 32, 36, 38, 39...
[]
907
Write a python function to find the last two digits in factorial of a given number.
def min_of_two( x, y ): if x < y: return x return y
[ "assert round_up(123.01247,0)==124", "assert round_up(123.01247,1)==123.1", "assert round_up(123.01247,2)==123.02" ]
[]
606
Write a function to count number of unique lists within a list.
def str_to_tuple(test_str): res = tuple(map(int, test_str.split(', '))) return (res)
[ "assert super_seq(\"AGGTAB\", \"GXTXAYB\", 6, 7) == 9", "assert super_seq(\"feek\", \"eke\", 4, 3) == 5", "assert super_seq(\"PARRT\", \"RTA\", 5, 3) == 6" ]
[]
627
Write a python function to copy a list from a singleton tuple.
def find_First_Missing(array,start,end): if (start > end): return end + 1 if (start != array[start]): return start; mid = int((start + end) / 2) if (array[mid] == mid): return find_First_Missing(array,mid+1,end) return find_First_Missing(array,start,mid)
[ "assert remove_spaces('python program')==('python program')", "assert remove_spaces('python programming language')==('python programming language')", "assert remove_spaces('python program')==('python program')" ]
[]
800
Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex.
def check_valid(test_tup): res = not any(map(lambda ele: not ele, test_tup)) return (res)
[ "assert coin_change([1, 2, 3],3,4)==4", "assert coin_change([4,5,6,7,8,9],6,9)==2", "assert coin_change([4,5,6,7,8,9],6,4)==1" ]
[]
739
Write a function to find out the second most repeated (or frequent) string in the given sequence.
def check_monthnumb(monthname2): if(monthname2=="January" or monthname2=="March"or monthname2=="May" or monthname2=="July" or monthname2=="Augest" or monthname2=="October" or monthname2=="December"): return True else: return False
[ "assert triangle_area(0) == 0", "assert triangle_area(-1) == -1", "assert triangle_area(2) == 4" ]
[]
634
Write a function to find the index of the first occurrence of a given number in a sorted array.
def remove_nested(test_tup): res = tuple() for count, ele in enumerate(test_tup): if not isinstance(ele, tuple): res = res + (ele, ) return (res)
[ "assert series_sum(6)==91", "assert series_sum(7)==140", "assert series_sum(12)==650" ]
[]
967
Write a function to remove all characters except letters and numbers using regex
def multiply_list(items): tot = 1 for x in items: tot *= x return tot
[ "assert test_three_equal(1,1,1) == 3", "assert test_three_equal(-1,-2,-3) == 0", "assert test_three_equal(1,2,2) == 2" ]
[]
768
Write a python function to check whether the product of digits of a number at even and odd places is equal or not.
from collections import defaultdict def get_unique(test_list): res = defaultdict(list) for sub in test_list: res[sub[1]].append(sub[0]) res = dict(res) res_dict = dict() for key in res: res_dict[key] = len(list(set(res[key]))) return (str(res_dict))
[ "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): 1, (9, 11): 1}", "assert unique_sublists([['green', 'orange'], ['black'], ['green', 'orange'], ['white']])=={('green', 'orange'): 2, ('black',): 1, ('white',): 1}", "assert unique_sublists([[1...
[]
751
Write a function to re-arrange the given tuples based on the given ordered list.
def rombus_perimeter(a): perimeter=4*a return perimeter
[ "assert is_subset([11, 1, 13, 21, 3, 7], 6, [11, 3, 7, 1], 4) == True", "assert is_subset([1, 2, 3, 4, 5, 6], 6, [1, 2, 4], 3) == True", "assert is_subset([10, 5, 2, 23, 19], 5, [19, 5, 3], 3) == False" ]
[]
667
Write a python function to left rotate the string.
def adjac(ele, sub = []): if not ele: yield sub else: yield from [idx for j in range(ele[0] - 1, ele[0] + 2) for idx in adjac(ele[1:], sub + [j])] def get_coordinates(test_tup): res = list(adjac(test_tup)) return (res)
[ "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" ]
[]
773
Write a function to add a dictionary to the tuple.
def check(string): if len(set(string).intersection("AEIOUaeiou"))>=5: return ('accepted') else: return ("not accepted")
[ "assert freq_element((4, 5, 4, 5, 6, 6, 5, 5, 4) ) == '{4: 3, 5: 4, 6: 2}'", "assert freq_element((7, 8, 8, 9, 4, 7, 6, 5, 4) ) == '{7: 2, 8: 2, 9: 1, 4: 2, 6: 1, 5: 1}'", "assert freq_element((1, 4, 3, 1, 4, 5, 2, 6, 2, 7) ) == '{1: 2, 4: 2, 3: 1, 5: 1, 2: 2, 6: 1, 7: 1}'" ]
[]
688
Write a function to remove the parenthesis area in a string.
import re def text_uppercase_lowercase(text): patterns = '[A-Z]+[a-z]+$' if re.search(patterns, text): return 'Found a match!' else: return ('Not matched!')
[ "assert is_Product_Even([1,2,3],3) == True", "assert is_Product_Even([1,2,1,4],4) == True", "assert is_Product_Even([1,1],2) == False" ]
[]
974
Write a function to find the product of it’s kth index in the given tuples.
def remove_negs(num_list): for item in num_list: if item < 0: num_list.remove(item) return num_list
[ "assert sum_positivenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==48", "assert sum_positivenum([10,15,-14,13,-18,12,-20])==50", "assert sum_positivenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==522" ]
[]
733
Write a python function to check whether every odd index contains odd numbers of a given list.
import re regex = '^[aeiouAEIOU][A-Za-z0-9_]*' def check_str(string): if(re.search(regex, string)): return ("Valid") else: return ("Invalid")
[ "assert bell_Number(2) == 2", "assert bell_Number(3) == 5", "assert bell_Number(4) == 15" ]
[]
864
Write a function to validate a gregorian date.
def last_Two_Digits(N): if (N >= 10): return fac = 1 for i in range(1,N + 1): fac = (fac * i) % 100 return (fac)
[ "assert max_of_two(10,20)==20", "assert max_of_two(19,15)==19", "assert max_of_two(-10,-20)==-10" ]
[]
848
Write a python function to count lower case letters in a given string.
def last(arr,x,n): low = 0 high = n - 1 res = -1 while (low <= high): mid = (low + high) // 2 if arr[mid] > x: high = mid - 1 elif arr[mid] < x: low = mid + 1 else: res = mid low = mid + 1 return res
[ "assert remove_all_spaces('python program')==('pythonprogram')", "assert remove_all_spaces('python programming language')==('pythonprogramminglanguage')", "assert remove_all_spaces('python program')==('pythonprogram')" ]
[]
841
Write a python function to find nth bell number.
def Convert(string): li = list(string.split(" ")) return li
[ "assert return_sum({'a': 100, 'b':200, 'c':300}) == 600", "assert return_sum({'a': 25, 'b':18, 'c':45}) == 88", "assert return_sum({'a': 36, 'b':39, 'c':49}) == 124" ]
[]
716
Write a function to remove all whitespaces from a string.
def equilibrium_index(arr): total_sum = sum(arr) left_sum=0 for i, num in enumerate(arr): total_sum -= num if left_sum == total_sum: return i left_sum += num return -1
[ "assert sort_sublists([[2], [0], [1, 3], [0, 7], [9, 11], [13, 15, 17]])==[[0], [2], [0, 7], [1, 3], [9, 11], [13, 15, 17]]", "assert sort_sublists([[1], [2, 3], [4, 5, 6], [7], [10, 11]])==[[1], [7], [2, 3], [10, 11], [4, 5, 6]]", "assert sort_sublists([[\"python\"],[\"java\",\"C\",\"C++\"],[\"DBMS\"],[\"SQL\"...
[]
656
Write a python function to find minimum possible value for the given periodic function.
def super_seq(X, Y, m, n): if (not m): return n if (not n): return m if (X[m - 1] == Y[n - 1]): return 1 + super_seq(X, Y, m - 1, n - 1) return 1 + min(super_seq(X, Y, m - 1, n), super_seq(X, Y, m, n - 1))
[ "assert check_element((4, 5, 7, 9, 3), [6, 7, 10, 11]) == True", "assert check_element((1, 2, 3, 4), [4, 6, 7, 8, 9]) == True", "assert check_element((3, 2, 1, 4, 5), [9, 8, 7, 6]) == False" ]
[]
878
Write a function to check if each element of second tuple is smaller than its corresponding index in first tuple.
def clear_tuple(test_tup): temp = list(test_tup) temp.clear() test_tup = tuple(temp) return (test_tup)
[ "assert get_noOfways(4)==3", "assert get_noOfways(3)==2", "assert get_noOfways(5)==5" ]
[]
935
Write a function to count the frequency of consecutive duplicate elements in a given list of numbers.
def series_sum(number): total = 0 total = (number * (number + 1) * (2 * number + 1)) / 6 return total
[ "assert is_nonagonal(10) == 325", "assert is_nonagonal(15) == 750", "assert is_nonagonal(18) == 1089" ]
[]
787
Write a function to join the tuples if they have similar initial elements.
def return_sum(dict): sum = 0 for i in dict.values(): sum = sum + i return sum
[ "assert is_Perfect_Square(10) == False", "assert is_Perfect_Square(36) == True", "assert is_Perfect_Square(14) == False" ]
[]
852
Write a python function to count the number of distinct power of prime factor of given number.
def decreasing_trend(nums): if (sorted(nums)== nums): return True else: return False
[ "assert floor_Min(10,20,30) == 15", "assert floor_Min(1,2,1) == 0", "assert floor_Min(11,10,9) == 9" ]
[]
642
Write a python function to find the sum of fourth power of first n odd natural numbers.
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 +=...
[ "assert lateralsurface_cone(5,12)==204.20352248333654", "assert lateralsurface_cone(10,15)==566.3586699569488", "assert lateralsurface_cone(19,17)==1521.8090132193388" ]
[]
796
Write a function to calculate the geometric sum of n-1.
def find_platform(arr, dep, n): arr.sort() dep.sort() plat_needed = 1 result = 1 i = 1 j = 0 while (i < n and j < n): if (arr[i] <= dep[j]): plat_needed+= 1 i+= 1 elif (arr[i] > dep[j]): plat_needed-= 1...
[ "assert sort_tuple([(\"Amana\", 28), (\"Zenat\", 30), (\"Abhishek\", 29),(\"Nikhil\", 21), (\"B\", \"C\")]) == [('Abhishek', 29), ('Amana', 28), ('B', 'C'), ('Nikhil', 21), ('Zenat', 30)]", "assert sort_tuple([(\"aaaa\", 28), (\"aa\", 30), (\"bab\", 29), (\"bb\", 21), (\"csa\", \"C\")]) == [('aa', 30), ('aaaa', 2...
[]
936
Write a python function to check whether the length of the word is even or not.
def sum_Range_list(nums, m, n): sum_range = 0 ...
[ "assert is_abundant(12)==True", "assert is_abundant(13)==False", "assert is_abundant(9)==False" ]
[]
715
Write a python function to check whether the two given strings are isomorphic to each other or not.
class Pair(object): def __init__(self, a, b): self.a = a self.b = b def max_chain_length(arr, n): max = 0 mcl = [1 for i in range(n)] for i in range(1, n): for j in range(0, i): if (arr[i].a > arr[j].b and mcl[i] < mcl[j] + 1): mcl[i] = mcl[j] + 1 for i in range(n): if (ma...
[ "assert sort_dict_item({(5, 6) : 3, (2, 3) : 9, (8, 4): 10, (6, 4): 12} ) == {(2, 3): 9, (6, 4): 12, (5, 6): 3, (8, 4): 10}", "assert sort_dict_item({(6, 7) : 4, (3, 4) : 10, (9, 5): 11, (7, 5): 13} ) == {(3, 4): 10, (7, 5): 13, (6, 7): 4, (9, 5): 11}", "assert sort_dict_item({(7, 8) : 5, (4, 5) : 11, (10, 6): ...
[]
682
Write a function that matches a string that has an a followed by zero or one 'b'.
def second_smallest(numbers): if (len(numbers)<2): return if ((len(numbers)==2) and (numbers[0] == numbers[1]) ): return dup_items = set() uniq_items = [] for x in numbers: if x not in dup_items: uniq_items.append(x) dup_items.add(x) uniq_items.sort() return uniq_...
[ "assert Check_Vow('corner','AaEeIiOoUu') == 2", "assert Check_Vow('valid','AaEeIiOoUu') == 2", "assert Check_Vow('true','AaEeIiOoUu') ==2" ]
[]
741
Write a function to convert a roman numeral to an integer.
def sum_Odd(n): terms = (n + 1)//2 sum1 = terms * terms return sum1 def sum_in_Range(l,r): return sum_Odd(r) - sum_Odd(l - 1)
[ "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'" ]
[]
922
Write a function to find the previous palindrome of a specified number.
def find_first_occurrence(A, x): (left, right) = (0, len(A) - 1) result = -1 while left <= right: mid = (left + right) // 2 if x == A[mid]: result = mid right = mid - 1 elif x < A[mid]: right = mid - 1 else: left = mi...
[ "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" ]
[]
782
Write a function to sort the tuples alphabetically by the first item of each tuple.
def Check_Solution(a,b,c): if b == 0: return ("Yes") else: return ("No")
[ "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'" ]
[]
871
Write a function to remove everything except alphanumeric characters from the given string by using regex.
import re def pass_validity(p): x = True while x: if (len(p)<6 or len(p)>12): break elif not re.search("[a-z]",p): break elif not re.search("[0-9]",p): break elif not re.search("[A-Z]",p): break elif not re.search("[$#@]",p): break elif r...
[ "assert get_inv_count([1, 20, 6, 4, 5], 5) == 5", "assert get_inv_count([8, 4, 2, 1], 4) == 6", "assert get_inv_count([3, 1, 2], 3) == 2" ]
[]
918
Write a function to extract unique values from the given dictionary values.
def rotate_right(list1,m,n): result = list1[-(m):]+list1[:-(n)] return result
[ "assert roman_to_int('MMMCMLXXXVI')==3986", "assert roman_to_int('MMMM')==4000", "assert roman_to_int('C')==100" ]
[]
744
Write a python function to access multiple elements of specified index from a given list.
def find_fixed_point(arr, n): for i in range(n): if arr[i] is i: return i return -1
[ "assert largest_subset([ 1, 3, 6, 13, 17, 18 ], 6) == 4", "assert largest_subset([10, 5, 3, 15, 20], 5) == 3", "assert largest_subset([18, 1, 3, 6, 13, 17], 6) == 4" ]
[]
933
Write a function to find the maximum value in record list as tuple attribute in the given tuple list.
def get_inv_count(arr, n): inv_count = 0 for i in range(n): for j in range(i + 1, n): if (arr[i] > arr[j]): inv_count += 1 return inv_count
[ "assert count_Char(\"abcac\",'a') == 4", "assert count_Char(\"abca\",'c') == 2", "assert count_Char(\"aba\",'a') == 7" ]
[]
820
Write a python function to find the sum of all even natural numbers within the range l and r.
def Split(list): ev_li = [] for i in list: if (i % 2 == 0): ev_li.append(i) return ev_li
[ "assert find_k_product([(5, 6, 7), (1, 3, 5), (8, 9, 19)], 2) == 665", "assert find_k_product([(6, 7, 8), (2, 4, 6), (9, 10, 20)], 1) == 280", "assert find_k_product([(7, 8, 9), (3, 5, 7), (10, 11, 21)], 0) == 210" ]
[]
708
Write a python function to count occurences of a character in a repeated string.
def length_Of_Last_Word(a): l = 0 x = a.strip() for i in range(len(x)): if x[i] == " ": l = 0 else: l += 1 return l
[ "assert access_elements([2,3,8,4,7,9],[0,3,5]) == [2, 4, 9]", "assert access_elements([1, 2, 3, 4, 5],[1,2]) == [2,3]", "assert access_elements([1,0,2,3],[0,1]) == [1,0]" ]
[]
893
Write a function to remove duplicate words from a given string using collections module.
M = 100 def maxAverageOfPath(cost, N): dp = [[0 for i in range(N + 1)] for j in range(N + 1)] dp[0][0] = cost[0][0] for i in range(1, N): dp[i][0] = dp[i - 1][0] + cost[i][0] for j in range(1, N): dp[0][j] = dp[0][j - 1] + cost[0][j] for i in range(1, N): for j in range(1, N): dp[i][j] ...
[ "assert sorted_models([{'make':'Nokia', 'model':216, 'color':'Black'}, {'make':'Mi Max', 'model':2, 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color':'Blue'}])==[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'Mi Max', 'model': 2, 'color': 'Gold'}...
[]
844
Write a function to merge two dictionaries into a single expression.
def even_Power_Sum(n): sum = 0; for i in range(1,n + 1): j = 2*i; sum = sum + (j*j*j*j); return sum;
[ "assert count_even([1, 2, 3, 5, 7, 8, 9, 10])==3", "assert count_even([10,15,14,13,-18,12,-20])==5", "assert count_even([1, 2, 4, 8, 9])==3" ]
[]
970
Write a python function to find the sum of non-repeated elements in a given array.
def mutiple_tuple(nums): temp = list(nums) product = 1 for x in temp: product *= x return product
[ "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)" ]
[]
944
Write a python function to find lcm of two positive integers.
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 fifth_Power_Sum(2) == 33", "assert fifth_Power_Sum(4) == 1300", "assert fifth_Power_Sum(3) == 276" ]
[]
638
Write a function to find a pair with the highest product from a given array of integers.
def move_last(num_list): a = [num_list[0] for i in range(num_list.count(num_list[0]))] x = [ i for i in num_list if i != num_list[0]] x.extend(a) return (x)
[ "assert min_k([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2) == [('Akash', 2), ('Akshat', 4)]", "assert min_k([('Sanjeev', 11), ('Angat', 5), ('Akash', 3), ('Nepin', 9)], 3) == [('Akash', 3), ('Angat', 5), ('Nepin', 9)]", "assert min_k([('tanmay', 14), ('Amer', 11), ('Ayesha', 9), ('SKD', 16)...
[]
879
Write a function to search a literals string in a string and also find the location within the original string where the pattern occurs by using regex.
def is_odd(n) : if (n^1 == n-1) : return True; else : return False;
[ "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)" ]
[]
604
Write a python function to check whether every even index contains even numbers of a given list.
def get_Number(n, k): arr = [0] * n; i = 0; odd = 1; while (odd <= n): arr[i] = odd; i += 1; odd += 2; even = 2; while (even <= n): arr[i] = even; i += 1; even += 2; return arr[k - 1];
[ "assert replace('peep','e') == 'pep'", "assert replace('Greek','e') == 'Grek'", "assert replace('Moon','o') == 'Mon'" ]
[]