Write Python code for the following task and make the tests pass.

Write a function to check whether it follows the sequence given in the patterns array.

cat > solution.py <<'PY'

def is_samepatterns(colors, patterns):
    if len(colors) != len(patterns):
        return False
    pattern_color_dict = {pattern: set() for pattern in patterns}
    for color, pattern in zip(colors, patterns):
        pattern_color_dict[pattern].add(color)
    return all(len(pattern_color_dict[pattern]) == 1 for pattern in patterns)

PY


Write Python code for the following task and make the tests pass.

Write a function to find tuples which have all elements divisible by k from the given list of tuples.

git init -q && git config user.email polar@test && git config user.name Polar && git add -A && git commit -qm initial

cat > solution.py <<'PY'

def find_tuples(test_list, K):
  res = [sub for sub in test_list if all(ele % K == 0 for ele in sub)]
  return res

PY


Write Python code for the following task and make the tests pass.

Write a python function to find whether a number is divisible by 11.

cat > solution.py <<'PY'

def is_Diff(n):
    return n % 11 == 0

PY


Write Python code for the following task and make the tests pass.

Write a python function to check whether the length of the word is odd or not.

cat > solution.py <<'PY'

def word_len(s):
    return len(s) % 2 == 1

PY


Write Python code for the following task and make the tests pass.

Write a function to find the nth tetrahedral number.

cat > solution.py <<'PY'

def tetrahedral_number(n):
	return (n * (n + 1) * (n + 2)) / 6

PY


Write Python code for the following task and make the tests pass.

Write a function to find the volume of a sphere.

cat > solution.py <<'PY'

import math
def volume_sphere(r):
  return (4./3.) * math.pi * (r**3)

PY


Write Python code for the following task and make the tests pass.

Write a function to find the nth number in the newman conway sequence.

cat > solution.py <<'PY'

def sequence(n):
	if n == 1 or n == 2:
		return 1
	seq = [0] * (n + 1)
	seq[1] = seq[2] = 1
	for i in range(3, n + 1):
		seq[i] = seq[seq[i - 1]] + seq[i - seq[i - 1]]
	return seq[n]

PY


Write Python code for the following task and make the tests pass.

Write a function to find the surface area of a sphere.

cat > solution.py <<'PY'

import math
def surfacearea_sphere(r):
  return 4 * math.pi * (r**2)

PY


Write Python code for the following task and make the tests pass.

Write a function to find nth centered hexagonal number.

cat > solution.py <<'PY'

def centered_hexagonal_number(n):
  return 3 * n * (n - 1) + 1

PY


Write Python code for the following task and make the tests pass.

Write a function to merge three dictionaries into a single dictionary.

cat > solution.py <<'PY'

import collections as ct
def merge_dictionaries_three(dict1,dict2, dict3):
    merged_dict = dict(ct.ChainMap({},dict1,dict2,dict3))
    return merged_dict

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def closest_num(N):
  return (N - 1)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def len_log(list1):
    return max(len(x) for x in list1)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def is_undulating(n):
	digits = [int(digit) for digit in str(n)]
	if len(set(digits)) != 2:
		return False
	return all(a != b for a, b in zip(digits, digits[1:]))

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def power(a, b):
	return a ** b

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def divisor(n):
  return sum(1 for i in range(1, n + 1) if n % i == 0)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def frequency_lists(list1):
    list1 = [item for sublist in list1 for item in sublist]
    return {x: list1.count(x) for x in list1}

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def multiply_num(numbers):
    from functools import reduce
    return reduce(lambda x, y: x * y, numbers) / len(numbers)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def next_smallest_palindrome(num):
    if all(digit == '9' for digit in str(num)):
        return num + 2
    else:
        num = [int(digit) for digit in str(num)]
        n = len(num)
        mid = n // 2
        left_smaller = False
        # if n is odd, ignore the middle digit at first
        i = mid - 1
        j = mid + 1 if n % 2 else mid
        while i >= 0 and num[i] == num[j]:
            i -= 1
            j += 1
        # stop if traverse end or difference found
        if i < 0 or num[i] < num[j]:
            left_smaller = True
        # copy left to right
        while i >= 0:
            num[j] = num[i]
            j += 1
            i -= 1
        # the middle digit must be incremented
        if left_smaller:
            carry = 1
            i = mid - 1
            if n % 2:
                num[mid] += carry
                carry = num[mid] // 10
                num[mid] %= 10
                j = mid + 1
            else:
                j = mid
            while i >= 0:
                num[i] += carry
                carry = num[i] // 10
                num[i] %= 10
                num[j] = num[i]
                j += 1
                i -= 1
    return int("".join(map(str, num)))

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def kth_element(arr, k):
  return arr[k-1]

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def sort_sublists(input_list):
    return [sorted(x) for x in input_list]

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def count(lst):
    return sum(lst)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def add_lists(test_list, test_tup):
  return test_tup + tuple(test_list)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

import heapq
def merge_sorted_list(num1,num2,num3):
  return sorted(num1 + num2 + num3)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def check_integer(text):
 text = text.strip()
 if len(text) < 1:
    return None
 else:
    if text[0] in '+-':
        text = text[1:]
    return text.isdigit()

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def string_to_list(string):
    return string.split(" ")

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def max_product_tuple(list1):
    return max(abs(x * y) for x, y in list1)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def div_sum(num):
    res = 1
    i = 2
    while i * i <= num:
        if num % i == 0:
            res += i
            if i * i != num:
                res += num / i
        i += 1
    return res
def amicable_numbers_sum(limit):
    amicables = set()
    for num in range(2, limit + 1):
        if num in amicables:
            continue
        sum_fact = div_sum(num)
        sum_fact2 = div_sum(sum_fact)
        if num == sum_fact2 and num != sum_fact:
            amicables.add(num)
            amicables.add(sum_fact2)
    return sum(amicables)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

def find_length(string):
	current_sum = 0
	max_sum = 0
	for c in string:
		current_sum += 1 if c == '0' else -1
		if current_sum < 0:
			current_sum = 0
		max_sum = max(current_sum, max_sum)
	return max_sum

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

import math
def sum(a,b):
    sum = 0
    n = math.gcd(a, b)
    N = int(math.sqrt(n)) + 1
    for i in range (1, N):
        if (n % i == 0):
            sum += i
            if (n / i != i):
                sum += (n / i)
    return sum

PY


Write Python code for the following task and make the tests pass.

Write a function to multiply two integers.

cat > solution.py <<'PY'

def multiply_int(x, y):
    return x * y

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def long_words(n, s):
    return list(filter(lambda x: len(x) > n, s.split(' ')))

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def magic_square_test(my_matrix):
    s = sum(my_matrix[0])
    # row
    if any(sum(row) != s for row in my_matrix):
        return False
    # column
    if any(sum(row[i] for row in my_matrix) != s for i in range(len(my_matrix[0]))):
        return False
    # diagonal
    if sum(my_matrix[i][i] for i in range(len(my_matrix))) != s:
        return False
    # anti-diagonal
    if sum(my_matrix[i][len(my_matrix) - i - 1] for i in range(len(my_matrix))) != s:
        return False
    return True

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

from collections import defaultdict
def max_occurrences(nums):
    d = defaultdict(int)
    for n in nums:
        d[n] += 1
    return max(d, key=d.get)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def reverse_vowels(str1):
	is_vowel = lambda x: x in 'aeiouAEIOU'
	pos = [i for i, c in enumerate(str1) if is_vowel(c)]
	return ''.join(c if not is_vowel(c) else str1[pos.pop()] for c in str1)

PY


Write Python code for the following task and make the tests pass.

Write a function to convert a tuple to a string.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def sum_negativenum(nums):
  return sum(x for x in nums if x < 0)

PY


Write Python code for the following task and make the tests pass.

Write a function to find the nth hexagonal number.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def zero_count(nums):
    if all(x == 0 for x in nums):
        return float('inf')
    return sum(x == 0 for x in nums) / sum(x != 0 for x in nums)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def is_Sum_Of_Powers_Of_Two(n):
    return n > 0 and n % 2 == 0

PY


Write Python code for the following task and make the tests pass.

Write a function to find the circumference of a circle.

cat > solution.py <<'PY'

import math
def circle_circumference(r):
  return 2 * math.pi * r

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def extract_singly(test_list):
  return set([item for sublist in test_list for item in sublist])

PY


Write Python code for the following task and make the tests pass.

Write a function to sort a list of elements.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def max_Abs_Diff(arr):
    return max(arr) - min(arr)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def sum_series(n):
  if n <= 0:
    return 0
  return sum(n - 2 * i for i in range(n // 2 + 1))

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def count_char_position(str1):
    return sum(ord(ch.lower()) - ord('a') == i for i, ch in enumerate(str1))

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def find_even_pair(A):
  if len(A) < 2:
    return 0
  return sum((a ^ b) % 2 == 0 for i, a in enumerate(A) for b in A[i + 1:])

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def next_power_of_2(n):
  if n and not n & (n - 1):
    return n
  res = 1
  while n != 0:
    n >>= 1
    res <<= 1
  return res;

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def frequency(a,x):
    return a.count(x)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def sum_range_list(list1, m, n):
    return sum(list1[m : n + 1])

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def perimeter_pentagon(a):
  return 5 * a

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def count_occurance(s):
  return s.count('std')

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def check_type(test_tuple):
    return all(isinstance(item, type(test_tuple[0])) for item in test_tuple)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

from bisect import bisect_left, bisect_right
def is_majority(arr, n, x):
	if x not in arr:
		return False
	l = bisect_left(arr, x)
	r = bisect_right(arr, x)
	return r - l > n / 2

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def count_Set_Bits(n):
    return bin(n)[2:].count('1')

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def odd_values_string(str1):
    return ''.join(str1[i] for i in range(0, len(str1), 2))

PY


Write Python code for the following task and make the tests pass.

Write a function to find minimum of three numbers.

cat > solution.py <<'PY'

def min_of_three(a,b,c):
  return min(a, b, c)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

import math
def lateralsuface_cylinder(r, h):
  return 2 * math.pi * r * h

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def volume_cube(l):
  return l ** 3

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def even_bit_set_number(n):
    mask = 2
    while mask < n:
        n |= mask
        mask <<= 2
    return n

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

from collections import Counter
def check_occurences(test_list):
  return dict(Counter(tuple(sorted(t)) for t in test_list))

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def number_of_substrings(str1):
	str_len = len(str1)
	return str_len * (str_len + 1) // 2

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

def get_total_number_of_sequences(m, n):
	T=[[0 for _ in range(n + 1)] for _ 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]

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def count_charac(str1):
    return len(str1)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def lps(str1):
	n = len(str1)
	dp = [[0] * n for _ in range(n)]
	for i in range(n - 1, -1, -1):
		dp[i][i] = 1
		for j in range(i + 1, n):
			if str1[i] == str1[j]:
				dp[i][j] = dp[i + 1][j - 1] + 2
			else:
				dp[i][j] = max(dp[i + 1][j], dp[i][j - 1])
	return dp[0][n - 1]

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def count_X(tup, x):
    return tup.count(x)

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def count_integer(list1):
    return sum(isinstance(x, int) for x in list1)

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

def count_Primes_nums(n):
    return sum(all(i % j != 0 for j in range(2, i)) for i in range(2, n))

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

Write a function to maximize the given two tuples.

cat > solution.py <<'PY'

def maximize_elements(test_tup1, test_tup2):
  return tuple((max(a, c), max(b, d)) for (a, b), (c, d) in zip(test_tup1, test_tup2))

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def newman_prime(n):
	if n == 0 or n == 1:
		return 1
	a = 1
	b = 1
	c = 1
	for _ in range(2, n + 1):
		c = 2 * b + a
		a = b
		b = c
	return c

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def ascii_value(k):
  return ord(k)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def sum_even_and_even_index(arr):
    return sum(x for x in arr[::2] if x % 2 == 0)

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

def even_Power_Sum(n):
    return sum(x ** 5 for x in range(2, 2 * n + 1, 2))

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def rear_extract(test_list):
  return [x[-1] for x in test_list]

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

def substract_elements(test_tup1, test_tup2):
  return tuple(x - y for x, y in zip(test_tup1, test_tup2))

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

import math
def volume_cylinder(r,h):
  return math.pi * r * r * h

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

Write a function to find the nth decagonal number.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def sequential_search(dlist, item):
    return item in dlist, (dlist.index(item) if item in dlist else -1)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def all_unique(test_list):
    return len(test_list) == len(set(test_list))

PY


Write Python code for the following task and make the tests pass.

Write a function to subtract two lists element-wise.

cat > solution.py <<'PY'

def sub_list(nums1,nums2):
  return [num1 - num2 for num1, num2 in zip(nums1, nums2)]

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

def validate(n):
    digits = [int(digit) for digit in str(n)]
    return all(digit >= digits.count(digit) for digit in digits)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

import re
def text_match_two_three(text):
    patterns = 'ab{2,3}'
    return re.search(patterns, text) is not None

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

def max_sub_array_sum_repeated(a, n, k):
	modifed = a * k
	pre = 0	# dp[i-1]
	res = modifed[0]
	for n in modifed:
		pre = max(pre + n, n)
		res = max(pre, res)
	return res

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def max_length(list1):
    return max([(len(x), x) for x in list1], key=lambda x: x[0])

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

Write a python function to count inversions in an array.

cat > solution.py <<'PY'

def get_Inv_Count(arr):
    # consider use merge sort, but for simplicity, use brute force
    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

PY


Write Python code for the following task and make the tests pass.

Write a function to flatten a given nested list structure.

cat > solution.py <<'PY'

def flatten_list(list1):
	result = []
	for item in list1:
		if isinstance(item, list):
			result.extend(flatten_list(item))
		else:
			result.append(item)
	return result

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

Write a function to find the depth of a dictionary.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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 .

cat > solution.py <<'PY'

def max_sum_increasing_subseq(a, n, index, k):
	dp = [[0 for _ in range(n)] for _ 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]

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def maximum(a,b):
    return max(a, b)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

Write a function to find the volume of a cone.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def highest_Power_of_2(n):
    i = 0
    while ((1 << i) <= n):
        i += 1
    return (1 << (i - 1))

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def get_max_sum (n):
	# if n = 0, f(0) = max(5(f(0), 0)), so f(0) = 5f(0) or f(0) = 0, for both cases f(0) = 0
	res = [0]
	for i in range(1, n + 1):
		res.append(max(res[i // 2] + res[i // 3] + res[i // 4] + res[i // 5], i))
	return res[n]

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def check_distinct(test_tup):
  return len(test_tup) == len(set(test_tup))

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def first_non_repeating_character(str1):
  for ch in str1:
    if str1.count(ch) == 1:
      return ch
  return None

PY


Write Python code for the following task and make the tests pass.

Write a function to find the median of three numbers.

cat > solution.py <<'PY'

def median_numbers(a,b,c):
    return sorted([a,b,c])[1]

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def minimum(a,b):
    return min(a,b)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def check_tuplex(tuplex, element):
  return element in tuplex

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def find_Parity(x):
    return x % 2 != 0

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def min_product_tuple(list1):
    return min(x * y for x, y in list1)

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

Write a python function to remove odd numbers from a given list.

cat > solution.py <<'PY'

def remove_odd(l):
    return [i for i in l if i % 2 == 0]

PY


Write Python code for the following task and make the tests pass.

Write a function to extract the nth element from a given list of tuples.

cat > solution.py <<'PY'

def extract_nth_element(list1, n):
    return [x[n] for x in list1]

PY


Write Python code for the following task and make the tests pass.

Write a python function to check whether any value in a sequence exists in a sequence or not.

cat > solution.py <<'PY'

def overlapping(list1,list2):
    return any(v in list2 for v in list1)

PY


Write Python code for the following task and make the tests pass.

Write a python function to find a pair with highest product from a given array of integers.

cat > solution.py <<'PY'

def max_Product(arr):
    pairs = [(a, b) for a in arr for b in arr if a != b]
    return max(pairs, key=lambda x: x[0] * x[1])

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the element of a list having maximum length.

cat > solution.py <<'PY'

def Find_Max(lst):
    return max(lst, key = len)

PY


Write Python code for the following task and make the tests pass.

Write a function to round every number of a given list of numbers and print the total sum multiplied by the length of the list.

cat > solution.py <<'PY'

def round_and_sum(list1):
  l = len(list1)
  return sum([round(i) for i in list1]) * l

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the cube sum of first n even natural numbers.

cat > solution.py <<'PY'

def cube_Sum(n):
    return 2 * (n ** 2) * ((n + 1) ** 2)

PY


Write Python code for the following task and make the tests pass.

Write a function to concatenate each element of tuple by the delimiter.

cat > solution.py <<'PY'

def concatenate_tuple(test_tup):
    delim = "-"
    res = ''.join([str(ele) + delim for ele in test_tup])
    res = res[ : len(res) - len(delim)]
    return (str(res))

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the average of cubes of first n natural numbers.

cat > solution.py <<'PY'

def find_Average_Of_Cube(n):
    return sum([(i ** 3) for i in range(1, n + 1)]) / n

PY


Write Python code for the following task and make the tests pass.

Write a function to extract only the rear index element of each string in the given tuple.

cat > solution.py <<'PY'

def extract_rear(test_tuple):
  return [ele[-1] for ele in test_tuple]

PY


Write Python code for the following task and make the tests pass.

Write a function to count the number of sublists containing a particular element.

cat > solution.py <<'PY'

def count_element_in_list(list1, x):
    return sum(x in sublist for sublist in list1)

PY


Write Python code for the following task and make the tests pass.

Write a function to filter odd numbers.

cat > solution.py <<'PY'

def filter_oddnumbers(nums):
    return [n for n in nums if n % 2 == 1]

PY


Write Python code for the following task and make the tests pass.

Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.

cat > solution.py <<'PY'

import re
def change_date_format(dt):
    return re.sub(r'(\d{4})-(\d{1,2})-(\d{1,2})', '\\3-\\2-\\1', dt)

PY


Write Python code for the following task and make the tests pass.

Write a function to sort the given array by using shell sort.

cat > solution.py <<'PY'

def shell_sort(my_list):
    gap = len(my_list) // 2
    while gap > 0:
        for i in range(gap, len(my_list)):
            current_item = my_list[i]
            j = i
            while j >= gap and my_list[j - gap] > current_item:
                my_list[j] = my_list[j - gap]
                j -= gap
            my_list[j] = current_item
        gap //= 2
    return my_list

PY


Write Python code for the following task and make the tests pass.

Write a function to extract the elementwise and tuples from the given two tuples.

cat > solution.py <<'PY'

def and_tuples(test_tup1, test_tup2):
  return tuple(x & y for x, y in zip(test_tup1, test_tup2))

PY


Write Python code for the following task and make the tests pass.

Write a function to find the directrix of a parabola.

cat > solution.py <<'PY'

def parabola_directrix(a, b, c):
  return ((int)(c - ((b * b) + 1) * 4 * a ))

PY


Write Python code for the following task and make the tests pass.

Write a function to find the median length of a trapezium.

cat > solution.py <<'PY'

def median_trapezium(base1,base2,height):
    return (base1 + base2) / 2

PY


Write Python code for the following task and make the tests pass.

Write a function to check whether the entered number is greater than the elements of the given array.

cat > solution.py <<'PY'

def check_greater(arr, number):
  return all(number > el for el in arr)

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the last digit of a given number.

cat > solution.py <<'PY'

def last_Digit(n) :
    if n < 0:
        n = -n
    return n % 10

PY


Write Python code for the following task and make the tests pass.

Write a python function to return the negative numbers in a list.

cat > solution.py <<'PY'

def neg_nos(list1):
  return [i for i in list1 if i < 0]

PY


Write Python code for the following task and make the tests pass.

Write a function to remove odd characters in a string.

cat > solution.py <<'PY'

def remove_odd(str1):
    return str1[1::2]

PY


Write Python code for the following task and make the tests pass.

Write a function to join a list of multiple integers into a single integer.

cat > solution.py <<'PY'

def multiple_to_single(L):
  return int(''.join(map(str,L)))

PY


Write Python code for the following task and make the tests pass.

Write a function to find the first adverb and their positions in a given sentence.

cat > solution.py <<'PY'

import re
def find_adverb_position(text):
    for m in re.finditer(r"\w+ly", text):
        return (m.start(), m.end(), m.group(0))

PY


Write Python code for the following task and make the tests pass.

Write a function to find the surface area of a cube of a given size.

cat > solution.py <<'PY'

def surfacearea_cube(l):
  return 6 * l * l

PY


Write Python code for the following task and make the tests pass.

Write a function to perform index wise multiplication of tuple elements in the given two tuples.

cat > solution.py <<'PY'

def index_multiplication(test_tup1, test_tup2):
  return tuple(tuple(a * b for a, b in zip(tup1, tup2))
   for tup1, tup2 in zip(test_tup1, test_tup2))

PY


Write Python code for the following task and make the tests pass.

Write a python function to count the occurence of all elements of list in a tuple.

cat > solution.py <<'PY'

from collections import Counter
def count_Occurrence(tup, lst):
    return sum(tup.count(ele) for ele in lst)

PY


Write Python code for the following task and make the tests pass.

Write a function to find cubes of individual elements in a list.

cat > solution.py <<'PY'

def cube_nums(nums):
    return [n**3 for n in nums]

PY


Write Python code for the following task and make the tests pass.

Write a function to calculate the sum of perrin numbers.

cat > solution.py <<'PY'

def cal_sum(n):
	a = 3
	b = 0
	c = 2
	if (n == 0):
		return 3
	if (n == 1):
		return 3
	if (n == 2):
		return 5
	sum = 5
	while (n > 2):
		d = a + b
		sum = sum + d
		a = b
		b = c
		c = d
		n = n - 1
	return sum

PY


Write Python code for the following task and make the tests pass.

Write a function to extract specified size of strings from a given list of string values.

cat > solution.py <<'PY'

def extract_string(str1, l):
    return [e for e in str1 if len(e) == l]

PY


Write Python code for the following task and make the tests pass.

Write a function to remove all whitespaces from the given string.

cat > solution.py <<'PY'

import re
def remove_whitespaces(text1):
  return text1.replace(' ', '')

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the sum of even factors of a number.

cat > solution.py <<'PY'

import math
def sumofFactors(n) :
    if (n % 2 != 0) :
        return 0
    return sum([i for i in range(2, n + 1) if n % i == 0 and i % 2 == 0])

PY


Write Python code for the following task and make the tests pass.

Write a function that matches a word containing 'z'.

cat > solution.py <<'PY'

import re
def text_match_wordz(text):
        return 'z' in text

PY


Write Python code for the following task and make the tests pass.

Write a function to check whether the given month number contains 31 days or not.

cat > solution.py <<'PY'

def check_monthnumb_number(monthnum2):
  return monthnum2 in [1, 3, 5, 7, 8, 10, 12]

PY


Write Python code for the following task and make the tests pass.

Write a function to reverse each string in a given list of string values.

cat > solution.py <<'PY'

def reverse_string_list(stringlist):
    return [x[::-1] for x in stringlist]

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the sublist having minimum length.

cat > solution.py <<'PY'

def Find_Min(lst):
    return min(lst, key=len)

PY


Write Python code for the following task and make the tests pass.

Write a function to find the area of a rectangle.

cat > solution.py <<'PY'

def rectangle_area(l,b):
  return l * b

PY


Write Python code for the following task and make the tests pass.

Write a function to remove uppercase substrings from a given string.

cat > solution.py <<'PY'

def remove_uppercase(str1):
  return ''.join(c for c in str1 if c.islower())

PY


Write Python code for the following task and make the tests pass.

Write a python function to get the first element of each sublist.

cat > solution.py <<'PY'

def Extract(lst):
    return [item[0] for item in lst]

PY


Write Python code for the following task and make the tests pass.

Write a function to find all possible combinations of the elements of a given list.

cat > solution.py <<'PY'

def combinations_list(list1):
    if len(list1) == 0:
        return [[]]
    result = []
    for el in combinations_list(list1[1:]):
        result += [el, el+[list1[0]]]
    return result

PY


Write Python code for the following task and make the tests pass.

Write a function to find the maximum product subarray of the given array.

cat > solution.py <<'PY'

def max_subarray_product(arr):
	max_so_far = min_ending = max_ending = arr[0]
	for n in arr[1:]:
		min_ending, max_ending = min(n, min_ending * n, max_ending * n), max(n, min_ending * n, max_ending * n)
		max_so_far = max(max_so_far, max_ending)
	return max_so_far

PY


Write Python code for the following task and make the tests pass.

Write a function to drop empty items from a given dictionary.

cat > solution.py <<'PY'

def drop_empty(dict1):
  dict1 = {key:value for (key, value) in dict1.items() if value is not None}
  return dict1

PY


Write Python code for the following task and make the tests pass.

Write a function to find the maximum product formed by multiplying numbers of an increasing subsequence of that array.

cat > solution.py <<'PY'

def max_product(arr):
  # record the correspond ending element to maintain the increasing subsequence
  ret = max_ending = min_ending = (arr[0], arr[0])
  for n in arr[1:]:
    if n > max_ending[1]:
      max_ending = max((max_ending[0] * n, n), max_ending, key=lambda x: x[0])
    else:
      max_ending = (n, n)
    if n > min_ending[1]:
      min_ending = min((min_ending[0] * n, n), min_ending, key=lambda x: x[0])
    else:
      min_ending = (n, n)
    ret = max(ret, max_ending, min_ending, key=lambda x: x[0])
  return ret[0]

PY


Write Python code for the following task and make the tests pass.

Write a function to find the pairwise addition of the neighboring elements of the given tuple.

cat > solution.py <<'PY'

def add_pairwise(test_tup):
  return tuple(a + b for a, b in zip(test_tup, test_tup[1:]))

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the product of the array multiplication modulo n.

cat > solution.py <<'PY'

def find_remainder(arr, n):
    from functools import reduce
    return reduce(lambda x, y: x * y, arr) % n

PY


Write Python code for the following task and make the tests pass.

Write a python function to check whether the given list contains consecutive numbers or not.

cat > solution.py <<'PY'

def check_Consecutive(l):
    return sorted(l) == list(range(min(l),max(l)+1))

PY


Write Python code for the following task and make the tests pass.

Write a function to find the tuple intersection of elements in the given tuple list irrespective of their order.

cat > solution.py <<'PY'

def tuple_intersection(test_list1, test_list2):
  return set([tuple(sorted(ele)) for ele in test_list1]) & set([tuple(sorted(ele)) for ele in test_list2])

PY


Write Python code for the following task and make the tests pass.

Write a function to replace characters in a string.

cat > solution.py <<'PY'

def replace_char(str1, ch, newch):
    return str1.replace(ch, newch)

PY


Write Python code for the following task and make the tests pass.

Write a function to sort a dictionary by value.

cat > solution.py <<'PY'

def sort_counter(dict1):
 return sorted(dict1.items(), key=lambda x: x[1], reverse=True)

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the sum of the largest and smallest value in a given array.

cat > solution.py <<'PY'

def big_sum(nums):
      return max(nums) + min(nums)

PY


Write Python code for the following task and make the tests pass.

Write a python function to convert the given string to lower case.

cat > solution.py <<'PY'

def is_lower(string):
    return string.lower()

PY


Write Python code for the following task and make the tests pass.

Write a function to remove lowercase substrings from a given string.

cat > solution.py <<'PY'

import re
def remove_lowercase(str1):
    return re.sub('[a-z]', '', str1)

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the first digit of a given number.

cat > solution.py <<'PY'

def first_Digit(n) :
    return int(str(n)[0])

PY


Write Python code for the following task and make the tests pass.

Write a python function which takes a list of integers and only returns the odd ones.

cat > solution.py <<'PY'

def Split(l):
    return list(filter(lambda x: x % 2 == 1, l))

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the difference between the sum of cubes of the first n natural numbers and the sum of the first n natural numbers.

cat > solution.py <<'PY'

def difference(n) :
    S = (n*(n + 1))//2;
    res = S*(S-1);
    return res;

PY


Write Python code for the following task and make the tests pass.

Write a python function to count the number of pairs whose xor value is odd.

cat > solution.py <<'PY'

def find_Odd_Pair(A,N) :
    oddPair = 0
    for i in range(0,N) :
        for j in range(i+1,N) :
            if ((A[i] ^ A[j]) % 2 != 0):
                oddPair+=1
    return oddPair

PY


Write Python code for the following task and make the tests pass.

Write a function to toggle the case of all characters in a string.

cat > solution.py <<'PY'

def toggle_string(string):
 return string.swapcase()

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the sum of the per-digit difference between two integers.

cat > solution.py <<'PY'

def digit_distance_nums(n1, n2):
    return sum([abs(int(c1) - int(c2)) for c1, c2 in zip(str(n1), str(n2))])

PY


Write Python code for the following task and make the tests pass.

Write a function to find the sum of the largest contiguous sublist in the given list.

cat > solution.py <<'PY'

def max_sub_array_sum(a, size):
  max_so_far = 0
  max_ending_here = 0
  for i in range(0, size):
    max_ending_here = max_ending_here + a[i]
    if max_ending_here < 0:
      max_ending_here = 0
    elif (max_so_far < max_ending_here):
      max_so_far = max_ending_here
  return max_so_far

PY


Write Python code for the following task and make the tests pass.

Write a function to find the union of the elements of two given tuples and output them in sorted order.

cat > solution.py <<'PY'

def union_elements(test_tup1, test_tup2):
  return tuple(sorted(set(test_tup1 + test_tup2)))

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the length of the longest sublists.

cat > solution.py <<'PY'

def Find_Max_Length(lst):
    return len(max(lst, key = len))

PY


Write Python code for the following task and make the tests pass.

Write a function to extract values between quotation marks from a string.

cat > solution.py <<'PY'

import re
def extract_values(text):
 return (re.findall(r'"(.*?)"', text))

PY


Write Python code for the following task and make the tests pass.

Write a python function which takes a list of integers and counts the number of possible unordered pairs where both elements are unequal.

cat > solution.py <<'PY'

def count_Pairs(arr,n):
    cnt = 0;
    for i in range(n):
        for j in range(i + 1,n):
            if (arr[i] != arr[j]):
                cnt += 1;
    return cnt;

PY


Write Python code for the following task and make the tests pass.

Write a python function to split a string into characters.

cat > solution.py <<'PY'

def split(word):
    return list(word)

PY


Write Python code for the following task and make the tests pass.

Write a function to get the sum of the digits of a non-negative integer.

cat > solution.py <<'PY'

def sum_digits(n):
  return sum(map(int, str(n)))

PY


Write Python code for the following task and make the tests pass.

Write a function to check whether a specified list is sorted or not.

cat > solution.py <<'PY'

def issort_list(list1):
    return all(a <= b for a, b in zip(list1, list1[1:]))

PY


Write Python code for the following task and make the tests pass.

Write a function to create a list of N empty dictionaries.

cat > solution.py <<'PY'

def empty_list(length):
 return [{} for _ in range(length)]

PY


Write Python code for the following task and make the tests pass.

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

cat > solution.py <<'PY'

def sort_sublists(list1):
    return list(map(sorted,list1))

PY


Write Python code for the following task and make the tests pass.

Write a python function to remove duplicate numbers from a given number of lists.

cat > solution.py <<'PY'

def two_unique_nums(nums):
  return [n for n in nums if nums.count(n)==1]

PY


Write Python code for the following task and make the tests pass.

Write a python function to calculate the product of the unique numbers in a given list.

cat > solution.py <<'PY'

def unique_product(list_data):
    from functools import reduce
    return reduce(lambda x, y: x*y, set(list_data))

PY


Write Python code for the following task and make the tests pass.

Write a python function to check whether a list is sublist of another or not.

cat > solution.py <<'PY'

def is_Sub_Array(A,B):
    a = 0
    b = 0
    while a < len(A) and b < len(B):
        if A[a] == B[b]:
            a += 1
            b += 1
        else:
            a += 1
    return b == len(B)

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the last digit in factorial of a given number.

cat > solution.py <<'PY'

def last_Digit_Factorial(n):
    if (n == 0):
      return 1
    elif (n <= 2):
      return n
    elif (n == 3):
      return 6
    elif (n == 4):
      return 4
    else:
      return 0

PY


Write Python code for the following task and make the tests pass.

Write a function to interleave 3 lists of the same length into a single flat list.

cat > solution.py <<'PY'

def interleave_lists(list1, list2, list3):
    return [el for pair in zip(list1, list2, list3) for el in pair]

PY


Write Python code for the following task and make the tests pass.

Write a function to find the dissimilar elements in the given two tuples.

cat > solution.py <<'PY'

def find_dissimilar(test_tup1, test_tup2):
  return tuple(set(test_tup1) ^ set(test_tup2))

PY


Write Python code for the following task and make the tests pass.

Write a function to remove uneven elements in the nested mixed tuple.

cat > solution.py <<'PY'

def even_ele(test_tuple, ):
	res = tuple()
	for ele in test_tuple:
		if isinstance(ele, tuple):
			res += (even_ele(ele), )
		elif ele % 2 == 0:
			res += (ele, )
	return res
def extract_even(test_tuple):
	return even_ele(test_tuple)

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the surface area of a square pyramid with a given base edge and height.

cat > solution.py <<'PY'

def surface_Area(b,s):
    return 2 * b * s + pow(b,2)

PY


Write Python code for the following task and make the tests pass.

Write a function which returns nth catalan number.

cat > solution.py <<'PY'

def catalan_number(num):
    if num <= 1:
         return 1
    res_num = 0
    for i in range(num):
        res_num += catalan_number(i) * catalan_number(num - i - 1)
    return res_num

PY


Write Python code for the following task and make the tests pass.

Write a function to find the n most expensive items in a given dataset.

cat > solution.py <<'PY'

import heapq
def expensive_items(items,n):
  expensive_items = heapq.nlargest(n, items, key=lambda s: s['price'])
  return expensive_items

PY


Write Python code for the following task and make the tests pass.

Write a python function to split a list at the nth eelment and add the first part to the end.

cat > solution.py <<'PY'

def split_Arr(l, n):
  return l[n:] + l[:n]

PY


Write Python code for the following task and make the tests pass.

Write a function to convert a list to a tuple.

cat > solution.py <<'PY'

def list_tuple(listx):
  return tuple(listx)

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the difference between largest and smallest value in a given list.

cat > solution.py <<'PY'

def big_diff(nums):
     return max(nums) - min(nums)

PY


Write Python code for the following task and make the tests pass.

Write a function to find perfect squares between two given numbers.

cat > solution.py <<'PY'

import math
def perfect_squares(a, b):
    if a > b:
        a, b = b, a
    if b < 0:
        return []
    if a < 0:
        a = 0
    return list(filter(lambda x: math.sqrt(x).is_integer(), range(a, b+1)))

PY


Write Python code for the following task and make the tests pass.

Write a function to convert polar coordinates to rectangular coordinates.

cat > solution.py <<'PY'

import cmath
def polar_rect(x,y):
    cn = cmath.polar(complex(x, y))
    cn1 = cmath.rect(2, cmath.pi)
    return (cn, cn1)

PY


Write Python code for the following task and make the tests pass.

Write a python function to interchange the first and last elements in a list.

cat > solution.py <<'PY'

def swap_List(newList):
    return newList[-1:] + newList[1:-1] + newList[:1]

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the sum of the product of consecutive binomial co-efficients.

cat > solution.py <<'PY'

def binomial_Coeff(n, k):
    C = [0] * (k + 1);
    C[0] = 1; # nC0 is 1
    for i in range(1,n + 1):
        for j in range(min(i, k),0,-1):
            C[j] = C[j] + C[j - 1];
    return C[k];
def sum_Of_product(n):
    return binomial_Coeff(2 * n, n - 1);

PY


Write Python code for the following task and make the tests pass.

Write a function to remove leading zeroes from an ip address.

cat > solution.py <<'PY'

import re
def removezero_ip(ip):
 return re.sub('\.[0]*', '.', ip)

PY


Write Python code for the following task and make the tests pass.

Write a function to find the difference of the first even and first odd number of a given list.

cat > solution.py <<'PY'

def diff_even_odd(list1):
    first_even = next((el for el in list1 if el%2==0), -1)
    first_odd = next((el for el in list1 if el%2!=0), -1)
    return (first_even - first_odd)

PY


Write Python code for the following task and make the tests pass.

Write a function to find the size in bytes of the given tuple.

cat > solution.py <<'PY'

import sys
def tuple_size(tuple_list):
  return sys.getsizeof(tuple_list)

PY


Write Python code for the following task and make the tests pass.

Write a function to find kth element from the given two sorted arrays.

cat > solution.py <<'PY'

def find_kth(arr1, arr2, k):
	return sorted(arr1 + arr2)[k - 1]

PY


Write Python code for the following task and make the tests pass.

Write a function to check whether the given number is armstrong or not.

cat > solution.py <<'PY'

def armstrong_number(number):
    order = len(str(number))
    return sum([int(i) ** order for i in str(number)]) == number

PY


Write Python code for the following task and make the tests pass.

Write a function to find sum and average of first n natural numbers.

cat > solution.py <<'PY'

def sum_average(number):
   sum_ = sum(range(1, number+1))
   average = sum_/number
   return sum_, average

PY


Write Python code for the following task and make the tests pass.

Write a python function to check whether the given number is even or not.

cat > solution.py <<'PY'

def is_Even(n) :
    return n % 2 == 0

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the first repeated character in a given string.

cat > solution.py <<'PY'

def first_repeated_char(str1):
  for index, c in enumerate(str1):
    if str1[:index + 1].count(c) > 1:
      return c
  return None

PY


Write Python code for the following task and make the tests pass.

Write a function to get all lucid numbers smaller than or equal to a given integer.

cat > solution.py <<'PY'

def get_ludic(n):
	ludics = []
	for i in range(1, n + 1):
		ludics.append(i)
	index = 1
	while(index != len(ludics)):
		first_ludic = ludics[index]
		remove_index = index + first_ludic
		while(remove_index < len(ludics)):
			ludics.remove(ludics[remove_index])
			remove_index = remove_index + first_ludic - 1
		index += 1
	return ludics

PY


Write Python code for the following task and make the tests pass.

Write a function to reverse words seperated by spaces in a given string.

cat > solution.py <<'PY'

def reverse_words(s):
	return ' '.join(reversed(s.split()))

PY


Write Python code for the following task and make the tests pass.

Write a function to check if the given integer is a prime number.

cat > solution.py <<'PY'

import math
def prime_num(num):
  if num <= 1:
    return False
  for i in range(2, int(math.sqrt(num)) + 1):
    if num % i == 0:
      return False
  return True

PY


Write Python code for the following task and make the tests pass.

Write a function to convert degrees to radians.

cat > solution.py <<'PY'

import math
def radian_degree(degree):
    return degree * math.pi / 180

PY


Write Python code for the following task and make the tests pass.

Write a function to search a string for a regex pattern. The function should return the matching subtring, a start index and an end index.

cat > solution.py <<'PY'

import re
def find_literals(text, pattern):
  match = re.search(pattern, text)
  if match is None:
    return None
  s = match.start()
  e = match.end()
  return (match.re.pattern, s, e)

PY


Write Python code for the following task and make the tests pass.

Write a python function to find nth bell number.

cat > solution.py <<'PY'

def bell_Number(n):
    bell = [[0 for i in range(n+1)] for j in range(n+1)]
    bell[0][0] = 1
    for i in range(1, n+1):
        bell[i][0] = bell[i-1][i-1]
        for j in range(1, i+1):
            bell[i][j] = bell[i-1][j-1] + bell[i][j-1]
    return bell[n][0]

PY


Write Python code for the following task and make the tests pass.

Write a python function which takes a list and returns a list with the same elements, but the k'th element removed.

cat > solution.py <<'PY'

def remove_kth_element(list1, k):
    return list1[:k-1] + list1[k:]

PY


Write Python code for the following task and make the tests pass.

Write a function which given a matrix represented as a list of lists returns the max of the n'th column.

cat > solution.py <<'PY'

def max_of_nth(test_list, N):
  return max([sub[N] for sub in test_list])

PY


Write Python code for the following task and make the tests pass.

Write a python function which takes a list of lists, where each sublist has two elements, and returns a list of two lists where the first list has the first element of each sublist and the second one has the second.

cat > solution.py <<'PY'

def merge(lst):
    return [list(ele) for ele in list(zip(*lst))]

PY


Write Python code for the following task and make the tests pass.

Write a function to find the cumulative sum of all the values that are present in the given tuple list.

cat > solution.py <<'PY'

def cummulative_sum(test_list):
  return sum(map(sum, test_list))

PY


Write Python code for the following task and make the tests pass.

Write a function which takes a tuple of tuples and returns the average value for each tuple as a list.

cat > solution.py <<'PY'

def average_tuple(nums):
    result = [sum(x) / len(x) for x in zip(*nums)]
    return result

PY


Write Python code for the following task and make the tests pass.

Write a function which takes two tuples of the same length and performs the element wise modulo.

cat > solution.py <<'PY'

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

PY


Write Python code for the following task and make the tests pass.

Write a function to divide two lists element wise.

cat > solution.py <<'PY'

def div_list(nums1,nums2):
  result = map(lambda x, y: x / y, nums1, nums2)
  return list(result)

PY


Write Python code for the following task and make the tests pass.

Write a function to move all the numbers to the end of the given string.

cat > solution.py <<'PY'

def move_num(test_str):
  num_str = ''.join(i for i in test_str if i.isdigit())
  else_str = ''.join(i for i in test_str if not i.isdigit())
  return else_str + num_str

PY


Write Python code for the following task and make the tests pass.

Write a function to find the size of the largest subset of a list of numbers so that every pair is divisible.

cat > solution.py <<'PY'

def largest_subset(a):
	n = len(a)
	dp = [0 for _ in range(n)]
	dp[n - 1] = 1;
	for i in range(n - 2, -1, -1):
		mxm = 0
		for j in range(i + 1, n):
			if a[j] % a[i] == 0 or a[i] % a[j] == 0:
				mxm = max(mxm, dp[j])
		dp[i] = 1 + mxm
	return max(dp)

PY


Write Python code for the following task and make the tests pass.

Write a function to find the median of two sorted lists of same size.

cat > solution.py <<'PY'

def get_median(arr1, arr2, n):
  i = 0
  j = 0
  m1 = -1
  m2 = -1
  count = 0
  while count < n + 1:
    count += 1
    if i == n:
      m1 = m2
      m2 = arr2[0]
      break
    elif j == n:
      m1 = m2
      m2 = arr1[0]
      break
    if arr1[i] <= arr2[j]:
      m1 = m2
      m2 = arr1[i]
      i += 1
    else:
      m1 = m2
      m2 = arr2[j]
      j += 1
  return (m1 + m2)/2

PY


Write Python code for the following task and make the tests pass.

Write a function to compute the n-th power of each number in a list.

cat > solution.py <<'PY'

def nth_nums(nums, n):
 nth_nums = list(map(lambda x: x ** n, nums))
 return nth_nums

PY


Write Python code for the following task and make the tests pass.

Write a python function to convert a given string to uppercase.

cat > solution.py <<'PY'

def is_upper(string):
  return string.upper()

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the area of the largest triangle that can be inscribed in a semicircle with a given radius.

cat > solution.py <<'PY'

def triangle_area(r) :
    if r < 0 :
        return None
    return r * r

PY


Write Python code for the following task and make the tests pass.

Write a function to replace all spaces in the given string with '%20'.

cat > solution.py <<'PY'

def replace_spaces(string):
  return string.replace(" ", "%20")

PY


Write Python code for the following task and make the tests pass.

Write a python function to find even numbers from a list of numbers.

cat > solution.py <<'PY'

def Split(l):
    return [num for num in l if num % 2 == 0]

PY


Write Python code for the following task and make the tests pass.

Write a function to extract all the adjacent coordinates of the given coordinate tuple.

cat > solution.py <<'PY'

def adjac(ele, sub = []):
  if not ele:
     yield sub
  else:
     yield from [idx for j in range(ele[0] - 1, ele[0] + 2)
                for idx in adjac(ele[1:], sub + [j])]
def get_coordinates(test_tup):
  return list(adjac(test_tup))

PY


Write Python code for the following task and make the tests pass.

Write a function to replace whitespaces with an underscore and vice versa in a given string.

cat > solution.py <<'PY'

def replace_spaces(text):
  return "".join(" " if c == "_" else ("_" if c == " " else c) for c in text)

PY


Write Python code for the following task and make the tests pass.

Write a python function to move all zeroes to the end of the given list.

cat > solution.py <<'PY'

def move_zero(num_list):
    zeros = [0] * num_list.count(0)
    front = [i for i in num_list if i != 0]
    return front + zeros

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the sum of xor of all pairs of numbers in the given list.

cat > solution.py <<'PY'

def pair_xor_Sum(arr,n) :
    ans = 0
    for i in range(0,n) :
        for j in range(i + 1,n) :
            ans = ans + (arr[i] ^ arr[j])
    return ans

PY


Write Python code for the following task and make the tests pass.

Write a function to sort the given list.

cat > solution.py <<'PY'

import heapq as hq
def heap_sort(iterable):
    hq.heapify(iterable)
    return [hq.heappop(iterable) for _ in range(len(iterable))]

PY


Write Python code for the following task and make the tests pass.

Write a function to check whether the given amount has no profit and no loss

cat > solution.py <<'PY'

def noprofit_noloss(actual_cost, sale_amount):
  return actual_cost == sale_amount

PY


Write Python code for the following task and make the tests pass.

Write a function to calculate the wind chill index rounded to the next integer given the wind velocity in km/h and a temperature in celsius.

cat > solution.py <<'PY'

import math
def wind_chill(v,t):
 windchill = 13.12 + 0.6215*t -  11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16)
 return int(round(windchill, 0))

PY


Write Python code for the following task and make the tests pass.

Write a function to sum the length of the names of a given list of names after removing the names that start with a lowercase letter.

cat > solution.py <<'PY'

def sample_nam(sample_names):
  sample_names=list(filter(lambda el:el[0].isupper() and el[1:].islower(),sample_names))
  return len(''.join(sample_names))

PY


Write Python code for the following task and make the tests pass.

Write a function to find the nth nonagonal number.

cat > solution.py <<'PY'

def is_nonagonal(n):
	return int(n * (7 * n - 5) / 2)

PY


Write Python code for the following task and make the tests pass.

Write a function that checks if a strings contains 'z', except at the start and end of the word.

cat > solution.py <<'PY'

import re
def text_match_wordz_middle(text):
	return re.search(r'\Bz\B',  text) is not None

PY


Write Python code for the following task and make the tests pass.

Write a python function to reverse an array upto a given position.

cat > solution.py <<'PY'

def reverse_Array_Upto_K(input, k):
  return input[k-1::-1] + input[k:]

PY


Write Python code for the following task and make the tests pass.

Write a function to add a dictionary to the tuple. The output should be a tuple.

cat > solution.py <<'PY'

def add_dict_to_tuple(test_tup, test_dict):
  return test_tup + (test_dict, )

PY


Write Python code for the following task and make the tests pass.

Given a square matrix of size N*N given as a list of lists, where each cell is associated with a specific cost. A path is defined as a specific sequence of cells that starts from the top-left cell move only right or down and ends on bottom right cell. We want to find a path with the maximum average over all existing paths. Average is computed as total cost divided by the number of cells visited in the path.

cat > solution.py <<'PY'

def maxAverageOfPath(cost):
  N = len(cost)
  dp = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
  dp[0][0] = cost[0][0]
  for i in range(1, N):
    dp[i][0] = dp[i - 1][0] + cost[i][0]
  for j in range(1, N):
    dp[0][j] = dp[0][j - 1] + cost[0][j]
  for i in range(1, N):
    for j in range(1, N):
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + cost[i][j]
  # all paths are of length 2 * N - 1, so just divide by that
  return dp[N - 1][N - 1] / (2 * N - 1)

PY


Write Python code for the following task and make the tests pass.

The input is given as - a dictionary with a student name as a key and a tuple of float (student_height, student_weight) as a value, - minimal height, - minimal weight. Write a function to filter students that have height and weight above the minimum.

cat > solution.py <<'PY'

def filter_data(students,h,w):
    return {k: s for k, s in students.items() if s[0] >= h and s[1] >= w}

PY


Write Python code for the following task and make the tests pass.

The input is defined as two lists of the same length. Write a function to count indices where the lists have the same values.

cat > solution.py <<'PY'

from operator import eq
def count_same_pair(nums1, nums2):
    result = sum(map(eq, nums1, nums2))
    return result

PY


Write Python code for the following task and make the tests pass.

Write a function that takes base and power as arguments and calculate the sum of all digits of the base to the specified power.

cat > solution.py <<'PY'

def power_base_sum(base, power):
    return sum([int(i) for i in str(pow(base, power))])

PY


Write Python code for the following task and make the tests pass.

Write a function to extract values between quotation marks " " of the given string.

cat > solution.py <<'PY'

import re
def extract_quotation(text1):
  return re.findall(r'"(.*?)"', text1)

PY


Write Python code for the following task and make the tests pass.

Write a function that takes as input a tuple of numbers (t_1,...,t_{N+1}) and returns a tuple of length N where the i-th element of the tuple is equal to t_i * t_{i+1}.

cat > solution.py <<'PY'

def multiply_elements(test_tup):
  return tuple(i * j for i, j in zip(test_tup, test_tup[1:]))

PY


Write Python code for the following task and make the tests pass.

Write a function takes as input two lists [a_1,...,a_n], [b_1,...,b_n] and returns [a_1+b_1,...,a_n+b_n].

cat > solution.py <<'PY'

def sum_list(lst1,lst2):
  return [a + b for a, b in zip(lst1, lst2)]

PY


Write Python code for the following task and make the tests pass.

Write a function to remove consecutive duplicates of a given list.

cat > solution.py <<'PY'

from itertools import groupby
def consecutive_duplicates(nums):
    return [key for key, _ in groupby(nums)]

PY


Write Python code for the following task and make the tests pass.

Write a function to find the lateral surface area of a cone given radius r and the height h.

cat > solution.py <<'PY'

import math
def lateralsurface_cone(r,h):
  l = math.sqrt(r * r + h * h)
  return math.pi * r  * l

PY


Write Python code for the following task and make the tests pass.

Write a function to replace all occurrences of spaces, commas, or dots with a colon.

cat > solution.py <<'PY'

import re
def replace_specialchar(text):
 return re.sub("[ ,.]", ":", text)

PY


Write Python code for the following task and make the tests pass.

Write a function to find the index of the first occurrence of a given number in a sorted array.

cat > solution.py <<'PY'

def find_first_occurrence(A, x):
    (left, right) = (0, len(A) - 1)
    result = -1
    while left <= right:
        mid = (left + right) // 2
        if x == A[mid]:
            result = mid
            right = mid - 1
        elif x < A[mid]:
            right = mid - 1
        else:
            left = mid + 1
    return result

PY


Write Python code for the following task and make the tests pass.

Write a python function to find sum of products of all possible sublists of a given list. https://www.geeksforgeeks.org/sum-of-products-of-all-possible-subarrays/

cat > solution.py <<'PY'

def sum_Of_Subarray_Prod(arr):
    result = 0  # final result
    partial = 0 # partial sum
    # stimulate the recursion
    while arr != []:
        partial = arr[-1] * (1 + partial)
        result += partial
        arr.pop()
    return result

PY


Write Python code for the following task and make the tests pass.

Write a python function to toggle bits of the number except the first and the last bit. https://www.geeksforgeeks.org/toggle-bits-number-expect-first-last-bits/

cat > solution.py <<'PY'

def toggle_middle_bits(n):
    binary = bin(n)[2:]
    toggled = ''.join(['0' if i == '1' else '1' for i in binary[1:-1]])
    return int(binary[0] + toggled + binary[-1], 2)

PY


Write Python code for the following task and make the tests pass.

Write a function to locate the left insertion point for a specified value in sorted order. https://www.w3resource.com/python-exercises/data-structures-and-algorithms/python-data-structure-exercise-24.php

cat > solution.py <<'PY'

import bisect
def left_insertion(a, x):
    return bisect.bisect_left(a, x)

PY


Write Python code for the following task and make the tests pass.

Write a function to check whether the given string is starting with a vowel or not using regex.

cat > solution.py <<'PY'

import re
def check_str(string):
	regex = '^[aeiouAEIOU][A-Za-z0-9_]*'
	return re.search(regex, string)

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the index of smallest triangular number with n digits. https://www.geeksforgeeks.org/index-of-smallest-triangular-number-with-n-digits/

cat > solution.py <<'PY'

import math
def find_Index(n):
    x = math.sqrt(2 * math.pow(10,(n - 1)))
    return round(x)

PY


Write Python code for the following task and make the tests pass.

Write a function to convert the given tuple to a key-value dictionary using adjacent elements. https://www.geeksforgeeks.org/python-convert-tuple-to-adjacent-pair-dictionary/

cat > solution.py <<'PY'

def tuple_to_dict(test_tup):
  return dict(test_tup[idx : idx + 2] for idx in range(0, len(test_tup), 2))

PY


Write Python code for the following task and make the tests pass.

Write a python function to check whether all the characters are same or not.

cat > solution.py <<'PY'

def all_Characters_Same(s) :
    return all(ch == s[0] for ch in s[1:])

PY


Write Python code for the following task and make the tests pass.

Write a function to caluclate the area of a tetrahedron.

cat > solution.py <<'PY'

import math
def area_tetrahedron(side):
  return math.sqrt(3)*(side*side)

PY


Write Python code for the following task and make the tests pass.

Write a function to rotate a given list by specified number of items to the right direction. https://www.geeksforgeeks.org/python-program-right-rotate-list-n/

cat > solution.py <<'PY'

def rotate_right(l, m):
  return l[-m:] + l[:-m]

PY


Write Python code for the following task and make the tests pass.

Write a function to check if the given tuple has any none value or not.

cat > solution.py <<'PY'

def check_none(test_tup):
  return any(ele is None for ele in test_tup)

PY


Write Python code for the following task and make the tests pass.

Write a function to find numbers within a given range from startnum ti endnum where every number is divisible by every digit it contains. https://www.w3resource.com/python-exercises/lambda/python-lambda-exercise-24.php

cat > solution.py <<'PY'

def divisible_by_digits(startnum, endnum):
    return [n for n in range(startnum, endnum+1) \
                if not any(map(lambda x: int(x) == 0 or n%int(x) != 0, str(n)))]

PY


Write Python code for the following task and make the tests pass.

Write a function to put spaces between words starting with capital letters in a given string.

cat > solution.py <<'PY'

import re
def capital_words_spaces(str1):
  return re.sub(r"(\w)([A-Z])", r"\1 \2", str1)

PY


Write Python code for the following task and make the tests pass.

Write a function to sort a given list of strings of numbers numerically. https://www.geeksforgeeks.org/python-sort-numeric-strings-in-a-list/

cat > solution.py <<'PY'

def sort_numeric_strings(nums_str):
    return sorted([int(x) for x in nums_str])

PY


Write Python code for the following task and make the tests pass.

Write a function to add the given tuple to the given list.

cat > solution.py <<'PY'

def add_tuple(test_list, test_tup):
  return test_list + list(test_tup)

PY


Write Python code for the following task and make the tests pass.

Write a function to check if the given array represents min heap or not. https://www.geeksforgeeks.org/how-to-check-if-a-given-array-represents-a-binary-heap/

cat > solution.py <<'PY'

def check_min_heap_helper(arr, i):
    if 2 * i + 2 > len(arr):
      return True
    left_child = (arr[i] <= arr[2 * i + 1]) and check_min_heap_helper(arr, 2 * i + 1)
    right_child = (2 * i + 2 == len(arr)) or  \
                (arr[i] <= arr[2 * i + 2] and \
                 check_min_heap_helper(arr, 2 * i + 2))
    return left_child and right_child
def check_min_heap(arr):
  return check_min_heap_helper(arr, 0)

PY


Write Python code for the following task and make the tests pass.

Write a function to find the nth jacobsthal number. https://www.geeksforgeeks.org/jacobsthal-and-jacobsthal-lucas-numbers/ 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341, 683, 1365, 2731, ...

cat > solution.py <<'PY'

def jacobsthal_num(n):
	dp = [0] * (n + 1)
	dp[0] = 0
	dp[1] = 1
	for i in range(2, n+1):
		dp[i] = dp[i - 1] + 2 * dp[i - 2]
	return dp[n]

PY


Write Python code for the following task and make the tests pass.

Write a function to find minimum k records from tuple list. https://www.geeksforgeeks.org/python-find-minimum-k-records-from-tuple-list/ - in this case a verbatim copy of test cases

cat > solution.py <<'PY'

def min_k(test_list, K):
  res = sorted(test_list, key = lambda x: x[1])[:K]
  return (res)

PY


Write Python code for the following task and make the tests pass.

We say that an element is common for lists l1, l2, l3 if it appears in all three lists under the same index. Write a function to find common elements from three lists. The function should return a list.

cat > solution.py <<'PY'

def extract_index_list(l1, l2, l3):
    return [a for a, b, c in zip(l1, l2, l3) if a == b == c]

PY


Write Python code for the following task and make the tests pass.

Write a function to find the second smallest number in a list.

cat > solution.py <<'PY'

def second_smallest(numbers):
  sorted_set = sorted(set(numbers))
  if len(sorted_set) < 2:
    return None
  return sorted_set[1]

PY


Write Python code for the following task and make the tests pass.

Write a function to count the pairs of reverse strings in the given string list. https://www.geeksforgeeks.org/python-program-to-count-the-pairs-of-reverse-strings/

cat > solution.py <<'PY'

def count_reverse_pairs(test_list):
  return sum(test_list[i+1:].count(s[::-1]) for i, s in enumerate(test_list))

PY


Write Python code for the following task and make the tests pass.

Write a function to count lists within a list. The function should return a dictionary where every list is converted to a tuple and the value of such tuple is the number of its occurencies in the original list.

cat > solution.py <<'PY'

def unique_sublists(list1):
    return {tuple(x): list1.count(x) for x in list1}

PY


Write Python code for the following task and make the tests pass.

Write a function to check whether a given string is a decimal number with a precision of 2.

cat > solution.py <<'PY'

def is_decimal(num):
    import re
    dnumre = re.compile(r"""^[0-9]+(\.[0-9]{1,2})?$""")
    return dnumre.search(num) is not None

PY


Write Python code for the following task and make the tests pass.

Write a python function to check whether a list of numbers contains only one distinct element or not.

cat > solution.py <<'PY'

def unique_Element(arr):
    return arr.count(arr[0]) == len(arr)

PY


Write Python code for the following task and make the tests pass.

Write a function to check whether the given month number contains 30 days or not. Months are given as number from 1 to 12.

cat > solution.py <<'PY'

def check_monthnumber_number(monthnum3):
  return monthnum3==4 or monthnum3==6 or monthnum3==9 or monthnum3==11

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the minimum difference between any two elements in a given array. https://www.geeksforgeeks.org/find-minimum-difference-pair/

cat > solution.py <<'PY'

def find_min_diff(arr,n):
    arr = sorted(arr)
    diff = 10**20
    for i in range(n-1):
        if arr[i+1] - arr[i] < diff:
            diff = arr[i+1] - arr[i]
    return diff

PY


Write Python code for the following task and make the tests pass.

Write a python function to count number of digits in a given string.

cat > solution.py <<'PY'

def number_ctr(s):
    return sum(c.isdigit() for c in s)

PY


Write Python code for the following task and make the tests pass.

Write a function to find nth polite number. geeksforgeeks.org/n-th-polite-number/

cat > solution.py <<'PY'

import math
def is_polite(n):
	n = n + 1
	return (int)(n+(math.log((n + math.log(n, 2)), 2)))

PY


Write Python code for the following task and make the tests pass.

Write a function to return a list of all pairs of consecutive items in a given list.

cat > solution.py <<'PY'

def pair_wise(l1):
    return list(zip(l1, l1[1:]))

PY


Write Python code for the following task and make the tests pass.

Write a python function to count the number of pairs whose sum is equal to ‘sum’. The funtion gets as input a list of numbers and the sum,

cat > solution.py <<'PY'

def get_pairs_count(arr, sum_):
    cnt = 0
    for n in arr:
        cnt += arr.count(sum_ - n)
        if sum_ - n == n:
            cnt -= 1
    return cnt / 2

PY


Write Python code for the following task and make the tests pass.

Write a python function to get the difference between two lists.

cat > solution.py <<'PY'

def Diff(li1,li2):
    return list(set(li1)-set(li2)) + list(set(li2)-set(li1))

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the sum of fourth power of first n odd natural numbers.

cat > solution.py <<'PY'

def odd_num_sum(n) :
    j = 0
    sm = 0
    for i in range(1,n + 1) :
        j = (2*i-1)
        sm = sm + (j*j*j*j)
    return sm

PY


Write Python code for the following task and make the tests pass.

Write a function to check if the given expression is balanced or not. https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/

cat > solution.py <<'PY'

from collections import deque
def check_expression(exp):
    if len(exp) == 0 or len(exp) % 2 == 1:
        return False
    stack = deque()
    for ch in exp:
        if ch == '(' or ch == '{' or ch == '[':
            stack.append(ch)
        if ch == ')' or ch == '}' or ch == ']':
            if not stack:
                return False
            top = stack.pop()
            if (top == '(' and ch != ')') or (top == '{' and ch != '}' or (top == '[' and ch != ']')):
                return False
    return not stack

PY


Write Python code for the following task and make the tests pass.

Write a function to remove all the words with k length in the given string.

cat > solution.py <<'PY'

def remove_length(test_str, K):
  return ' '.join([i for i in test_str.split() if len(i) != K])

PY


Write Python code for the following task and make the tests pass.

Write a function to find the occurrence and position of the substrings within a string. Return None if there is no match.

cat > solution.py <<'PY'

import re
def occurance_substring(text,pattern):
 for match in re.finditer(pattern, text):
    s = match.start()
    e = match.end()
    return (text[s:e], s, e)
 return None

PY


Write Python code for the following task and make the tests pass.

Write a python function to check whether every odd index contains odd numbers of a given list.

cat > solution.py <<'PY'

def odd_position(nums):
	return all(n % 2 == 1 for n in nums[1::2])

PY


Write Python code for the following task and make the tests pass.

Write a python function to find the sum of non-repeated elements in a given list.

cat > solution.py <<'PY'

def find_sum(arr):
    return sum(set(arr))

PY