Dataset Viewer
Auto-converted to Parquet Duplicate
task_id
int32
11
510
text
stringlengths
37
191
code
stringlengths
37
1.33k
test_list
listlengths
3
3
test_setup_code
stringclasses
2 values
challenge_test_list
listlengths
0
3
processed_text
stringlengths
58
240
11
Write a python function to remove first and last occurrence of a given character from the string.
def remove_Occ(s,ch): for i in range(len(s)): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break for i in range(len(s) - 1,-1,-1): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break return s
[ "assert remove_Occ(\"hello\",\"l\") == \"heo\"", "assert remove_Occ(\"abcda\",\"a\") == \"bcd\"", "assert remove_Occ(\"PHP\",\"P\") == \"H\"" ]
[ "assert remove_Occ(\"hellolloll\",\"l\") == \"helollol\"", "assert remove_Occ(\"\",\"l\") == \"\"" ]
Write a python function `remove_Occ(s, ch)` to remove first and last occurrence of a given character from the string.
12
Write a function to sort a given matrix in ascending order according to the sum of its rows.
def sort_matrix(M): result = sorted(M, key=sum) return result
[ "assert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]]", "assert sort_matrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])==[[-2, 4, -5], [1, -1, 1], [1, 2, 3]]", "assert sort_matrix([[5,8,9],[6,4,3],[2,1,4]])==[[2, 1, 4], [6, 4, 3], [5, 8, 9]]" ]
[]
Write a function `sort_matrix(M)` to sort a given matrix in ascending order according to the sum of its rows.
13
Write a function to count the most common words in a dictionary.
from collections import Counter def count_common(words): word_counts = Counter(words) top_four = word_counts.most_common(4) return (top_four)
[ "assert count_common(['red','green','black','pink','black','white','black','eyes','white','black','orange','pink','pink','red','red','white','orange','white',\"black\",'pink','green','green','pink','green','pink','white','orange',\"orange\",'red']) == [('pink', 6), ('black', 5), ('white', 5), ('red', 4)]", "assert count_common(['one', 'two', 'three', 'four', 'five', 'one', 'two', 'one', 'three', 'one']) == [('one', 4), ('two', 2), ('three', 2), ('four', 1)]", "assert count_common(['Facebook', 'Apple', 'Amazon', 'Netflix', 'Google', 'Apple', 'Netflix', 'Amazon']) == [('Apple', 2), ('Amazon', 2), ('Netflix', 2), ('Facebook', 1)]" ]
[]
Write a function `count_common(words)` to count the most common words in a list and return the 4 most common as a list of `(word, count)` tuples in descending order.
14
Write a python function to find the volume of a triangular prism.
def find_Volume(l,b,h) : return ((l * b * h) / 2)
[ "assert find_Volume(10,8,6) == 240", "assert find_Volume(3,2,2) == 6", "assert find_Volume(1,2,1) == 1" ]
[]
Write a python function `find_Volume(l, b, h)` to find the volume of a triangular prism.
15
Write a function to split a string at lowercase letters.
import re def split_lowerstring(text): return (re.findall('[a-z][^a-z]*', text))
[ "assert split_lowerstring(\"AbCd\")==['bC','d']", "assert split_lowerstring(\"Python\")==['y', 't', 'h', 'o', 'n']", "assert split_lowerstring(\"Programming\")==['r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g']" ]
[]
Write a function `split_lowerstring(text)` to split a string at lowercase letters.
16
Write a function to find sequences of lowercase letters joined with an underscore.
import re def text_lowercase_underscore(text): patterns = '^[a-z]+_[a-z]+$' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
[ "assert text_lowercase_underscore(\"aab_cbbbc\")==('Found a match!')", "assert text_lowercase_underscore(\"aab_Abbbc\")==('Not matched!')", "assert text_lowercase_underscore(\"Aaab_abbbc\")==('Not matched!')" ]
[ "assert text_lowercase_underscore(\"aab-cbbbc\")==('Not matched!')" ]
Write a function `text_lowercase_underscore(text)` to find sequences of lowercase letters joined with an underscore.
17
Write a function to find the perimeter of a square.
def square_perimeter(a): perimeter=4*a return perimeter
[ "assert square_perimeter(10)==40", "assert square_perimeter(5)==20", "assert square_perimeter(4)==16" ]
[]
Write a function `square_perimeter(a)` to find the perimeter of a square.
18
Write a function to remove characters from the first string which are present in the second string.
NO_OF_CHARS = 256 def str_to_list(string): temp = [] for x in string: temp.append(x) return temp def lst_to_string(List): return ''.join(List) def get_char_count_array(string): count = [0] * NO_OF_CHARS for i in string: count[ord(i)] += 1 return count def remove_dirty_chars(string, second_string): count = get_char_count_array(second_string) ip_ind = 0 res_ind = 0 temp = '' str_list = str_to_list(string) while ip_ind != len(str_list): temp = str_list[ip_ind] if count[ord(temp)] == 0: str_list[res_ind] = str_list[ip_ind] res_ind += 1 ip_ind+=1 return lst_to_string(str_list[0:res_ind])
[ "assert remove_dirty_chars(\"probasscurve\", \"pros\") == 'bacuve'", "assert remove_dirty_chars(\"digitalindia\", \"talent\") == 'digiidi'", "assert remove_dirty_chars(\"exoticmiles\", \"toxic\") == 'emles' " ]
[]
Write a function `remove_dirty_chars(string, second_string)` to remove characters from the first string which are present in the second string.
19
Write a function to find whether a given array of integers contains any duplicate element.
def test_duplicate(arraynums): nums_set = set(arraynums) return len(arraynums) != len(nums_set)
[ "assert test_duplicate(([1,2,3,4,5]))==False", "assert test_duplicate(([1,2,3,4, 4]))==True", "assert test_duplicate([1,1,2,2,3,3,4,4,5])==True" ]
[]
Write a function `test_duplicate(arraynums)` to find whether a given array of integers contains any duplicate element.
20
Write a function to check if the given number is woodball or not.
def is_woodall(x): if (x % 2 == 0): return False if (x == 1): return True x = x + 1 p = 0 while (x % 2 == 0): x = x/2 p = p + 1 if (p == x): return True return False
[ "assert is_woodall(383) == True", "assert is_woodall(254) == False", "assert is_woodall(200) == False" ]
[ "assert is_woodall(32212254719) == True", "assert is_woodall(32212254718) == False", "assert is_woodall(159) == True" ]
Write a function `is_woodall(x)` to check if the given number is woodball or not.
21
Write a function to find m number of multiples of n.
def multiples_of_num(m,n): multiples_of_num= list(range(n,(m+1)*n, n)) return list(multiples_of_num)
[ "assert multiples_of_num(4,3)== [3,6,9,12]", "assert multiples_of_num(2,5)== [5,10]", "assert multiples_of_num(9,2)== [2,4,6,8,10,12,14,16,18]" ]
[]
Write a function `multiples_of_num(m, n)` to find `m` number of multiples of `n`.
22
Write a function to find the first duplicate element in a given array of integers.
def find_first_duplicate(nums): num_set = set() no_duplicate = -1 for i in range(len(nums)): if nums[i] in num_set: return nums[i] else: num_set.add(nums[i]) return no_duplicate
[ "assert find_first_duplicate(([1, 2, 3, 4, 4, 5]))==4", "assert find_first_duplicate([1, 2, 3, 4])==-1", "assert find_first_duplicate([1, 1, 2, 3, 3, 2, 2])==1" ]
[]
Write a function `find_first_duplicate(nums)` to find the first duplicate element in a given array of integers.
23
Write a python function to find the maximum sum of elements of list in a list of lists.
def maximum_Sum(list1): maxi = -100000 for x in list1: sum = 0 for y in x: sum+= y maxi = max(sum,maxi) return maxi
[ "assert maximum_Sum([[1,2,3],[4,5,6],[10,11,12],[7,8,9]]) == 33", "assert maximum_Sum([[0,1,1],[1,1,2],[3,2,1]]) == 6", "assert maximum_Sum([[0,1,3],[1,2,1],[9,8,2],[0,1,0],[6,4,8]]) == 19" ]
[ "assert maximum_Sum([[0,-1,-1],[-1,-1,-2],[-3,-2,-1]]) == -2" ]
Write a python function `maximum_Sum(list1)` to find the maximum sum of elements of any sublist in a list of lists.
24
Write a function to convert the given binary number to its decimal equivalent.
def binary_to_decimal(binary): binary1 = binary decimal, i, n = 0, 0, 0 while(binary != 0): dec = binary % 10 decimal = decimal + dec * pow(2, i) binary = binary//10 i += 1 return (decimal)
[ "assert binary_to_decimal(100) == 4", "assert binary_to_decimal(1011) == 11", "assert binary_to_decimal(1101101) == 109" ]
[]
Write a function `binary_to_decimal(binary)` to convert the given binary number to its decimal equivalent.
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" ]
Write a python function `find_Product(arr, n)` to find the product of non-repeated elements in a given array.
26
Write a function to check if the given tuple list has all k elements.
def check_k_elements(test_list, K): res = True for tup in test_list: for ele in tup: if ele != K: res = False return (res)
[ "assert check_k_elements([(4, 4), (4, 4, 4), (4, 4), (4, 4, 4, 4), (4, )], 4) == True", "assert check_k_elements([(7, 7, 7), (7, 7)], 7) == True", "assert check_k_elements([(9, 9), (9, 9, 9, 9)], 7) == False" ]
[ "assert check_k_elements([(4, 4), (4, 4, 4), (4, 4), (4, 4, 6, 4), (4, )], 4) == False" ]
Write a function `check_k_elements(test_list, K)` to check if the given tuple list has all k elements.
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']" ]
[]
Write a python function `remove(list)` to remove all digits from a list of strings.
28
Write a python function to find binomial co-efficient.
def binomial_Coeff(n,k): if k > n : return 0 if k==0 or k ==n : return 1 return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k)
[ "assert binomial_Coeff(5,2) == 10", "assert binomial_Coeff(4,3) == 4", "assert binomial_Coeff(3,2) == 3" ]
[ "assert binomial_Coeff(14,6) == 3003" ]
Write a python function `binomial_Coeff(n, k)` to find the binomial co-efficient.
29
Write a python function to find the element occurring odd number of times.
def get_Odd_Occurrence(arr,arr_size): for i in range(0,arr_size): count = 0 for j in range(0,arr_size): if arr[i] == arr[j]: count+=1 if (count % 2 != 0): return arr[i] return -1
[ "assert get_Odd_Occurrence([1,2,3,1,2,3,1],7) == 1", "assert get_Odd_Occurrence([1,2,3,2,3,1,3],7) == 3", "assert get_Odd_Occurrence([2,3,5,4,5,2,4,3,5,2,4,4,2],13) == 5" ]
[]
Write a python function `get_Odd_Occurrence(arr, arr_size)` to find the element occurring odd number of times.
30
Write a python function to count all the substrings starting and ending with same characters.
def check_Equality(s): return (ord(s[0]) == ord(s[len(s) - 1])); def count_Substring_With_Equal_Ends(s): result = 0; n = len(s); for i in range(n): for j in range(1,n-i+1): if (check_Equality(s[i:i+j])): result+=1; return result;
[ "assert count_Substring_With_Equal_Ends(\"abc\") == 3", "assert count_Substring_With_Equal_Ends(\"abcda\") == 6", "assert count_Substring_With_Equal_Ends(\"ab\") == 2" ]
[]
Write a Python function `count_Substring_With_Equal_Ends(s: str) -> int` to count all substrings of `s` that start and end with the same character.
31
Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm.
def func(nums, k): import collections d = collections.defaultdict(int) for row in nums: for i in row: d[i] += 1 temp = [] import heapq for key, v in d.items(): if len(temp) < k: temp.append((v, key)) if len(temp) == k: heapq.heapify(temp) else: if v > temp[0][0]: heapq.heappop(temp) heapq.heappush(temp, (v, key)) result = [] while temp: v, key = heapq.heappop(temp) result.append(key) return result
[ "assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],3)==[5, 7, 1]", "assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],1)==[1]", "assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],5)==[6, 5, 7, 8, 1]" ]
[]
Write a function `func(nums, k)` to find the top `k` integers that occur most frequently from given lists of sorted and distinct integers using a heap queue algorithm.
32
Write a python function to find the largest prime factor of a given number.
import math def max_Prime_Factors (n): maxPrime = -1 while n%2 == 0: maxPrime = 2 n >>= 1 for i in range(3,int(math.sqrt(n))+1,2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime)
[ "assert max_Prime_Factors(15) == 5", "assert max_Prime_Factors(6) == 3", "assert max_Prime_Factors(2) == 2" ]
[]
Write a python function `max_Prime_Factors(n)` to find the largest prime factor of a given number `n`.
33
Write a python function to convert a decimal number to binary number.
def decimal_To_Binary(N): B_Number = 0 cnt = 0 while (N != 0): rem = N % 2 c = pow(10,cnt) B_Number += rem*c N //= 2 cnt += 1 return B_Number
[ "assert decimal_To_Binary(10) == 1010", "assert decimal_To_Binary(1) == 1", "assert decimal_To_Binary(20) == 10100" ]
[]
Write a python function `decimal_To_Binary(N)` to convert a decimal number to binary number.
34
Write a python function to find the missing number in a sorted array.
def find_missing(ar,N): l = 0 r = N - 1 while (l <= r): mid = (l + r) / 2 mid= int (mid) if (ar[mid] != mid + 1 and ar[mid - 1] == mid): return (mid + 1) elif (ar[mid] != mid + 1): r = mid - 1 else: l = mid + 1 return (-1)
[ "assert find_missing([1,2,3,5],4) == 4", "assert find_missing([1,3,4,5],4) == 2", "assert find_missing([1,2,3,5,6,7],5) == 4" ]
[]
Write a python function `find_missing(ar, N)` to find the missing number in a sorted array.
35
Write a function to find the n-th rectangular number.
def find_rect_num(n): return n*(n + 1)
[ "assert find_rect_num(4) == 20", "assert find_rect_num(5) == 30", "assert find_rect_num(6) == 42" ]
[]
Write a function `find_rect_num(n)` to find the n-th rectangular number.
36
Write a python function to find the nth digit in the proper fraction of two given numbers.
def find_Nth_Digit(p,q,N) : while (N > 0) : N -= 1; p *= 10; res = p // q; p %= q; return res;
[ "assert find_Nth_Digit(1,2,1) == 5", "assert find_Nth_Digit(3,5,1) == 6", "assert find_Nth_Digit(5,6,5) == 3" ]
[]
Write a python function `find_Nth_Digit(p, q, N)` to find the Nth digit in the decimal expansion of the proper fraction p/q for two given numbers.
37
Write a function to sort a given mixed list of integers and strings.
def sort_mixed_list(mixed_list): int_part = sorted([i for i in mixed_list if type(i) is int]) str_part = sorted([i for i in mixed_list if type(i) is str]) return int_part + str_part
[ "assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']", "assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']", "assert sort_mixed_list([19,'red',12,'green','blue', 10,'white','green',1])==[1, 10, 12, 19, 'blue', 'green', 'green', 'red', 'white']" ]
[]
Write a function `sort_mixed_list(mixed_list)` to sort a given mixed list of integers and strings.
38
Write a function to find the division of first even and odd number of a given list.
def div_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 div_even_odd([1,3,5,7,4,1,6,8])==4", "assert div_even_odd([1,2,3,4,5,6,7,8,9,10])==2", "assert div_even_odd([1,5,7,9,10])==10" ]
[]
Write a function `div_even_odd(list1)` to find the division of the first even number and the first odd number in a given list.
39
Write a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different.
import heapq from collections import Counter def rearange_string(S): ctr = Counter(S) heap = [(-value, key) for key, value in ctr.items()] heapq.heapify(heap) if (-heap[0][0]) * 2 > len(S) + 1: return "" ans = [] while len(heap) >= 2: nct1, char1 = heapq.heappop(heap) nct2, char2 = heapq.heappop(heap) ans.extend([char1, char2]) if nct1 + 1: heapq.heappush(heap, (nct1 + 1, char1)) if nct2 + 1: heapq.heappush(heap, (nct2 + 1, char2)) return "".join(ans) + (heap[0][1] if heap else "")
[ "assert rearange_string(\"aab\")==('aba')", "assert rearange_string(\"aabb\")==('abab')", "assert rearange_string(\"abccdd\")==('cdabcd')" ]
[]
Write a function `rearange_string(S: str) -> str` to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different.
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})" ]
[]
Write a function `freq_element(nums)` to find the frequency of the elements in a given list of lists using the `collections` module.
41
Write a function to filter even numbers using lambda function.
def filter_evennumbers(nums): even_nums = list(filter(lambda x: x%2 == 0, nums)) return even_nums
[ "assert filter_evennumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[2, 4, 6, 8, 10]", "assert filter_evennumbers([10,20,45,67,84,93])==[10,20,84]", "assert filter_evennumbers([5,7,9,8,6,4,3])==[8,6,4]" ]
[]
Write a function `filter_evennumbers(nums)` to filter even numbers using lambda function.
42
Write a python function to find the sum of repeated elements in a given array.
def find_Sum(arr,n): return sum([x for x in arr if arr.count(x) > 1])
[ "assert find_Sum([1,2,3,1,1,4,5,6],8) == 3", "assert find_Sum([1,2,3,1,1],5) == 3", "assert find_Sum([1,1,2],3) == 2" ]
[ "assert find_Sum([1,1,2,3,4,5,6,3,5],9) == 18" ]
Write a Python function `find_Sum(arr, n)` to find the sum of repeated elements in a given array.
43
Write a function to find sequences of lowercase letters joined with an underscore using regex.
import re def text_match(text): patterns = '^[a-z]+_[a-z]+$' if re.search(patterns, text): return ('Found a match!') else: return ('Not matched!')
[ "assert text_match(\"aab_cbbbc\") == 'Found a match!'", "assert text_match(\"aab_Abbbc\") == 'Not matched!'", "assert text_match(\"Aaab_abbbc\") == 'Not matched!'" ]
[ "assert text_match(\"aab-cbbbc\") == 'Not matched!'" ]
Write a function `text_match(text)` to find sequences of lowercase letters joined with an underscore using regex.
44
Write a function that matches a word at the beginning of a string.
import re def text_match_string(text): patterns = '^\w+' if re.search(patterns, text): return 'Found a match!' else: return 'Not matched!'
[ "assert text_match_string(\" python\")==('Not matched!')", "assert text_match_string(\"python\")==('Found a match!')", "assert text_match_string(\" lang\")==('Not matched!')" ]
[ "assert text_match_string(\"foo\")==('Found a match!')" ]
Write a function `text_match_string(text)` that matches a word at the beginning of a string.
45
Write a function to find the gcd of the given array elements.
def find_gcd(x, y): while(y): x, y = y, x % y return x def get_gcd(l): num1 = l[0] num2 = l[1] gcd = find_gcd(num1, num2) for i in range(2, len(l)): gcd = find_gcd(gcd, l[i]) return gcd
[ "assert get_gcd([2, 4, 6, 8, 16]) == 2", "assert get_gcd([1, 2, 3]) == 1", "assert get_gcd([2, 4, 6, 8]) == 2 " ]
[]
Write a function `get_gcd(l)` to find the gcd of the given array elements.
46
Write a python function to determine whether all the numbers are different from each other are not.
def test_distinct(data): if len(data) == len(set(data)): return True else: return False;
[ "assert test_distinct([1,5,7,9]) == True", "assert test_distinct([2,4,5,5,7,9]) == False", "assert test_distinct([1,2,3]) == True" ]
[]
Write a Python function `test_distinct(data)` that determines whether all the numbers in `data` are different from each other.
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" ]
Write a python function `compute_Last_Digit(A, B)` to find the last digit when factorial of `A` divides factorial of `B`.
48
Write a python function to set all odd bits of a given number.
def odd_bit_set_number(n): count = 0;res = 0;temp = n while temp > 0: if count % 2 == 0: res |= (1 << count) count += 1 temp >>= 1 return (n | res)
[ "assert odd_bit_set_number(10) == 15", "assert odd_bit_set_number(20) == 21", "assert odd_bit_set_number(30) == 31" ]
[]
Write a python function `odd_bit_set_number(n)` to set all odd bits of a given number.
49
Write a function to extract every first or specified element from a given two-dimensional list.
def specified_element(nums, N): result = [i[N] for i in nums] return result
[ "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],0)==[1, 4, 7]", "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],2)==[3, 6, 9]", "assert specified_element([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],1)==[2,5,1]" ]
[]
Write a function `specified_element(nums, N)` to extract every first or specified element from a given two-dimensional list.
50
Write a function to find the list with minimum length using lambda function.
def min_length_list(input_list): min_length = min(len(x) for x in input_list ) min_list = min(input_list, key = lambda i: len(i)) return(min_length, min_list)
[ "assert min_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(1, [0])", "assert min_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(1,[1])", "assert min_length_list([[3,4,5],[6,7,8,9],[10,11,12],[1,2]])==(2,[1,2])" ]
[]
Write a function `min_length_list(input_list)` to find the list with minimum length using a lambda function.
51
Write a function to print check if the triangle is equilateral or not.
def check_equilateral(x,y,z): if x == y == z: return True else: return False
[ "assert check_equilateral(6,8,12)==False ", "assert check_equilateral(6,6,12)==False", "assert check_equilateral(6,6,6)==True" ]
[]
Write a function `check_equilateral(x, y, z)` to check if the triangle is equilateral or not.
52
Write a function to caluclate area of a parallelogram.
def parallelogram_area(b,h): area=b*h return area
[ "assert parallelogram_area(10,20)==200", "assert parallelogram_area(15,20)==300", "assert parallelogram_area(8,9)==72" ]
[]
Write a function `parallelogram_area(b, h)` to caluclate area of a parallelogram.
53
Write a python function to check whether the first and last characters of a given string are equal or not.
def check_Equality(str): if (str[0] == str[-1]): return ("Equal") else: return ("Not Equal")
[ "assert check_Equality(\"abcda\") == \"Equal\"", "assert check_Equality(\"ab\") == \"Not Equal\"", "assert check_Equality(\"mad\") == \"Not Equal\"" ]
[]
Write a Python function `check_Equality(str)` to check whether the first and last characters of a given string are equal or not.
54
Write a function to sort the given array by using counting sort.
def counting_sort(my_list): max_value = 0 for i in range(len(my_list)): if my_list[i] > max_value: max_value = my_list[i] buckets = [0] * (max_value + 1) for i in my_list: buckets[i] += 1 i = 0 for j in range(max_value + 1): for a in range(buckets[j]): my_list[i] = j i += 1 return my_list
[ "assert counting_sort([1,23,4,5,6,7,8]) == [1, 4, 5, 6, 7, 8, 23]", "assert counting_sort([12, 9, 28, 33, 69, 45]) == [9, 12, 28, 33, 45, 69]", "assert counting_sort([8, 4, 14, 3, 2, 1]) == [1, 2, 3, 4, 8, 14]" ]
[]
Write a function `counting_sort(my_list)` to sort the given array by using counting sort.
55
Write a function to find t-nth term of geometric series.
import math def tn_gp(a,n,r): tn = a * (math.pow(r, n - 1)) return tn
[ "assert tn_gp(1,5,2)==16", "assert tn_gp(1,5,4)==256", "assert tn_gp(2,6,3)==486" ]
[]
Write a function `tn_gp(a, n, r)` to find t-nth term of geometric series.
56
Write a python function to check if a given number is one less than twice its reverse.
def rev(num): rev_num = 0 while (num > 0): rev_num = (rev_num * 10 + num % 10) num = num // 10 return rev_num def check(n): return (2 * rev(n) == n + 1)
[ "assert check(70) == False", "assert check(23) == False", "assert check(73) == True" ]
[]
Write a python function `check(n)` to check if a given number is one less than twice its reverse.
57
Write a python function to find the largest number that can be formed with the given digits.
def find_Max_Num(arr,n) : arr.sort(reverse = True) num = arr[0] for i in range(1,n) : num = num * 10 + arr[i] return num
[ "assert find_Max_Num([1,2,3],3) == 321", "assert find_Max_Num([4,5,6,1],4) == 6541", "assert find_Max_Num([1,2,3,9],4) == 9321" ]
[]
Write a Python function `find_Max_Num(arr, n)` to find the largest number that can be formed with the given digits.
58
Write a python function to check whether the given two integers have opposite sign or not.
def opposite_Signs(x,y): return ((x ^ y) < 0);
[ "assert opposite_Signs(1,-2) == True", "assert opposite_Signs(3,2) == False", "assert opposite_Signs(-10,-10) == False" ]
[]
Write a Python function `opposite_Signs(x: int, y: int) -> bool` to check whether the given two integers have opposite sign or not.
59
Write a function to find the nth octagonal number.
def is_octagonal(n): return 3 * n * n - 2 * n
[ "assert is_octagonal(5) == 65", "assert is_octagonal(10) == 280", "assert is_octagonal(15) == 645" ]
[]
Write a function `is_octagonal(n)` to find the nth octagonal number.
60
Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array.
def max_len_sub( arr, n): mls=[] max = 0 for i in range(n): mls.append(1) for i in range(n): for j in range(i): if (abs(arr[i] - arr[j]) <= 1 and mls[i] < mls[j] + 1): mls[i] = mls[j] + 1 for i in range(n): if (max < mls[i]): max = mls[i] return max
[ "assert max_len_sub([2, 5, 6, 3, 7, 6, 5, 8], 8) == 5", "assert max_len_sub([-2, -1, 5, -1, 4, 0, 3], 7) == 4", "assert max_len_sub([9, 11, 13, 15, 18], 5) == 1" ]
[]
Write a function `max_len_sub(arr, n)` to find the maximum length of a subsequence of the given array where the absolute difference between adjacent elements in the subsequence is at most 1.
61
Write a python function to count number of substrings with the sum of digits equal to their length.
from collections import defaultdict def count_Substrings(s,n): count,sum = 0,0 mp = defaultdict(lambda : 0) mp[0] += 1 for i in range(n): sum += ord(s[i]) - ord('0') count += mp[sum - (i + 1)] mp[sum - (i + 1)] += 1 return count
[ "assert count_Substrings('112112',6) == 6", "assert count_Substrings('111',3) == 6", "assert count_Substrings('1101112',7) == 12" ]
[]
Write a python function `count_Substrings(s, n)` to count number of substrings with the sum of digits equal to their length.
62
Write a python function to find smallest number in a list.
def smallest_num(xs): return min(xs)
[ "assert smallest_num([10, 20, 1, 45, 99]) == 1", "assert smallest_num([1, 2, 3]) == 1", "assert smallest_num([45, 46, 50, 60]) == 45" ]
[]
Write a python function `smallest_num(xs)` to find the smallest number in a list.
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" ]
[]
Write a function `max_difference(test_list)` to find the maximum difference between available pairs in the given tuple list.
64
Write a function to sort a list of tuples using lambda.
def subject_marks(subjectmarks): #subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]) subjectmarks.sort(key = lambda x: x[1]) return subjectmarks
[ "assert subject_marks([('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)])==[('Social sciences', 82), ('English', 88), ('Science', 90), ('Maths', 97)]", "assert subject_marks([('Telugu',49),('Hindhi',54),('Social',33)])==([('Social',33),('Telugu',49),('Hindhi',54)])", "assert subject_marks([('Physics',96),('Chemistry',97),('Biology',45)])==([('Biology',45),('Physics',96),('Chemistry',97)])" ]
[]
Write a function `subject_marks(subjectmarks)` to sort a list of tuples using lambda.
65
Write a function of recursion list sum.
def recursive_list_sum(data_list): total = 0 for element in data_list: if type(element) == type([]): total = total + recursive_list_sum(element) else: total = total + element return total
[ "assert recursive_list_sum(([1, 2, [3,4],[5,6]]))==21", "assert recursive_list_sum(([7, 10, [15,14],[19,41]]))==106", "assert recursive_list_sum(([10, 20, [30,40],[50,60]]))==210" ]
[]
Write a function of recursion list sum with the signature `def recursive_list_sum(data_list):`.
66
Write a python function to count positive numbers in a list.
def pos_count(list): pos_count= 0 for num in list: if num >= 0: pos_count += 1 return pos_count
[ "assert pos_count([1,-2,3,-4]) == 2", "assert pos_count([3,4,5,-1]) == 3", "assert pos_count([1,2,3,4]) == 4" ]
[]
Write a python function `pos_count(nums: list) -> int` to count positive numbers in a list.
67
Write a function to find the number of ways to partition a set of bell numbers.
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(10)==115975", "assert bell_number(56)==6775685320645824322581483068371419745979053216268760300" ]
[]
Write a function `bell_number(n)` to find the number of ways to partition a set (Bell number).
68
Write a python function to check whether the given array is monotonic or not.
def is_Monotonic(A): return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or all(A[i] >= A[i + 1] for i in range(len(A) - 1)))
[ "assert is_Monotonic([6, 5, 4, 4]) == True", "assert is_Monotonic([1, 2, 2, 3]) == True", "assert is_Monotonic([1, 3, 2]) == False" ]
[]
Write a Python function `is_Monotonic(A)` to check whether the given array `A` is monotonic or not.
69
Write a function to check whether a list contains the given sublist or not.
def is_sublist(l, s): sub_set = False if s == []: sub_set = True elif s == l: sub_set = True elif len(s) > len(l): sub_set = False else: for i in range(len(l)): if l[i] == s[0]: n = 1 while (n < len(s)) and (l[i+n] == s[n]): n += 1 if n == len(s): sub_set = True return sub_set
[ "assert is_sublist([2,4,3,5,7],[3,7])==False", "assert is_sublist([2,4,3,5,7],[4,3])==True", "assert is_sublist([2,4,3,5,7],[1,6])==False" ]
[]
Write a function `is_sublist(l, s)` to check whether a list `l` contains the given sublist `s` or not.
70
Write a function to find whether all the given tuples have equal length or not.
def find_equal_tuple(Input, k): flag = 1 for tuple in Input: if len(tuple) != k: flag = 0 break return flag def get_equal(Input, k): if find_equal_tuple(Input, k) == 1: return ("All tuples have same length") else: return ("All tuples do not have same length")
[ "assert get_equal([(11, 22, 33), (44, 55, 66)], 3) == 'All tuples have same length'", "assert get_equal([(1, 2, 3), (4, 5, 6, 7)], 3) == 'All tuples do not have same length'", "assert get_equal([(1, 2), (3, 4)], 2) == 'All tuples have same length'" ]
[]
Write a function `get_equal(Input, k)` to find whether all the given tuples have equal length or not.
71
Write a function to sort a list of elements using comb sort.
def comb_sort(nums): shrink_fact = 1.3 gaps = len(nums) swapped = True i = 0 while gaps > 1 or swapped: gaps = int(float(gaps) / shrink_fact) swapped = False i = 0 while gaps + i < len(nums): if nums[i] > nums[i+gaps]: nums[i], nums[i+gaps] = nums[i+gaps], nums[i] swapped = True i += 1 return nums
[ "assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79]", "assert comb_sort([41, 32, 15, 19, 22]) == [15, 19, 22, 32, 41]", "assert comb_sort([99, 15, 13, 47]) == [13, 15, 47, 99]" ]
[]
Write a function `comb_sort(nums)` to sort a list of elements using comb sort.
72
Write a python function to check whether the given number can be represented as difference of two squares or not.
def dif_Square(n): if (n % 4 != 2): return True return False
[ "assert dif_Square(5) == True", "assert dif_Square(10) == False", "assert dif_Square(15) == True" ]
[]
Write a python function `dif_Square(n)` to check whether the given number can be represented as difference of two squares or not.
73
Write a function to split the given string with multiple delimiters by using regex.
import re def multiple_split(text): return (re.split('; |, |\*|\n',text))
[ "assert multiple_split('Forces of the \\ndarkness*are coming into the play.') == ['Forces of the ', 'darkness', 'are coming into the play.']", "assert multiple_split('Mi Box runs on the \\n Latest android*which has google assistance and chromecast.') == ['Mi Box runs on the ', ' Latest android', 'which has google assistance and chromecast.']", "assert multiple_split('Certain services\\nare subjected to change*over the seperate subscriptions.') == ['Certain services', 'are subjected to change', 'over the seperate subscriptions.']" ]
[]
Write a function `multiple_split(text)` to split the given string with multiple delimiters by using regex.
74
Write a function to check whether it follows the sequence given in the patterns array.
def is_samepatterns(colors, patterns): if len(colors) != len(patterns): return False sdict = {} pset = set() sset = set() for i in range(len(patterns)): pset.add(patterns[i]) sset.add(colors[i]) if patterns[i] not in sdict.keys(): sdict[patterns[i]] = [] keys = sdict[patterns[i]] keys.append(colors[i]) sdict[patterns[i]] = keys if len(pset) != len(sset): return False for values in sdict.values(): for i in range(len(values) - 1): if values[i] != values[i+1]: return False return True
[ "assert is_samepatterns([\"red\",\"green\",\"green\"], [\"a\", \"b\", \"b\"])==True ", "assert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\",\"b\"])==False ", "assert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\"])==False " ]
[]
Write a function `is_samepatterns(colors, patterns)` to check whether `colors` follows the sequence given in the `patterns` array.
75
Write a function to find tuples which have all elements divisible by k from the given list of tuples.
def find_tuples(test_list, K): res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)] return (str(res))
[ "assert find_tuples([(6, 24, 12), (7, 9, 6), (12, 18, 21)], 6) == '[(6, 24, 12)]'", "assert find_tuples([(5, 25, 30), (4, 2, 3), (7, 8, 9)], 5) == '[(5, 25, 30)]'", "assert find_tuples([(7, 9, 16), (8, 16, 4), (19, 17, 18)], 4) == '[(8, 16, 4)]'" ]
[]
Write a function `find_tuples(test_list, K)` to find tuples which have all elements divisible by `K` from the given list of tuples.
76
Write a python function to count the number of squares in a rectangle.
def count_Squares(m,n): if(n < m): temp = m m = n n = temp return ((m * (m + 1) * (2 * m + 1) / 6 + (n - m) * m * (m + 1) / 2))
[ "assert count_Squares(4,3) == 20", "assert count_Squares(2,2) == 5", "assert count_Squares(1,1) == 1" ]
[]
Write a python function `count_Squares(m, n)` to count the number of squares in a rectangle.
77
Write a python function to find the difference between sum of even and odd digits.
def is_Diff(n): return (n % 11 == 0)
[ "assert is_Diff (12345) == False", "assert is_Diff(1212112) == True", "assert is_Diff(1212) == False" ]
[]
Write a python function `is_Diff(n)` to find the difference between the sum of digits in even and odd positions of `n` and return whether it is divisible by 11.
78
Write a python function to find number of integers with odd number of set bits.
def count_With_Odd_SetBits(n): if (n % 2 != 0): return (n + 1) / 2 count = bin(n).count('1') ans = n / 2 if (count % 2 != 0): ans += 1 return ans
[ "assert count_With_Odd_SetBits(5) == 3", "assert count_With_Odd_SetBits(10) == 5", "assert count_With_Odd_SetBits(15) == 8" ]
[]
Write a python function `count_With_Odd_SetBits(n)` to find number of integers with odd number of set bits.
79
Write a python function to check whether the length of the word is odd or not.
def word_len(s): s = s.split(' ') for word in s: if len(word)%2!=0: return True else: return False
[ "assert word_len(\"Hadoop\") == False", "assert word_len(\"great\") == True", "assert word_len(\"structure\") == True" ]
[]
Write a Python function `word_len(s)` to check whether the length of the word is odd or not.
80
Write a function to find the nth tetrahedral number.
def tetrahedral_number(n): return (n * (n + 1) * (n + 2)) / 6
[ "assert tetrahedral_number(5) == 35.0", "assert tetrahedral_number(6) == 56.0", "assert tetrahedral_number(7) == 84.0" ]
[]
Write a function `tetrahedral_number(n)` to find the nth tetrahedral number.
81
Write a function to zip the two given tuples.
def zip_tuples(test_tup1, test_tup2): res = [] for i, j in enumerate(test_tup1): res.append((j, test_tup2[i % len(test_tup2)])) return (res)
[ "assert zip_tuples((7, 8, 4, 5, 9, 10),(1, 5, 6) ) == [(7, 1), (8, 5), (4, 6), (5, 1), (9, 5), (10, 6)]", "assert zip_tuples((8, 9, 5, 6, 10, 11),(2, 6, 7) ) == [(8, 2), (9, 6), (5, 7), (6, 2), (10, 6), (11, 7)]", "assert zip_tuples((9, 10, 6, 7, 11, 12),(3, 7, 8) ) == [(9, 3), (10, 7), (6, 8), (7, 3), (11, 7), (12, 8)]" ]
[]
Write a function `zip_tuples(test_tup1, test_tup2)` to zip the two given tuples.
82
Write a function to find the volume of a sphere.
import math def volume_sphere(r): volume=(4/3)*math.pi*r*r*r return volume
[ "assert volume_sphere(10)==4188.790204786391", "assert volume_sphere(25)==65449.84694978735", "assert volume_sphere(20)==33510.32163829113" ]
[]
Write a function `volume_sphere(r)` to find the volume of a sphere.
83
Write a python function to find the character made by adding all the characters of the given string.
def get_Char(strr): summ = 0 for i in range(len(strr)): summ += (ord(strr[i]) - ord('a') + 1) if (summ % 26 == 0): return ord('z') else: summ = summ % 26 return chr(ord('a') + summ - 1)
[ "assert get_Char(\"abc\") == \"f\"", "assert get_Char(\"gfg\") == \"t\"", "assert get_Char(\"ab\") == \"c\"" ]
[]
Write a python function `get_Char(strr)` to find the character made by adding all the characters of the given string.
84
Write a function to find the n-th number in newman conway sequence.
def sequence(n): if n == 1 or n == 2: return 1 else: return sequence(sequence(n-1)) + sequence(n-sequence(n-1))
[ "assert sequence(10) == 6", "assert sequence(2) == 1", "assert sequence(3) == 2" ]
[]
Write a function `sequence(n)` to find the n-th number in the Newman–Conway sequence.
85
Write a function to find the surface area of a sphere.
import math def surfacearea_sphere(r): surfacearea=4*math.pi*r*r return surfacearea
[ "assert surfacearea_sphere(10)==1256.6370614359173", "assert surfacearea_sphere(15)==2827.4333882308138", "assert surfacearea_sphere(20)==5026.548245743669" ]
[]
Write a function `surfacearea_sphere(r)` to find the surface area of a sphere.
86
Write a function to find nth centered hexagonal number.
def centered_hexagonal_number(n): return 3 * n * (n - 1) + 1
[ "assert centered_hexagonal_number(10) == 271", "assert centered_hexagonal_number(2) == 7", "assert centered_hexagonal_number(9) == 217" ]
[]
Write a function `centered_hexagonal_number(n)` to find the nth centered hexagonal number.
87
Write a function to merge three dictionaries into a single expression.
import collections as ct def merge_dictionaries_three(dict1,dict2, dict3): merged_dict = dict(ct.ChainMap({},dict1,dict2,dict3)) return merged_dict
[ "assert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" },{ \"O\": \"Orange\", \"W\": \"White\", \"B\": \"Black\" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White', 'O': 'Orange'}", "assert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" },{\"L\":\"lavender\",\"B\":\"Blue\"})=={'W': 'White', 'P': 'Pink', 'B': 'Black', 'R': 'Red', 'G': 'Green', 'L': 'lavender'}", "assert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" },{\"L\":\"lavender\",\"B\":\"Blue\"},{ \"G\": \"Green\", \"W\": \"White\" })=={'B': 'Black', 'P': 'Pink', 'R': 'Red', 'G': 'Green', 'L': 'lavender', 'W': 'White'}" ]
[]
Write a function `merge_dictionaries_three(dict1, dict2, dict3)` to merge three dictionaries into a single expression.
88
Write a function to get the frequency of the elements in a list.
import collections def freq_count(list1): freq_count= collections.Counter(list1) return freq_count
[ "assert freq_count([10,10,10,10,20,20,20,20,40,40,50,50,30])==({10: 4, 20: 4, 40: 2, 50: 2, 30: 1}) ", "assert freq_count([1,2,3,4,3,2,4,1,3,1,4])==({1:3, 2:2,3:3,4:3}) ", "assert freq_count([5,6,7,4,9,10,4,5,6,7,9,5])==({10:1,5:3,6:2,7:2,4:2,9:2}) " ]
[]
Write a function `freq_count(list1)` to get the frequency of the elements in a list.
89
Write a function to find the closest smaller number than n.
def closest_num(N): return (N - 1)
[ "assert closest_num(11) == 10", "assert closest_num(7) == 6", "assert closest_num(12) == 11" ]
[]
Write a function `closest_num(N)` to find the closest smaller number than `N`.
90
Write a python function to find the length of the longest word.
def len_log(list1): max=len(list1[0]) for i in list1: if len(i)>max: max=len(i) return max
[ "assert len_log([\"python\",\"PHP\",\"bigdata\"]) == 7", "assert len_log([\"a\",\"ab\",\"abc\"]) == 3", "assert len_log([\"small\",\"big\",\"tall\"]) == 5" ]
[]
Write a Python function `len_log(list1)` to find the length of the longest word in `list1`.
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" ]
[]
Write a function `find_substring(str1, sub_str)` to check if a substring is present in a given list of string values.
92
Write a function to check whether the given number is undulating or not.
def is_undulating(n): if (len(n) <= 2): return False for i in range(2, len(n)): if (n[i - 2] != n[i]): return False return True
[ "assert is_undulating(\"1212121\") == True", "assert is_undulating(\"1991\") == False", "assert is_undulating(\"121\") == True" ]
[]
Write a function `is_undulating(n)` to check whether the given number is undulating or not.
93
Write a function to calculate the value of 'a' to the power 'b'.
def power(a,b): if b==0: return 1 elif a==0: return 0 elif b==1: return a else: return a*power(a,b-1)
[ "assert power(3,4) == 81", "assert power(2,3) == 8", "assert power(5,5) == 3125" ]
[]
Write a function `power(a, b)` to calculate the value of `a` to the power `b`.
94
Write a function to extract the index minimum value record from the given tuples.
from operator import itemgetter def index_minimum(test_list): res = min(test_list, key = itemgetter(1))[0] return (res)
[ "assert index_minimum([('Rash', 143), ('Manjeet', 200), ('Varsha', 100)]) == 'Varsha'", "assert index_minimum([('Yash', 185), ('Dawood', 125), ('Sanya', 175)]) == 'Dawood'", "assert index_minimum([('Sai', 345), ('Salman', 145), ('Ayesha', 96)]) == 'Ayesha'" ]
[]
Write a function `index_minimum(test_list)` to extract the index minimum value record from the given tuples.
95
Write a python function to find the minimum length of sublist.
def Find_Min_Length(lst): minLength = min(len(x) for x in lst ) return minLength
[ "assert Find_Min_Length([[1],[1,2]]) == 1", "assert Find_Min_Length([[1,2],[1,2,3],[1,2,3,4]]) == 2", "assert Find_Min_Length([[3,3,3],[4,4,4,4]]) == 3" ]
[]
Write a python function `Find_Min_Length(lst)` to find the minimum length of sublist.
96
Write a python function to find the number of divisors of a given integer.
def divisor(n): for i in range(n): x = len([i for i in range(1,n+1) if not n % i]) return x
[ "assert divisor(15) == 4 ", "assert divisor(12) == 6", "assert divisor(9) == 3" ]
[]
Write a python function `divisor(n)` to find the number of divisors of a given integer `n`.
97
Write a function to find frequency count of list of lists.
def frequency_lists(list1): list1 = [item for sublist in list1 for item in sublist] dic_data = {} for num in list1: if num in dic_data.keys(): dic_data[num] += 1 else: key = num value = 1 dic_data[key] = value return dic_data
[ "assert frequency_lists([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]])=={1: 1, 2: 3, 3: 1, 4: 1, 5: 2, 6: 1, 7: 1, 8: 1, 9: 1}", "assert frequency_lists([[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 frequency_lists([[20,30,40,17],[18,16,14,13],[10,20,30,40]])=={20:2,30:2,40:2,17: 1,18:1, 16: 1,14: 1,13: 1, 10: 1}" ]
[]
Write a function `frequency_lists(list1)` to find the frequency count of elements in a list of lists.
98
Write a function to multiply all the numbers in a list and divide with the length of the list.
def multiply_num(numbers): total = 1 for x in numbers: total *= x return total/len(numbers)
[ "assert multiply_num((8, 2, 3, -1, 7))==-67.2", "assert multiply_num((-10,-20,-30))==-2000.0", "assert multiply_num((19,15,18))==1710.0" ]
[]
Write a function `multiply_num(numbers)` to multiply all the numbers in a list and divide with the length of the list.
99
Write a function to convert the given decimal number to its binary equivalent.
def decimal_to_binary(n): return bin(n).replace("0b","")
[ "assert decimal_to_binary(8) == '1000'", "assert decimal_to_binary(18) == '10010'", "assert decimal_to_binary(7) == '111' " ]
[]
Write a function `decimal_to_binary(n)` to convert the given decimal number to its binary equivalent.
100
Write a function to find the next smallest palindrome of a specified number.
import sys def next_smallest_palindrome(num): numstr = str(num) for i in range(num+1,sys.maxsize): if str(i) == str(i)[::-1]: return i
[ "assert next_smallest_palindrome(99)==101", "assert next_smallest_palindrome(1221)==1331", "assert next_smallest_palindrome(120)==121" ]
[]
Write a function `next_smallest_palindrome(num)` to find the next smallest palindrome of a specified number.
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" ]
[]
Write a function `kth_element(arr, n, k)` to find the kth element in the given array.
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')" ]
[]
Write a function `snake_to_camel(word)` to convert a snake case string to a camel case string.
103
Write a function to find eulerian number a(n, m).
def eulerian_num(n, m): if (m >= n or n == 0): return 0 if (m == 0): return 1 return ((n - m) * eulerian_num(n - 1, m - 1) +(m + 1) * eulerian_num(n - 1, m))
[ "assert eulerian_num(3, 1) == 4", "assert eulerian_num(4, 1) == 11", "assert eulerian_num(5, 3) == 26" ]
[]
Write a function `eulerian_num(n, m)` to find the Eulerian number a(n, m).
104
Write a function to sort each sublist of strings in a given list of lists using lambda function.
def sort_sublists(input_list): result = [sorted(x, key = lambda x:x[0]) for x in input_list] return result
[ "assert sort_sublists(([\"green\", \"orange\"], [\"black\", \"white\"], [\"white\", \"black\", \"orange\"]))==[['green', 'orange'], ['black', 'white'], ['black', 'orange', 'white']]", "assert sort_sublists(([\" red \",\"green\" ],[\"blue \",\" black\"],[\" orange\",\"brown\"]))==[[' red ', 'green'], [' black', 'blue '], [' orange', 'brown']]", "assert sort_sublists(([\"zilver\",\"gold\"], [\"magnesium\",\"aluminium\"], [\"steel\", \"bronze\"]))==[['gold', 'zilver'],['aluminium', 'magnesium'], ['bronze', 'steel']]" ]
[]
Write a function `sort_sublists(input_list)` to sort each sublist of strings in a given list of lists using a lambda function.
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" ]
[]
Write a python function `count(lst)` to count true booleans in the given list.
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)" ]
[]
Write a function `add_lists(test_list, test_tup)` to add the given list to the given tuples.
107
Write a python function to count hexadecimal numbers for a given range.
def count_Hexadecimal(L,R) : count = 0; for i in range(L,R + 1) : if (i >= 10 and i <= 15) : count += 1; elif (i > 15) : k = i; while (k != 0) : if (k % 16 >= 10) : count += 1; k = k // 16; return count;
[ "assert count_Hexadecimal(10,15) == 6", "assert count_Hexadecimal(2,4) == 0", "assert count_Hexadecimal(15,16) == 1" ]
[]
Write a python function `count_Hexadecimal(L, R)` to count hexadecimal numbers for a given range.
108
Write a function to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm.
import heapq def merge_sorted_list(num1,num2,num3): num1=sorted(num1) num2=sorted(num2) num3=sorted(num3) result = heapq.merge(num1,num2,num3) return list(result)
[ "assert merge_sorted_list([25, 24, 15, 4, 5, 29, 110],[19, 20, 11, 56, 25, 233, 154],[24, 26, 54, 48])==[4, 5, 11, 15, 19, 20, 24, 24, 25, 25, 26, 29, 48, 54, 56, 110, 154, 233]", "assert merge_sorted_list([1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12])==[1, 1, 2, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 11, 12]", "assert merge_sorted_list([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1],[25, 35, 22, 85, 14, 65, 75, 25, 58],[12, 74, 9, 50, 61, 41])==[1, 2, 3, 4, 7, 8, 9, 9, 9, 10, 12, 14, 14, 18, 22, 25, 25, 35, 41, 50, 58, 61, 65, 74, 75, 85]" ]
[]
Write a function `merge_sorted_list(num1, num2, num3)` to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm.
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" ]
[]
Write a python function `odd_Equivalent(s, n)` to find the count of rotations of a binary string with odd value.
110
Write a function to extract the ranges that are missing from the given list with the given start range and end range values.
def extract_missing(test_list, strt_val, stop_val): res = [] for sub in test_list: if sub[0] > strt_val: res.append((strt_val, sub[0])) strt_val = sub[1] if strt_val < stop_val: res.append((strt_val, stop_val)) return (res)
[ "assert extract_missing([(6, 9), (15, 34), (48, 70)], 2, 100) == [(2, 6), (9, 100), (9, 15), (34, 100), (34, 48), (70, 100)]", "assert extract_missing([(7, 2), (15, 19), (38, 50)], 5, 60) == [(5, 7), (2, 60), (2, 15), (19, 60), (19, 38), (50, 60)]", "assert extract_missing([(7, 2), (15, 19), (38, 50)], 1, 52) == [(1, 7), (2, 52), (2, 15), (19, 52), (19, 38), (50, 52)]" ]
[]
Write a function `extract_missing(test_list, strt_val, stop_val)` to extract the ranges that are missing from the given list with the given start range and end range values.
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
15