Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to get the frequency of all the elements in a list, returned as a dictionary.

Tests:
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})

import collections
def freq_count(list1):
  freq_count= collections.Counter(list1)
  return freq_count


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the closest smaller number than n.

Tests:
assert closest_num(11) == 10
assert closest_num(7) == 6
assert closest_num(12) == 11


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the length of the longest word.

Tests:
assert len_log(["python","PHP","bigdata"]) == 7
assert len_log(["a","ab","abc"]) == 3
assert len_log(["small","big","tall"]) == 5

def len_log(list1):
    max=len(list1[0])
    for i in list1:
        if len(i)>max:
            max=len(i)
    return max


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to check if a string is present as a substring in a given list of string values.

Tests:
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

def find_substring(str1, sub_str):
   if any(sub_str in s for s in str1):
       return True
   return False


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to check whether the given number is undulating or not.

Tests:
assert is_undulating(1212121) == True
assert is_undulating(1991) == False
assert is_undulating(121) == True

def is_undulating(n):
	n = str(n)
	if (len(n) <= 2):
		return False
	for i in range(2, len(n)):
		if (n[i - 2] != n[i]):
			return False
	return True


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to calculate the value of 'a' to the power 'b'.

Tests:
assert power(3,4) == 81
assert power(2,3) == 8
assert power(5,5) == 3125

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)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Given a list of tuples, write a function that returns the first value of the tuple with the smallest second value.

Tests:
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'

from operator import itemgetter
def index_minimum(test_list):
  res = min(test_list, key = itemgetter(1))[0]
  return (res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the length of the smallest list in a list of lists.

Tests:
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

def Find_Min_Length(lst):
    minLength = min(len(x) for x in lst )
    return minLength


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the number of divisors of a given integer.

Tests:
assert divisor(15) == 4
assert divisor(12) == 6
assert divisor(9) == 3

def divisor(n):
  for i in range(n):
    x = len([i for i in range(1,n+1) if not n % i])
  return x


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find frequency of each element in a flattened list of lists, returned in a dictionary.

Tests:
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}

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


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to multiply all the numbers in a list and divide with the length of the list.

Tests:
assert math.isclose(multiply_num((8, 2, 3, -1, 7)), -67.2, rel_tol=0.001)
assert math.isclose(multiply_num((-10,-20,-30)), -2000.0, rel_tol=0.001)
assert math.isclose(multiply_num((19,15,18)), 1710.0, rel_tol=0.001)

def multiply_num(numbers):
    total = 1
    for x in numbers:
        total *= x
    return total/len(numbers)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to convert the given decimal number to its binary equivalent, represented as a string with no leading zeros.

Tests:
assert decimal_to_binary(8) == '1000'
assert decimal_to_binary(18) == '10010'
assert decimal_to_binary(7) == '111'

def decimal_to_binary(n):
    return bin(n).replace("0b","")


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the next smallest palindrome of a specified integer, returned as an integer.

Tests:
assert next_smallest_palindrome(99)==101
assert next_smallest_palindrome(1221)==1331
assert next_smallest_palindrome(120)==121

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


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the kth element in the given array using 1-based indexing.

Tests:
assert kth_element([12,3,5,7,19], 2) == 3
assert kth_element([17,24,8,23], 3) == 8
assert kth_element([16,21,25,36,4], 4) == 36

def kth_element(arr, k):
  n = len(arr)
  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]


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to convert a snake case string to camel case string.

Tests:
assert snake_to_camel('python_program')=='PythonProgram'
assert snake_to_camel('python_language')==('PythonLanguage')
assert snake_to_camel('programming_language')==('ProgrammingLanguage')

def snake_to_camel(word):
        import re
        return ''.join(x.capitalize() or '_' for x in word.split('_'))


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the Eulerian number a(n, m).

Tests:
assert eulerian_num(3, 1) == 4
assert eulerian_num(4, 1) == 11
assert eulerian_num(5, 3) == 26

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))


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to sort each sublist of strings in a given list of lists.

Tests:
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']]

def sort_sublists(input_list):
    result = [sorted(x, key = lambda x:x[0]) for x in input_list]
    return result


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to count true booleans in the given list.

Tests:
assert count([True,False,True]) == 2
assert count([False,False]) == 0
assert count([True,True,True]) == 3


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to append the given list to the given tuples.

Tests:
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)

def add_lists(test_list, test_tup):
  res = tuple(list(test_tup) + test_list)
  return (res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to merge three lists into a single sorted list.

Tests:
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]

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)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the number of numbers with an odd value when rotating a binary string the given number of times.

Tests:
assert odd_Equivalent("011001",6) == 3
assert odd_Equivalent("11011",5) == 4
assert odd_Equivalent("1010",4) == 2

def odd_Equivalent(s,n):
    count=0
    for i in range(0,n):
        if (s[i] == '1'):
            count = count + 1
    return count


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the common elements in given nested lists.

Tests:
assert set(common_in_nested_lists([[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]]))==set([18, 12])
assert set(common_in_nested_lists([[12, 5, 23, 25, 45], [7, 11, 5, 23, 28], [1, 5, 8, 18, 23, 16]]))==set([5,23])
assert set(common_in_nested_lists([[2, 3,4, 1], [4, 5], [6,4, 8],[4, 5], [6, 8,4]]))==set([4])

def common_in_nested_lists(nestedlist):
    result = list(set.intersection(*map(set, nestedlist)))
    return result


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to check if a string represents an integer or not.

Tests:
assert check_integer("python")==False
assert check_integer("1")==True
assert check_integer("12345")==True

def check_integer(text):
 text = text.strip()
 if len(text) < 1:
    return None
 else:
     if all(text[i] in "0123456789" for i in range(len(text))):
          return True
     elif (text[0] in "+-") and \
         all(text[i] in "0123456789" for i in range(1,len(text))):
         return True
     else:
        return False


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to check whether all dictionaries in a list are empty or not.

Tests:
assert empty_dit([{},{},{}])==True
assert empty_dit([{1,2},{},{}])==False
assert empty_dit({})==True

def empty_dit(list1):
 empty_dit=all(not d for d in list1)
 return empty_dit


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to convert a given tuple of positive integers into a single integer.

Tests:
assert tuple_to_int((1,2,3))==123
assert tuple_to_int((4,5,6))==456
assert tuple_to_int((5,6,7))==567

def tuple_to_int(nums):
    result = int(''.join(map(str,nums)))
    return result


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to convert all possible convertible elements in a list of lists to floats.

Tests:
assert list_to_float( [("3", "4"), ("1", "26.45"), ("7.32", "8"), ("4", "8")] ) == [(3.0, 4.0), (1.0, 26.45), (7.32, 8.0), (4.0, 8.0)]
assert list_to_float( [("4", "4"), ("2", "27"), ("4.12", "9"), ("7", "11")] ) == [(4.0, 4.0), (2.0, 27.0), (4.12, 9.0), (7.0, 11.0)]
assert list_to_float( [("6", "78"), ("5", "26.45"), ("1.33", "4"), ("82", "13")] ) == [(6.0, 78.0), (5.0, 26.45), (1.33, 4.0), (82.0, 13.0)]

def list_to_float(test_list):
  res = []
  for tup in test_list:
    temp = []
    for ele in tup:
      if ele.isalpha():
        temp.append(ele)
      else:
        temp.append(float(ele))
    res.append((temp[0],temp[1]))
  return res


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to convert a string to a list of strings split on the space character.

Tests:
assert string_to_list("python programming")==['python','programming']
assert string_to_list("lists tuples strings")==['lists','tuples','strings']
assert string_to_list("write a program")==['write','a','program']

def string_to_list(string):
    lst = list(string.split(" "))
    return lst


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the element that appears only once in a sorted array.

Tests:
assert search([1,1,2,2,3]) == 3
assert search([1,1,3,3,4,4,5,5,7,7,8]) == 8
assert search([1,2,2,3,3,4,4]) == 1

def search(arr):
    n = len(arr)
    XOR = 0
    for i in range(n) :
        XOR = XOR ^ arr[i]
    return (XOR)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the maximum absolute product between numbers in pairs of tuples within a given list.

Tests:
assert max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==36
assert max_product_tuple([(10,20), (15,2), (5,10)] )==200
assert max_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==484

def max_product_tuple(list1):
    result_max = max([abs(x * y) for x, y in list1] )
    return result_max


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to sum all amicable numbers from 1 to a specified number.

Tests:
assert amicable_numbers_sum(999)==504
assert amicable_numbers_sum(9999)==31626
assert amicable_numbers_sum(99)==0

def amicable_numbers_sum(limit):
    if not isinstance(limit, int):
        return "Input is not an integer!"
    if limit < 1:
        return "Input must be bigger than 0!"
    amicables = set()
    for num in range(2, limit+1):
        if num in amicables:
            continue
        sum_fact = sum([fact for fact in range(1, num) if num % fact == 0])
        sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0])
        if num == sum_fact2 and num != sum_fact:
            amicables.add(num)
            amicables.add(sum_fact2)
    return sum(amicables)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to get the angle of a complex number.

Tests:
assert math.isclose(angle_complex(0,1j), 1.5707963267948966, rel_tol=0.001)
assert math.isclose(angle_complex(2,1j), 0.4636476090008061, rel_tol=0.001)
assert math.isclose(angle_complex(0,2j), 1.5707963267948966, rel_tol=0.001)

import cmath
def angle_complex(a,b):
  cn=complex(a,b)
  angle=cmath.phase(a+b)
  return angle


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string.

Tests:
assert find_length("11000010001") == 6
assert find_length("10111") == 1
assert find_length("11011101100101") == 2

def find_length(string):
	n = len(string)
	current_sum = 0
	max_sum = 0
	for i in range(n):
		current_sum += (1 if string[i] == '0' else -1)
		if current_sum < 0:
			current_sum = 0
		max_sum = max(current_sum, max_sum)
	return max_sum if max_sum else 0


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the sum of common divisors of two given numbers.

Tests:
assert sum(10,15) == 6
assert sum(100,150) == 93
assert sum(4,6) == 3

def sum(a,b):
    sum = 0
    for i in range (1,min(a,b)):
        if (a % i == 0 and b % i == 0):
            sum += i
    return sum


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to multiply two integers.

Tests:
assert multiply_int(10,20)==200
assert multiply_int(5,10)==50
assert multiply_int(4,8)==32

def multiply_int(x, y):
    if y < 0:
        return -multiply_int(x, -y)
    elif y == 0:
        return 0
    elif y == 1:
        return x
    else:
        return x + multiply_int(x, y - 1)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find words that are longer than n characters from a given list of words.

Tests:
assert long_words(3,"python is a programming language")==['python','programming','language']
assert long_words(2,"writing a program")==['writing','program']
assert long_words(5,"sorting list")==['sorting']

def long_words(n, str):
    word_len = []
    txt = str.split(" ")
    for x in txt:
        if len(x) > n:
            word_len.append(x)
    return word_len


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to calculate whether the matrix is a magic square.

Tests:
assert magic_square_test([[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]])==True
assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 8]])==True
assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 7]])==False

def magic_square_test(my_matrix):
    iSize = len(my_matrix[0])
    sum_list = []
    sum_list.extend([sum (lines) for lines in my_matrix])
    for col in range(iSize):
        sum_list.append(sum(row[col] for row in my_matrix))
    result1 = 0
    for i in range(0,iSize):
        result1 +=my_matrix[i][i]
    sum_list.append(result1)
    result2 = 0
    for i in range(iSize-1,-1,-1):
        result2 +=my_matrix[i][i]
    sum_list.append(result2)
    if len(set(sum_list))>1:
        return False
    return True


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the item with maximum frequency in a given list.

Tests:
assert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2])==2
assert max_occurrences([2,3,8,4,7,9,8,7,9,15,14,10,12,13,16,18])==8
assert max_occurrences([10,20,20,30,40,90,80,50,30,20,50,10])==20

from collections import defaultdict
def max_occurrences(nums):
    dict = defaultdict(int)
    for i in nums:
        dict[i] += 1
    result = max(dict.items(), key=lambda x: x[1])
    return result[0]


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to reverse only the vowels of a given string (where y is not a vowel).

Tests:
assert reverse_vowels("Python") == "Python"
assert reverse_vowels("USA") == "ASU"
assert reverse_vowels("ab") == "ab"

def reverse_vowels(str1):
	vowels = ""
	for char in str1:
		if char in "aeiouAEIOU":
			vowels += char
	result_string = ""
	for char in str1:
		if char in "aeiouAEIOU":
			result_string += vowels[-1]
			vowels = vowels[:-1]
		else:
			result_string += char
	return result_string


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to convert a tuple to a string.

Tests:
assert tup_string(('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's'))==("exercises")
assert tup_string(('p','y','t','h','o','n'))==("python")
assert tup_string(('p','r','o','g','r','a','m'))==("program")

def tup_string(tup1):
  str =  ''.join(tup1)
  return str


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to calculate the sum of the negative numbers of a given list of numbers.

Tests:
assert sum_negativenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==-32
assert sum_negativenum([10,15,-14,13,-18,12,-20])==-52
assert sum_negativenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==-894

def sum_negativenum(nums):
  sum_negativenum = list(filter(lambda nums:nums<0,nums))
  return sum(sum_negativenum)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the nth hexagonal number.

Tests:
assert hexagonal_num(10) == 190
assert hexagonal_num(5) == 45
assert hexagonal_num(7) == 91

def hexagonal_num(n):
	return n*(2*n - 1)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the ratio of zeroes to non-zeroes in an array of integers.

Tests:
assert math.isclose(zero_count([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8]), 0.181818, rel_tol=0.001)
assert math.isclose(zero_count([2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8]), 0.00, rel_tol=0.001)
assert math.isclose(zero_count([2, 4, -6, -9, 11, -12, 14, -5, 17]), 0.00, rel_tol=0.001)

from array import array
def zero_count(nums):
    n = len(nums)
    n1 = 0
    for x in nums:
        if x == 0:
            n1 += 1
        else:
          None
    return n1/(n-n1)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.

Tests:
assert is_Sum_Of_Powers_Of_Two(10) == True
assert is_Sum_Of_Powers_Of_Two(7) == False
assert is_Sum_Of_Powers_Of_Two(14) == True

def is_Sum_Of_Powers_Of_Two(n):
    if (n % 2 == 1):
        return False
    else:
        return True


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the circumference of a circle.

Tests:
assert math.isclose(circle_circumference(10), 62.830000000000005, rel_tol=0.001)
assert math.isclose(circle_circumference(5), 31.415000000000003, rel_tol=0.001)
assert math.isclose(circle_circumference(4), 25.132, rel_tol=0.001)

def circle_circumference(r):
  perimeter=2*3.1415*r
  return perimeter


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to flatten the list of lists into a single set of numbers.

Tests:
assert set(extract_singly([(3, 4, 5), (4, 5, 7), (1, 4)])) == set([3, 4, 5, 7, 1])
assert set(extract_singly([(1, 2, 3), (4, 2, 3), (7, 8)])) == set([1, 2, 3, 4, 7, 8])
assert set(extract_singly([(7, 8, 9), (10, 11, 12), (10, 11)])) == set([7, 8, 9, 10, 11, 12])

def extract_singly(test_list):
  res = []
  temp = set()
  for inner in test_list:
    for ele in inner:
      if not ele in temp:
        temp.add(ele)
        res.append(ele)
  return (res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to sort a list of elements.

Tests:
assert pancake_sort([15, 79, 25, 38, 69]) == [15, 25, 38, 69, 79]
assert pancake_sort([98, 12, 54, 36, 85]) == [12, 36, 54, 85, 98]
assert pancake_sort([41, 42, 32, 12, 23]) == [12, 23, 32, 41, 42]

def pancake_sort(nums):
    arr_len = len(nums)
    while arr_len > 1:
        mi = nums.index(max(nums[0:arr_len]))
        nums = nums[mi::-1] + nums[mi+1:len(nums)]
        nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)]
        arr_len -= 1
    return nums


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to count number items that are identical in the same position of three given lists.

Tests:
assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,9],[2,1,3,1,2,6,7,9])==3
assert count_samepair([1,2,3,4,5,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==4
assert count_samepair([1,2,3,4,2,6,7,8],[2,2,3,1,2,6,7,8],[2,1,3,1,2,6,7,8])==5

def count_samepair(list1,list2,list3):
    result = sum(m == n == o for m, n, o in zip(list1,list2,list3))
    return result


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find number of lists present in the given tuple.

Tests:
assert find_lists(([1, 2, 3, 4], [5, 6, 7, 8])) == 2
assert find_lists(([1, 2], [3, 4], [5, 6]))  == 3
assert find_lists(([9, 8, 7, 6, 5, 4, 3, 2, 1])) == 1

def find_lists(Input):
	if isinstance(Input, list):
		return 1
	else:
		return len(Input)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the maximum difference between any two elements in a given array.

Tests:
assert max_Abs_Diff((2,1,5,3)) == 4
assert max_Abs_Diff((9,3,2,5,1)) == 8
assert max_Abs_Diff((3,2,1)) == 2

def max_Abs_Diff(arr):
    n = len(arr)
    minEle = arr[0]
    maxEle = arr[0]
    for i in range(1, n):
        minEle = min(minEle,arr[i])
        maxEle = max(maxEle,arr[i])
    return (maxEle - minEle)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that returns integers x and y that satisfy ax + by = n as a tuple, or return None if no solution exists.

Tests:
assert find_solution(2, 3, 7) == (2, 1)
assert find_solution(4, 2, 7) == None
assert find_solution(1, 13, 17) == (4, 1)

def find_solution(a, b, n):
	i = 0
	while i * a <= n:
		if (n - (i * a)) % b == 0:
			return (i, (n - (i * a)) // b)
		i = i + 1
	return None


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to remove all elements from a given list present in another list.

Tests:
assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2, 4, 6, 8]) == [1, 3, 5, 7, 9, 10]
assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 3, 5, 7]) == [2, 4, 6, 8, 9, 10]
assert remove_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [5, 7]) == [1, 2, 3, 4, 6, 8, 9, 10]

def remove_elements(list1, list2):
    result = [x for x in list1 if x not in list2]
    return result


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to calculate the sum (n - 2*i) from i=0 to n // 2, for instance n + (n-2) + (n-4)... (until n-x =< 0).

Tests:
assert sum_series(6) == 12
assert sum_series(10) == 30
assert sum_series(9) == 25

def sum_series(n):
  if n < 1:
    return 0
  else:
    return n + sum_series(n - 2)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to calculate the area of a regular polygon given the length and number of its sides.

Tests:
assert math.isclose(area_polygon(4, 20), 400., rel_tol=0.001)
assert math.isclose(area_polygon(10, 15), 1731.197, rel_tol=0.001)
assert math.isclose(area_polygon(9, 7), 302.909, rel_tol=0.001)

from math import tan, pi
def area_polygon(s, l):
  area = s * (l ** 2) / (4 * tan(pi / s))
  return area


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to determine if the sum of the divisors of two integers are the same.

Tests:
assert are_equivalent(36, 57) == False
assert are_equivalent(2, 4) == False
assert are_equivalent(23, 47) == True

import math
def div_sum(n):
  total = 1
  i = 2

  while i * i <= n:
    if (n % i == 0):
      total = (total + i + math.floor(n / i))
    i += 1

  return total

def are_equivalent(num1, num2):
    return div_sum(num1) == div_sum(num2);


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to count the number of characters in a string that occur at the same position in the string as in the English alphabet (case insensitive).

Tests:
assert count_char_position("xbcefg") == 2
assert count_char_position("ABcED") == 3
assert count_char_position("AbgdeF") == 5

def count_char_position(str1):
    count_chars = 0
    for i in range(len(str1)):
        if ((i == ord(str1[i]) - ord('A')) or
            (i == ord(str1[i]) - ord('a'))):
            count_chars += 1
    return count_chars


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that counts the number of pairs of integers in a list that xor to an even number.

Tests:
assert find_even_pair([5, 4, 7, 2, 1]) == 4
assert find_even_pair([7, 2, 8, 1, 0, 5, 11]) == 9
assert find_even_pair([1, 2, 3]) == 1

def find_even_pair(A):
  count = 0
  for i in range(0, len(A)):
    for j in range(i+1, len(A)):
        if ((A[i] ^ A[j]) % 2 == 0):
          count += 1

  return count


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the smallest power of 2 greater than or equal to n.

Tests:
assert next_power_of_2(0) == 1
assert next_power_of_2(5) == 8
assert next_power_of_2(17) == 32

def next_power_of_2(n):
  if n and not n & (n - 1):
    return n

  count = 0
  while n != 0:
    n >>= 1
    count += 1

  return 1 << count;


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to count the number of occurrences of a number in a given list.

Tests:
assert frequency([1,2,3], 4) == 0
assert frequency([1,2,2,3,3,3,4], 3) == 3
assert frequency([0,1,2,3,1,2], 1) == 2

def frequency(a,x):
    count = 0
    for i in a:
      if i == x:
        count += 1

    return count


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the sum of numbers in a list within a range specified by two indices.

Tests:
assert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 8, 10) == 29
assert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 5, 7) == 16
assert sum_range_list([2,1,5,6,8,3,4,9,10,11,8,12], 7, 10) == 38

def sum_range_list(list1, m, n):
    sum_range = 0
    for i in range(m, n+1, 1):
        sum_range += list1[i]
    return sum_range


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the perimeter of a regular pentagon from the length of its sides.

Tests:
assert perimeter_pentagon(5) == 25
assert perimeter_pentagon(10) == 50
assert perimeter_pentagon(15) == 75

import math
def perimeter_pentagon(a):
  perimeter=(5*a)
  return perimeter


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to count the number of occurence of the string 'std' in a given string.

Tests:
assert count_occurance("letstdlenstdporstd") == 3
assert count_occurance("truststdsolensporsd") == 1
assert count_occurance("makestdsostdworthit") == 2
assert count_occurance("stds") == 1
assert count_occurance("") == 0

def count_occurance(s):
  count = 0
  for i in range(len(s) - 2):
    if (s[i] == 's' and s[i+1] == 't' and s[i+2] == 'd'):
      count = count + 1
  return count


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to check if all the elements in tuple have same data type or not.

Tests:
assert check_type((5, 6, 7, 3, 5, 6) ) == True
assert check_type((1, 2, "4") ) == False
assert check_type((3, 2, 1, 4, 5) ) == True

def check_type(test_tuple):
  res = True
  for ele in test_tuple:
    if not isinstance(ele, type(test_tuple[0])):
      res = False
      break
  return (res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in a sorted array, its length (n), and an element and returns whether the element is the majority element in the given sorted array. (The majority element is the element that occurs more than n/2 times.)

Tests:
assert is_majority([1, 2, 3, 3, 3, 3, 10], 7, 3) == True
assert is_majority([1, 1, 2, 4, 4, 4, 6, 6], 8, 4) == False
assert is_majority([1, 1, 1, 2, 2], 5, 1) == True
assert is_majority([1, 1, 2, 2], 5, 1) == False

def is_majority(arr, n, x):
	i = binary_search(arr, 0, n-1, x)
	if i == -1:
		return False
	if ((i + n//2) <= (n -1)) and arr[i + n//2] == x:
		return True
	else:
		return False
def binary_search(arr, low, high, x):
	if high >= low:
		mid = (low + high)//2
		if (mid == 0 or x > arr[mid-1]) and (arr[mid] == x):
			return mid
		elif x > arr[mid]:
			return binary_search(arr, (mid + 1), high, x)
		else:
			return binary_search(arr, low, (mid -1), x)
	return -1


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to count the number of set bits (binary digits with value 1) in a given number.

Tests:
assert count_Set_Bits(2) == 1
assert count_Set_Bits(4) == 1
assert count_Set_Bits(6) == 2

def count_Set_Bits(n):
    count = 0
    while (n):
        count += n & 1
        n >>= 1
    return count


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to remove the characters which have odd index values of a given string.

Tests:
assert odd_values_string('abcdef') == 'ace'
assert odd_values_string('python') == 'pto'
assert odd_values_string('data') == 'dt'
assert odd_values_string('lambs') == 'lms'

def odd_values_string(str):
  result = ""
  for i in range(len(str)):
    if i % 2 == 0:
      result = result + str[i]
  return result


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find minimum of three numbers.

Tests:
assert min_of_three(10,20,0)==0
assert min_of_three(19,15,18)==15
assert min_of_three(-10,-20,-30)==-30

def min_of_three(a,b,c):
      if (a <= b) and (a <= c):
        smallest = a
      elif (b <= a) and (b <= c):
        smallest = b
      else:
        smallest = c
      return smallest


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to check whether all the bits are unset in the given range or not.

Tests:
assert all_Bits_Set_In_The_Given_Range(4,1,2) == True
assert all_Bits_Set_In_The_Given_Range(17,2,4) == True
assert all_Bits_Set_In_The_Given_Range(39,4,6) == False

def all_Bits_Set_In_The_Given_Range(n,l,r):
    num = (((1 << r) - 1) ^ ((1 << (l - 1)) - 1))
    new_num = n & num
    if (new_num == 0):
        return True
    return False


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved.

Tests:
assert re_arrange_array([-1, 2, -3, 4, 5, 6, -7, 8, 9], 9) == [-1, -3, -7, 4, 5, 6, 2, 8, 9]
assert re_arrange_array([12, -14, -26, 13, 15], 5) == [-14, -26, 12, 13, 15]
assert re_arrange_array([10, 24, 36, -42, -39, -78, 85], 7) == [-42, -39, -78, 10, 24, 36, 85]

def re_arrange_array(arr, n):
  j=0
  for i in range(0, n):
    if (arr[i] < 0):
      temp = arr[i]
      arr[i] = arr[j]
      arr[j] = temp
      j = j + 1
  return arr


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string.

Tests:
assert replace_blank("hello people",'@')==("hello@people")
assert replace_blank("python program language",'$')==("python$program$language")
assert replace_blank("blank space","-")==("blank-space")

def replace_blank(str1,char):
 str2 = str1.replace(' ', char)
 return str2


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in a list and an integer n and returns a list containing the n largest items from the list.

Tests:
assert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2))==set([100,90])
assert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5))==set([100,90,80,70,60])
assert set(larg_nnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3))==set([100,90,80])

import heapq
def larg_nnum(list1,n):
 largest=heapq.nlargest(n,list1)
 return largest


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the lateral surface area of a cylinder.

Tests:
assert math.isclose(lateralsuface_cylinder(10,5), 314.15000000000003, rel_tol=0.001)
assert math.isclose(lateralsuface_cylinder(4,5), 125.66000000000001, rel_tol=0.001)
assert math.isclose(lateralsuface_cylinder(4,10), 251.32000000000002, rel_tol=0.001)

def lateralsuface_cylinder(r,h):
  lateralsurface= 2*3.1415*r*h
  return lateralsurface


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the volume of a cube given its side length.

Tests:
assert volume_cube(3)==27
assert volume_cube(2)==8
assert volume_cube(5)==125

def volume_cube(l):
  volume = l * l * l
  return volume


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to set all even bits of a given number.

Tests:
assert even_bit_set_number(10) == 10
assert even_bit_set_number(20) == 30
assert even_bit_set_number(30) == 30

def even_bit_set_number(n):
    count = 0;res = 0;temp = n
    while(temp > 0):
        if (count % 2 == 1):
            res |= (1 << count)
        count+=1
        temp >>= 1
    return (n | res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in a list of tuples and returns a dictionary mapping each unique tuple to the number of times it occurs in the list.

Tests:
assert check_occurences([(3, 1), (1, 3), (2, 5), (5, 2), (6, 3)] ) == {(1, 3): 2, (2, 5): 2, (3, 6): 1}
assert check_occurences([(4, 2), (2, 4), (3, 6), (6, 3), (7, 4)] ) == {(2, 4): 2, (3, 6): 2, (4, 7): 1}
assert check_occurences([(13, 2), (11, 23), (12, 25), (25, 12), (16, 23)] ) == {(2, 13): 1, (11, 23): 1, (12, 25): 2, (16, 23): 1}

from collections import Counter
def check_occurences(test_list):
  res = dict(Counter(tuple(ele) for ele in map(sorted, test_list)))
  return  (res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to count the number of non-empty substrings of a given string.

Tests:
assert number_of_substrings("abc") == 6
assert number_of_substrings("abcd") == 10
assert number_of_substrings("abcde") == 15

def number_of_substrings(str):
	str_len = len(str);
	return int(str_len * (str_len + 1) / 2);


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.

Tests:
assert get_total_number_of_sequences(10, 4) == 4
assert get_total_number_of_sequences(5, 2) == 6
assert get_total_number_of_sequences(16, 3) == 84

def get_total_number_of_sequences(m,n):
	T=[[0 for i in range(n+1)] for i in range(m+1)]
	for i in range(m+1):
		for j in range(n+1):
			if i==0 or j==0:
				T[i][j]=0
			elif i<j:
				T[i][j]=0
			elif j==1:
				T[i][j]=i
			else:
				T[i][j]=T[i-1][j]+T[i//2][j-1]
	return T[m][n]


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in two lists and replaces the last element of the first list with the elements of the second list.

Tests:
assert replace_list([1, 3, 5, 7, 9, 10],[2, 4, 6, 8])==[1, 3, 5, 7, 9, 2, 4, 6, 8]
assert replace_list([1,2,3,4,5],[5,6,7,8])==[1,2,3,4,5,6,7,8]
assert replace_list(["red","blue","green"],["yellow"])==["red","blue","yellow"]

def replace_list(list1,list2):
 list1[-1:] = list2
 replace_list=list1
 return replace_list


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to count the total number of characters in a string.

Tests:
assert count_charac("python programming")==18
assert count_charac("language")==8
assert count_charac("words")==5

def count_charac(str1):
 total = 0
 for i in str1:
    total = total + 1
 return total


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the next perfect square greater than a given number.

Tests:
assert next_Perfect_Square(35) == 36
assert next_Perfect_Square(6) == 9
assert next_Perfect_Square(9) == 16

import math
def next_Perfect_Square(N):
    nextN = math.floor(math.sqrt(N)) + 1
    return nextN * nextN


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.

Tests:
assert max_sum([1, 15, 51, 45, 33, 100, 12, 18, 9]) == 194
assert max_sum([80, 60, 30, 40, 20, 10]) == 210
assert max_sum([2, 3 ,14, 16, 21, 23, 29, 30]) == 138

def max_sum(arr):
	MSIBS = arr[:]
	for i in range(len(arr)):
		for j in range(0, i):
			if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
				MSIBS[i] = MSIBS[j] + arr[i]
	MSDBS = arr[:]
	for i in range(1, len(arr) + 1):
		for j in range(1, i):
			if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
				MSDBS[-i] = MSDBS[-j] + arr[-i]
	max_sum = float("-Inf")
	for i, j, k in zip(MSIBS, MSDBS, arr):
		max_sum = max(max_sum, i + j - k)
	return max_sum


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function for computing square roots using the babylonian method.

Tests:
assert math.isclose(babylonian_squareroot(10), 3.162277660168379, rel_tol=0.001)
assert math.isclose(babylonian_squareroot(2), 1.414213562373095, rel_tol=0.001)
assert math.isclose(babylonian_squareroot(9), 3.0, rel_tol=0.001)

def babylonian_squareroot(number):
    if(number == 0):
        return 0;
    g = number/2.0;
    g2 = g + 1;
    while(g != g2):
        n = number/ g;
        g2 = g;
        g = (g + n)/2;
    return g;


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the length of the longest palindromic subsequence in the given string.

Tests:
assert lps("TENS FOR TENS") == 5
assert lps("CARDIO FOR CARDS") == 7
assert lps("PART OF THE JOURNEY IS PART") == 9

def lps(str):
	n = len(str)
	L = [[0 for x in range(n)] for x in range(n)]
	for i in range(n):
		L[i][i] = 1
	for cl in range(2, n+1):
		for i in range(n-cl+1):
			j = i+cl-1
			if str[i] == str[j] and cl == 2:
				L[i][j] = 2
			elif str[i] == str[j]:
				L[i][j] = L[i+1][j-1] + 2
			else:
				L[i][j] = max(L[i][j-1], L[i+1][j]);
	return L[0][n-1]


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in an integer n and calculates the harmonic sum of n-1.

Tests:
assert math.isclose(harmonic_sum(7), 2.5928571428571425, rel_tol=0.001)
assert math.isclose(harmonic_sum(4), 2.083333333333333, rel_tol=0.001)
assert math.isclose(harmonic_sum(19), 3.547739657143682, rel_tol=0.001)

def harmonic_sum(n):
  if n < 2:
    return 1
  else:
    return 1 / n + (harmonic_sum(n - 1))


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the intersection of two arrays.

Tests:
assert intersection_array([1, 2, 3, 5, 7, 8, 9, 10],[1, 2, 4, 8, 9])==[1, 2, 8, 9]
assert intersection_array([1, 2, 3, 5, 7, 8, 9, 10],[3,5,7,9])==[3,5,7,9]
assert intersection_array([1, 2, 3, 5, 7, 8, 9, 10],[10,20,30,40])==[10]

def intersection_array(array_nums1,array_nums2):
 result = list(filter(lambda x: x in array_nums1, array_nums2))
 return result


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function that takes in a tuple and an element and counts the occcurences of the element in the tuple.

Tests:
assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),4) == 0
assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),10) == 3
assert count_X((10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),8) == 4

def count_X(tup, x):
    count = 0
    for ele in tup:
        if (ele == x):
            count = count + 1
    return count


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in a list and an element and inserts the element before each element in the list, and returns the resulting list.

Tests:
assert insert_element(['Red', 'Green', 'Black'] ,'c')==['c', 'Red', 'c', 'Green', 'c', 'Black']
assert insert_element(['python', 'java'] ,'program')==['program', 'python', 'program', 'java']
assert insert_element(['happy', 'sad'] ,'laugh')==['laugh', 'happy', 'laugh', 'sad']

def insert_element(list,element):
 list = [v for elt in list for v in (element, elt)]
 return list


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to convert complex numbers to polar coordinates.

Tests:
assert convert(1) == (1.0, 0.0)
assert convert(4) == (4.0,0.0)
assert convert(5) == (5.0,0.0)

import cmath
def convert(numbers):
  num = cmath.polar(numbers)
  return (num)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function that returns the number of integer elements in a given list.

Tests:
assert count_integer([1,2,'abc',1.2]) == 2
assert count_integer([1,2,3]) == 3
assert count_integer([1,1.2,4,5.1]) == 2

def count_integer(list1):
    ctr = 0
    for i in list1:
        if isinstance(i, int):
            ctr = ctr + 1
    return ctr


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in a list and length n, and generates all combinations (with repetition) of the elements of the list and returns a list with a tuple for each combination.

Tests:
assert combinations_colors( ["Red","Green","Blue"],1)==[('Red',), ('Green',), ('Blue',)]
assert combinations_colors( ["Red","Green","Blue"],2)==[('Red', 'Red'), ('Red', 'Green'), ('Red', 'Blue'), ('Green', 'Green'), ('Green', 'Blue'), ('Blue', 'Blue')]
assert combinations_colors( ["Red","Green","Blue"],3)==[('Red', 'Red', 'Red'), ('Red', 'Red', 'Green'), ('Red', 'Red', 'Blue'), ('Red', 'Green', 'Green'), ('Red', 'Green', 'Blue'), ('Red', 'Blue', 'Blue'), ('Green', 'Green', 'Green'), ('Green', 'Green', 'Blue'), ('Green', 'Blue', 'Blue'), ('Blue', 'Blue', 'Blue')]

from itertools import combinations_with_replacement
def combinations_colors(l, n):
    return list(combinations_with_replacement(l,n))


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function that takes in a non-negative number and returns the number of prime numbers less than the given non-negative number.

Tests:
assert count_Primes_nums(5) == 2
assert count_Primes_nums(10) == 4
assert count_Primes_nums(100) == 25

def count_Primes_nums(n):
    ctr = 0
    for num in range(n):
        if num <= 1:
            continue
        for i in range(2,num):
            if (num % i) == 0:
                break
        else:
            ctr += 1
    return ctr


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in two numbers and returns a tuple with the second number and then the first number.

Tests:
assert swap_numbers(10,20)==(20,10)
assert swap_numbers(15,17)==(17,15)
assert swap_numbers(100,200)==(200,100)

def swap_numbers(a,b):
 temp = a
 a = b
 b = temp
 return (a,b)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to maximize the given two tuples.

Tests:
assert maximize_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((6, 7), (4, 9), (2, 9), (7, 10))
assert maximize_elements(((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))) == ((7, 8), (5, 10), (3, 10), (8, 11))
assert maximize_elements(((3, 5), (6, 7), (4, 11), (3, 12)), ((8, 9), (5, 11), (3, 3), (9, 5))) == ((8, 9), (6, 11), (4, 11), (9, 12))

def maximize_elements(test_tup1, test_tup2):
  res = tuple(tuple(max(a, b) for a, b in zip(tup1, tup2))
   for tup1, tup2 in zip(test_tup1, test_tup2))
  return (res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the nth newman–shanks–williams prime number.

Tests:
assert newman_prime(3) == 7
assert newman_prime(4) == 17
assert newman_prime(5) == 41

def newman_prime(n):
	if n == 0 or n == 1:
		return 1
	return 2 * newman_prime(n - 1) + newman_prime(n - 2)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in two tuples and performs mathematical division operation element-wise across the given tuples.

Tests:
assert division_elements((10, 4, 6, 9),(5, 2, 3, 3)) == (2, 2, 2, 3)
assert division_elements((12, 6, 8, 16),(6, 3, 4, 4)) == (2, 2, 2, 4)
assert division_elements((20, 14, 36, 18),(5, 7, 6, 9)) == (4, 2, 6, 2)

def division_elements(test_tup1, test_tup2):
  res = tuple(ele1 // ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
  return (res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in a list and an integer L and splits the given list into two parts where the length of the first part of the list is L, and returns the resulting lists in a tuple.

Tests:
assert split_two_parts([1,1,2,3,4,4,5,1],3)==([1, 1, 2], [3, 4, 4, 5, 1])
assert split_two_parts(['a', 'b', 'c', 'd'],2)==(['a', 'b'], ['c', 'd'])
assert split_two_parts(['p', 'y', 't', 'h', 'o', 'n'],4)==(['p', 'y', 't', 'h'], ['o', 'n'])

def split_two_parts(list1, L):
    return list1[:L], list1[L:]


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to calculate a dog's age in dog's years.

Tests:
assert dog_age(12)==61
assert dog_age(15)==73
assert dog_age(24)==109

def dog_age(h_age):
 if h_age < 0:
 	exit()
 elif h_age <= 2:
	 d_age = h_age * 10.5
 else:
	 d_age = 21 + (h_age - 2)*4
 return d_age


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in a list and an integer n and splits a list for every nth element, returning a list of the resulting lists.

Tests:
assert list_split(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'],3)==[['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']]
assert list_split([1,2,3,4,5,6,7,8,9,10,11,12,13,14],3)==[[1,4,7,10,13], [2,5,8,11,14], [3,6,9,12]]
assert list_split(['python','java','C','C++','DBMS','SQL'],2)==[['python', 'C', 'DBMS'], ['java', 'C++', 'SQL']]

def list_split(S, step):
    return [S[i::step] for i in range(step)]


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the lateral surface area of a cube given its side length.

Tests:
assert lateralsurface_cube(5)==100
assert lateralsurface_cube(9)==324
assert lateralsurface_cube(10)==400

def lateralsurface_cube(l):
  LSA = 4 * (l * l)
  return LSA


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function that takes in an integer n and returns the sum of the squares of the first n odd natural numbers.

Tests:
assert square_Sum(2) == 10
assert square_Sum(3) == 35
assert square_Sum(4) == 84

def square_Sum(n):
    return int(n*(4*n*n-1)/3)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the n'th star number.

Tests:
assert find_star_num(3) == 37
assert find_star_num(4) == 73
assert find_star_num(5) == 121

def find_star_num(n):
	return (6 * n * (n - 1) + 1)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the ascii value of a character.

Tests:
assert ascii_value('A')==65
assert ascii_value('R')==82
assert ascii_value('S')==83

def ascii_value(k):
  ch=k
  return ord(ch)

def ascii_value(k):
  ch=k
  return ord(ch)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the sum of even numbers at even positions of a list.

Tests:
assert sum_even_and_even_index([5, 6, 12, 1, 18, 8]) == 30
assert sum_even_and_even_index([3, 20, 17, 9, 2, 10, 18, 13, 6, 18]) == 26
assert sum_even_and_even_index([5, 6, 12, 1]) == 12

def sum_even_and_even_index(arr):
    i = 0
    sum = 0
    for i in range(0, len(arr),2):
        if (arr[i] % 2 == 0) :
            sum += arr[i]
    return sum


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function that takes in an integer n and finds the sum of the first n even natural numbers that are raised to the fifth power.

Tests:
assert even_Power_Sum(2) == 1056
assert even_Power_Sum(3) == 8832
assert even_Power_Sum(1) == 32

def even_Power_Sum(n):
    sum = 0;
    for i in range(1,n+1):
        j = 2*i;
        sum = sum + (j*j*j*j*j);
    return sum;


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in a list of tuples and returns a list containing the rear element of each tuple.

Tests:
assert rear_extract([(1, 'Rash', 21), (2, 'Varsha', 20), (3, 'Kil', 19)]) == [21, 20, 19]
assert rear_extract([(1, 'Sai', 36), (2, 'Ayesha', 25), (3, 'Salman', 45)]) == [36, 25, 45]
assert rear_extract([(1, 'Sudeep', 14), (2, 'Vandana', 36), (3, 'Dawood', 56)]) == [14, 36, 56]

def rear_extract(test_list):
  res = [lis[-1] for lis in test_list]
  return (res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in two tuples and subtracts the elements of the first tuple by the elements of the second tuple with the same index.

Tests:
assert substract_elements((10, 4, 5), (2, 5, 18)) == (8, -1, -13)
assert substract_elements((11, 2, 3), (24, 45 ,16)) == (-13, -43, -13)
assert substract_elements((7, 18, 9), (10, 11, 12)) == (-3, 7, -3)

def substract_elements(test_tup1, test_tup2):
  res = tuple(map(lambda i, j: i - j, test_tup1, test_tup2))
  return (res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function that takes in a positive integer n and finds the sum of even index binomial coefficients.

Tests:
assert even_binomial_Coeff_Sum(4) == 8
assert even_binomial_Coeff_Sum(6) == 32
assert even_binomial_Coeff_Sum(2) == 2

import math
def even_binomial_Coeff_Sum( n):
    return (1 << (n - 1))


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in the radius and height of a cylinder and returns the the volume.

Tests:
assert math.isclose(volume_cylinder(10,5), 1570.7500000000002, rel_tol=0.001)
assert math.isclose(volume_cylinder(4,5), 251.32000000000002, rel_tol=0.001)
assert math.isclose(volume_cylinder(4,10), 502.64000000000004, rel_tol=0.001)

def volume_cylinder(r,h):
  volume=3.1415*r*r*h
  return volume


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in a dictionary and integer n and filters the dictionary to only include entries with values greater than or equal to n.

Tests:
assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},170)=={'Cierra Vega': 175, 'Alden Cantrell': 180, 'Pierre Cox': 190}
assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},180)=={ 'Alden Cantrell': 180, 'Pierre Cox': 190}
assert dict_filter({'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190},190)=={ 'Pierre Cox': 190}

def dict_filter(dict,n):
 result = {key:value for (key, value) in dict.items() if value >=n}
 return result


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the number of elements that occurs before the tuple element in the given tuple.

Tests:
assert count_first_elements((1, 5, 7, (4, 6), 10) ) == 3
assert count_first_elements((2, 9, (5, 7), 11) ) == 2
assert count_first_elements((11, 15, 5, 8, (2, 3), 8) ) == 4

def count_first_elements(test_tup):
  for count, ele in enumerate(test_tup):
    if isinstance(ele, tuple):
      break
  return (count)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the nth decagonal number.

Tests:
assert is_num_decagonal(3) == 27
assert is_num_decagonal(7) == 175
assert is_num_decagonal(10) == 370

def is_num_decagonal(n):
	return 4 * n * n - 3 * n


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in an array and element and returns a tuple containing a boolean that indicates if the element is in the array and the index position of the element (or -1 if the element is not found).

Tests:
assert sequential_search([11,23,58,31,56,77,43,12,65,19],31) == (True, 3)
assert sequential_search([12, 32, 45, 62, 35, 47, 44, 61],61) == (True, 7)
assert sequential_search([9, 10, 17, 19, 22, 39, 48, 56],48) == (True, 6)

def sequential_search(dlist, item):
    pos = 0
    found = False
    while pos < len(dlist) and not found:
        if dlist[pos] == item:
            found = True
        else:
            pos = pos + 1
    return found, pos


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to check if the elements of a given list are unique or not.

Tests:
assert all_unique([1,2,3]) == True
assert all_unique([1,2,1,2]) == False
assert all_unique([1,2,3,4,5]) == True

def all_unique(test_list):
    if len(test_list) > len(set(test_list)):
        return False
    return True


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to subtract two lists element-wise.

Tests:
assert sub_list([1, 2, 3],[4,5,6])==[-3,-3,-3]
assert sub_list([1,2],[3,4])==[-2,-2]
assert sub_list([90,120],[50,70])==[40,50]

def sub_list(nums1,nums2):
  result = map(lambda x, y: x - y, nums1, nums2)
  return list(result)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function takes in an integer and check whether the frequency of each digit in the integer is less than or equal to the digit itself.

Tests:
assert validate(1234) == True
assert validate(51241) == False
assert validate(321) == True

def validate(n):
    for i in range(10):
        temp = n;
        count = 0;
        while (temp):
            if (temp % 10 == i):
                count+=1;
            if (count > i):
                return False
            temp //= 10;
    return True


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that takes in a list and element and checks whether all items in the list are equal to the given element.

Tests:
assert check_element(["green", "orange", "black", "white"],'blue')==False
assert check_element([1,2,3,4],7)==False
assert check_element(["green", "green", "green", "green"],'green')==True

def check_element(list,element):
  check_element=all(v== element for v in list)
  return check_element


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function that checks whether a string contains the 'a' character followed by two or three 'b' characters.

Tests:
assert text_match_two_three("ac")==(False)
assert text_match_two_three("dc")==(False)
assert text_match_two_three("abbbba")==(True)

import re
def text_match_two_three(text):
        patterns = 'ab{2,3}'
        if re.search(patterns,  text):
                return True
        else:
                return False


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the largest sum of a contiguous array in the modified array which is formed by repeating the given array k times.

Tests:
assert max_sub_array_sum_repeated([10, 20, -30, -1], 4, 3) == 30
assert max_sub_array_sum_repeated([-1, 10, 20], 3, 2) == 59
assert max_sub_array_sum_repeated([-1, -2, -3], 3, 3) == -1

def max_sub_array_sum_repeated(a, n, k):
	max_so_far = -2147483648
	max_ending_here = 0
	for i in range(n*k):
		max_ending_here = max_ending_here + a[i%n]
		if (max_so_far < max_ending_here):
			max_so_far = max_ending_here
		if (max_ending_here < 0):
			max_ending_here = 0
	return max_so_far


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function takes in an integer n and returns the sum of squares of first n even natural numbers.

Tests:
assert square_Sum(2) == 20
assert square_Sum(3) == 56
assert square_Sum(4) == 120

def square_Sum(n):
    return int(2*n*(n+1)*(2*n+1)/3)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the list of maximum length in a list of lists.

Tests:
assert max_length([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])
assert max_length([[1], [5, 7], [10, 12, 14,15]])==(4, [10, 12, 14,15])
assert max_length([[5], [15,20,25]])==(3, [15,20,25])

def max_length(list1):
    max_length = max(len(x) for x in  list1 )
    max_list = max((x) for x in   list1)
    return(max_length, max_list)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find out the number of ways of painting the fence such that at most 2 adjacent posts have the same color for the given fence with n posts and k colors.

Tests:
assert count_no_of_ways(2, 4) == 16
assert count_no_of_ways(3, 2) == 6
assert count_no_of_ways(4, 4) == 228

def count_no_of_ways(n, k):
	dp = [0] * (n + 1)
	total = k
	mod = 1000000007
	dp[1] = k
	dp[2] = k * k
	for i in range(3,n+1):
		dp[i] = ((k - 1) * (dp[i - 1] + dp[i - 2])) % mod
	return dp[n]


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find quotient of two numbers (rounded down to the nearest integer).

Tests:
assert find(10,3) == 3
assert find(4,2) == 2
assert find(20,5) == 4

def find(n,m):
    q = n//m
    return (q)

def find(n,m):
    q = n//m
    return (q)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the third side of a right angled triangle.

Tests:
assert otherside_rightangle(7,8)==10.63014581273465
assert otherside_rightangle(3,4)==5
assert otherside_rightangle(7,15)==16.55294535724685

import math
def otherside_rightangle(w,h):
  s=math.sqrt((w*w)+(h*h))
  return s


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the maximum value in a given heterogeneous list.

Tests:
assert max_val(['Python', 3, 2, 4, 5, 'version'])==5
assert max_val(['Python', 15, 20, 25])==25
assert max_val(['Python', 30, 20, 40, 50, 'version'])==50

def max_val(listval):
     max_val = max(i for i in listval if isinstance(i, int))
     return(max_val)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to return the sum of all divisors of a number.

Tests:
assert sum_div(8)==7
assert sum_div(12)==16
assert sum_div(7)==1

def sum_div(number):
    divisors = [1]
    for i in range(2, number):
        if (number % i)==0:
            divisors.append(i)
    return sum(divisors)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to count inversions in an array.

Tests:
assert get_Inv_Count([1,20,6,4,5]) == 5
assert get_Inv_Count([1,2,1]) == 1
assert get_Inv_Count([1,2,5,6,1]) == 3

def get_Inv_Count(arr):
    inv_count = 0
    for i in range(len(arr)):
        for j in range(i + 1, len(arr)):
            if (arr[i] > arr[j]):
                inv_count += 1
    return inv_count


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to flatten a given nested list structure.

Tests:
assert flatten_list([0, 10, [20, 30], 40, 50, [60, 70, 80], [90, 100, 110, 120]])==[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]
assert flatten_list([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])==[10, 20, 40, 30, 56, 25, 10, 20, 33, 40]
assert flatten_list([[1,2,3], [4,5,6], [10,11,12], [7,8,9]])==[1, 2, 3, 4, 5, 6, 10, 11, 12, 7, 8, 9]

def flatten_list(list1):
    result_list = []
    if not list1: return result_list
    stack = [list(list1)]
    while stack:
        c_num = stack.pop()
        next = c_num.pop()
        if c_num: stack.append(c_num)
        if isinstance(next, list):
            if next: stack.append(list(next))
        else: result_list.append(next)
    result_list.reverse()
    return result_list


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to calculate the maximum aggregate from the list of tuples.

Tests:
assert max_aggregate([('Juan Whelan',90),('Sabah Colley',88),('Peter Nichols',7),('Juan Whelan',122),('Sabah Colley',84)])==('Juan Whelan', 212)
assert max_aggregate([('Juan Whelan',50),('Sabah Colley',48),('Peter Nichols',37),('Juan Whelan',22),('Sabah Colley',14)])==('Juan Whelan', 72)
assert max_aggregate([('Juan Whelan',10),('Sabah Colley',20),('Peter Nichols',30),('Juan Whelan',40),('Sabah Colley',50)])==('Sabah Colley', 70)

from collections import defaultdict
def max_aggregate(stdata):
    temp = defaultdict(int)
    for name, marks in stdata:
        temp[name] += marks
    return max(temp.items(), key=lambda x: x[1])


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the count of all binary sequences of length 2n such that sum of first n bits is same as sum of last n bits.

Tests:
assert math.isclose(count_binary_seq(1), 2.0, rel_tol=0.001)
assert math.isclose(count_binary_seq(2), 6.0, rel_tol=0.001)
assert math.isclose(count_binary_seq(3), 20.0, rel_tol=0.001)

def count_binary_seq(n):
	nCr = 1
	res = 1
	for r in range(1, n + 1):
		nCr = (nCr * (n + 1 - r)) / r
		res += nCr * nCr
	return res


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the depth of a dictionary.

Tests:
assert dict_depth({'a':1, 'b': {'c': {'d': {}}}})==4
assert dict_depth({'a':1, 'b': {'c':'python'}})==2
assert dict_depth({1: 'Sun', 2: {3: {4:'Mon'}}})==3

def dict_depth(d):
    if isinstance(d, dict):
        return 1 + (max(map(dict_depth, d.values())) if d else 0)
    return 0


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find element at a given index after number of rotations.

Tests:
assert find_Element([1,2,3,4,5],[[0,2],[0,3]],2,1) == 3
assert find_Element([1,2,3,4],[[0,1],[0,2]],1,2) == 3
assert find_Element([1,2,3,4,5,6],[[0,1],[0,2]],1,1) == 1

def find_Element(arr,ranges,rotations,index) :
    for i in range(rotations - 1,-1,-1 ) :
        left = ranges[i][0]
        right = ranges[i][1]
        if (left <= index and right >= index) :
            if (index == left) :
                index = right
            else :
                index = index - 1
    return arr[index]


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to return two words from a list of words starting with letter 'p'.

Tests:
assert start_withp(["Python PHP", "Java JavaScript", "c c++"])==('Python', 'PHP')
assert start_withp(["Python Programming","Java Programming"])==('Python','Programming')
assert start_withp(["Pqrst Pqr","qrstuv"])==('Pqrst','Pqr')

import re
def start_withp(words):
 for w in words:
        m = re.match("(P\w+)\W(P\w+)", w)
        if m:
            return m.groups()


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the maximum sum of increasing subsequence from prefix until ith index and also including a given kth element which is after i, i.e., k > i .

Tests:
assert max_sum_increasing_subseq([1, 101, 2, 3, 100, 4, 5 ], 7, 4, 6) == 11
assert max_sum_increasing_subseq([1, 101, 2, 3, 100, 4, 5 ], 7, 2, 5) == 7
assert max_sum_increasing_subseq([11, 15, 19, 21, 26, 28, 31], 7, 2, 4) == 71

def max_sum_increasing_subseq(a, n, index, k):
	dp = [[0 for i in range(n)]
			for i in range(n)]
	for i in range(n):
		if a[i] > a[0]:
			dp[0][i] = a[i] + a[0]
		else:
			dp[0][i] = a[i]
	for i in range(1, n):
		for j in range(n):
			if a[j] > a[i] and j > i:
				if dp[i - 1][i] + a[j] > dp[i - 1][j]:
					dp[i][j] = dp[i - 1][i] + a[j]
				else:
					dp[i][j] = dp[i - 1][j]
			else:
				dp[i][j] = dp[i - 1][j]
	return dp[index][k]


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to get a colon of a tuple.

Tests:
assert colon_tuplex(("HELLO", 5, [], True) ,2,50)==("HELLO", 5, [50], True)
assert colon_tuplex(("HELLO", 5, [], True) ,2,100)==(("HELLO", 5, [100],True))
assert colon_tuplex(("HELLO", 5, [], True) ,2,500)==("HELLO", 5, [500], True)

from copy import deepcopy
def colon_tuplex(tuplex,m,n):
  tuplex_colon = deepcopy(tuplex)
  tuplex_colon[m].append(n)
  return tuplex_colon


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the specified number of largest products from two given lists, selecting one factor from each list.

Tests:
assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],3)==[60, 54, 50]
assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],4)==[60, 54, 50, 48]
assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],5)==[60, 54, 50, 48, 45]

def large_product(nums1, nums2, N):
    result = sorted([x*y for x in nums1 for y in nums2], reverse=True)[:N]
    return result


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the maximum of two numbers.

Tests:
assert maximum(5,10) == 10
assert maximum(-1,-2) == -1
assert maximum(9,7) == 9

def maximum(a,b):
    if a >= b:
        return a
    else:
        return b


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to convert a given string to a tuple of characters.

Tests:
assert string_to_tuple("python 3.0")==('p', 'y', 't', 'h', 'o', 'n', '3', '.', '0')
assert string_to_tuple("item1")==('i', 't', 'e', 'm', '1')
assert string_to_tuple("15.10")==('1', '5', '.', '1', '0')

def string_to_tuple(str1):
    result = tuple(x for x in str1 if not x.isspace())
    return result


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to set the left most unset bit.

Tests:
assert set_left_most_unset_bit(10) == 14
assert set_left_most_unset_bit(12) == 14
assert set_left_most_unset_bit(15) == 15

def set_left_most_unset_bit(n):
    if not (n & (n + 1)):
        return n
    pos, temp, count = 0, n, 0
    while temp:
        if not (temp & 1):
            pos = count
        count += 1; temp>>=1
    return (n | (1 << (pos)))


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the volume of a cone.

Tests:
assert math.isclose(volume_cone(5,12), 314.15926535897927, rel_tol=0.001)
assert math.isclose(volume_cone(10,15), 1570.7963267948965, rel_tol=0.001)
assert math.isclose(volume_cone(19,17), 6426.651371693521, rel_tol=0.001)

import math
def volume_cone(r,h):
  volume = (1.0/3) * math.pi * r * r * h
  return volume


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the highest power of 2 that is less than or equal to n.

Tests:
assert highest_Power_of_2(10) == 8
assert highest_Power_of_2(19) == 16
assert highest_Power_of_2(32) == 32

def highest_Power_of_2(n):
    res = 0
    for i in range(n, 0, -1):
        if ((i & (i - 1)) == 0):
            res = i
            break
    return res


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the n'th lucas number.

Tests:
assert find_lucas(9) == 76
assert find_lucas(4) == 7
assert find_lucas(3) == 4

def find_lucas(n):
	if (n == 0):
		return 2
	if (n == 1):
		return 1
	return find_lucas(n - 1) + find_lucas(n - 2)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to apply a given format string to all of the elements in a list.

Tests:
assert add_string([1,2,3,4],'temp{0}')==['temp1', 'temp2', 'temp3', 'temp4']
assert add_string(['a','b','c','d'], 'python{0}')==[ 'pythona', 'pythonb', 'pythonc', 'pythond']
assert add_string([5,6,7,8],'string{0}')==['string5', 'string6', 'string7', 'string8']

def add_string(list_, string):
 add_string=[string.format(i) for i in  list_]
 return add_string


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to convert more than one list to nested dictionary.

Tests:
assert convert_list_dictionary(["S001", "S002", "S003", "S004"],["Adina Park", "Leyton Marsh", "Duncan Boyle", "Saim Richards"] ,[85, 98, 89, 92])==[{'S001': {'Adina Park': 85}}, {'S002': {'Leyton Marsh': 98}}, {'S003': {'Duncan Boyle': 89}}, {'S004': {'Saim Richards': 92}}]
assert convert_list_dictionary(["abc","def","ghi","jkl"],["python","program","language","programs"],[100,200,300,400])==[{'abc':{'python':100}},{'def':{'program':200}},{'ghi':{'language':300}},{'jkl':{'programs':400}}]
assert convert_list_dictionary(["A1","A2","A3","A4"],["java","C","C++","DBMS"],[10,20,30,40])==[{'A1':{'java':10}},{'A2':{'C':20}},{'A3':{'C++':30}},{'A4':{'DBMS':40}}]

def convert_list_dictionary(l1, l2, l3):
     result = [{x: {y: z}} for (x, y, z) in zip(l1, l2, l3)]
     return result


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the maximum sum possible by using the given equation f(n) = max( (f(n/2) + f(n/3) + f(n/4) + f(n/5)), n).

Tests:
assert get_max_sum(60) == 106
assert get_max_sum(10) == 12
assert get_max_sum(2) == 2

def get_max_sum (n):
	res = list()
	res.append(0)
	res.append(1)
	i = 2
	while i<n + 1:
		res.append(max(i, (res[int(i / 2)]
						+ res[int(i / 3)] +
							res[int(i / 4)]
						+ res[int(i / 5)])))
		i = i + 1
	return res[n]


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the list with maximum length.

Tests:
assert max_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])
assert max_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(5,[1,2,3,4,5])
assert max_length_list([[3,4,5],[6,7,8,9],[10,11,12]])==(4,[6,7,8,9])

def max_length_list(input_list):
    max_length = max(len(x) for x in input_list )
    max_list = max(input_list, key = lambda i: len(i))
    return(max_length, max_list)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to check if given tuple contains no duplicates.

Tests:
assert check_distinct((1, 4, 5, 6, 1, 4)) == False
assert check_distinct((1, 4, 5, 6)) == True
assert check_distinct((2, 3, 4, 5, 6)) == True

def check_distinct(test_tup):
  res = True
  temp = set()
  for ele in test_tup:
    if ele in temp:
      res = False
      break
    temp.add(ele)
  return res


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the first non-repeated character in a given string.

Tests:
assert first_non_repeating_character("abcabc") == None
assert first_non_repeating_character("abc") == "a"
assert first_non_repeating_character("ababc") == "c"

def first_non_repeating_character(str1):
  char_order = []
  ctr = {}
  for c in str1:
    if c in ctr:
      ctr[c] += 1
    else:
      ctr[c] = 1
      char_order.append(c)
  for c in char_order:
    if ctr[c] == 1:
      return c
  return None


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to check whether the given string starts and ends with the same character or not.

Tests:
assert check_char("abba") == "Valid"
assert check_char("a") == "Valid"
assert check_char("abcd") == "Invalid"

import re
regex = r'^[a-z]$|^([a-z]).*\1$'
def check_char(string):
	if(re.search(regex, string)):
		return "Valid"
	else:
		return "Invalid"


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the median of three numbers.

Tests:
assert median_numbers(25,55,65)==55.0
assert median_numbers(20,10,30)==20.0
assert median_numbers(15,45,75)==45.0

def median_numbers(a,b,c):
 if a > b:
    if a < c:
        median = a
    elif b > c:
        median = b
    else:
        median = c
 else:
    if a > c:
        median = a
    elif b < c:
        median = b
    else:
        median = c
 return median


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to compute the sum of digits of each number of a given list.

Tests:
assert sum_of_digits([10,2,56])==14
assert sum_of_digits([[10,20,4,5,'b',70,'a']])==19
assert sum_of_digits([10,20,-4,5,-70])==19

def sum_of_digits(nums):
    return sum(int(el) for n in nums for el in str(n) if el.isdigit())


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to perform the mathematical bitwise xor operation across the given tuples.

Tests:
assert bitwise_xor((10, 4, 6, 9), (5, 2, 3, 3)) == (15, 6, 5, 10)
assert bitwise_xor((11, 5, 7, 10), (6, 3, 4, 4)) == (13, 6, 3, 14)
assert bitwise_xor((12, 6, 8, 11), (7, 4, 5, 6)) == (11, 2, 13, 13)

def bitwise_xor(test_tup1, test_tup2):
  res = tuple(ele1 ^ ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
  return (res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to extract the number of unique tuples in the given list.

Tests:
assert extract_freq([(3, 4), (1, 2), (4, 3), (5, 6)] ) == 3
assert extract_freq([(4, 15), (2, 3), (5, 4), (6, 7)] ) == 4
assert extract_freq([(5, 16), (2, 3), (6, 5), (6, 9)] ) == 4

def extract_freq(test_list):
  res = len(list(set(tuple(sorted(sub)) for sub in test_list)))
  return (res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to perform index wise addition of tuple elements in the given two nested tuples.

Tests:
assert add_nested_tuples(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((7, 10), (7, 14), (3, 10), (8, 13))
assert add_nested_tuples(((2, 4), (5, 6), (3, 10), (2, 11)), ((7, 8), (4, 10), (2, 2), (8, 4))) == ((9, 12), (9, 16), (5, 12), (10, 15))
assert add_nested_tuples(((3, 5), (6, 7), (4, 11), (3, 12)), ((8, 9), (5, 11), (3, 3), (9, 5))) == ((11, 14), (11, 18), (7, 14), (12, 17))

def add_nested_tuples(test_tup1, test_tup2):
  res = tuple(tuple(a + b for a, b in zip(tup1, tup2))
   for tup1, tup2 in zip(test_tup1, test_tup2))
  return (res)


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find the minimum of two numbers.

Tests:
assert minimum(1,2) == 1
assert minimum(-5,-4) == -5
assert minimum(0,0) == 0

def minimum(a,b):
    if a <= b:
        return a
    else:
        return b


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to check whether an element exists within a tuple.

Tests:
assert check_tuplex(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),'r')==True
assert check_tuplex(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),'5')==False
assert check_tuplex(("w", 3, "r", "e", "s", "o", "u", "r", "c","e"),3)==True

def check_tuplex(tuplex,tuple1):
  if tuple1 in tuplex:
    return True
  else:
     return False


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a python function to find whether the parity of a given number is odd.

Tests:
assert find_Parity(12) == False
assert find_Parity(7) == True
assert find_Parity(10) == False

def find_Parity(x):
    y = x ^ (x >> 1);
    y = y ^ (y >> 2);
    y = y ^ (y >> 4);
    y = y ^ (y >> 8);
    y = y ^ (y >> 16);
    if (y & 1):
        return True
    return False


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to create the next bigger number by rearranging the digits of a given number.

Tests:
assert rearrange_bigger(12)==21
assert rearrange_bigger(10)==False
assert rearrange_bigger(102)==120

def rearrange_bigger(n):
    nums = list(str(n))
    for i in range(len(nums)-2,-1,-1):
        if nums[i] < nums[i+1]:
            z = nums[i:]
            y = min(filter(lambda x: x > z[0], z))
            z.remove(y)
            z.sort()
            nums[i:] = [y] + z
            return int("".join(nums))
    return False


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find k number of smallest pairs which consist of one element from the first array and one element from the second array.

Tests:
assert k_smallest_pairs([1,3,7],[2,4,6],2)==[[1, 2], [1, 4]]
assert k_smallest_pairs([1,3,7],[2,4,6],1)==[[1, 2]]
assert k_smallest_pairs([1,3,7],[2,4,6],7)==[[1, 2], [1, 4], [3, 2], [1, 6], [3, 4], [3, 6], [7, 2]]

import heapq
def k_smallest_pairs(nums1, nums2, k):
   queue = []
   def push(i, j):
       if i < len(nums1) and j < len(nums2):
           heapq.heappush(queue, [nums1[i] + nums2[j], i, j])
   push(0, 0)
   pairs = []
   while queue and len(pairs) < k:
       _, i, j = heapq.heappop(queue)
       pairs.append([nums1[i], nums2[j]])
       push(i, j + 1)
       if j == 0:
           push(i + 1, 0)
   return pairs


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the minimum product from the pairs of tuples within a given list.

Tests:
assert min_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==8
assert min_product_tuple([(10,20), (15,2), (5,10)] )==30
assert min_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==100

def min_product_tuple(list1):
    result_min = min([abs(x * y) for x, y in list1] )
    return result_min


Question:
Write a Python function that satisfies the following description. Return only the function definition(s); the function name and signature must match the tests below.

Description:
Write a function to find the minimum value in a given heterogeneous list.

Tests:
assert min_val(['Python', 3, 2, 4, 5, 'version'])==2
assert min_val(['Python', 15, 20, 25])==15
assert min_val(['Python', 30, 20, 40, 50, 'version'])==20

def min_val(listval):
     min_val = min(i for i in listval if isinstance(i, int))
     return min_val