mr44/mbsearch huggingface dataset:
Task: Write a function to find ln, m lobb number.

Solution:
def binomial_coeff(n, k): 
	C = [[0 for j in range(k + 1)] 
			for i in range(n + 1)] 
	for i in range(0, n + 1): 
		for j in range(0, min(i, k) + 1): 
			if (j == 0 or j == i): 
				C[i][j] = 1
			else: 
				C[i][j] = (C[i - 1][j - 1] 
							+ C[i - 1][j]) 
	return C[n][k] 
def lobb_num(n, m): 
	return (((2 * m + 1) *
		binomial_coeff(2 * n, m + n)) 
					/ (m + n + 1))


Tests:
assert int(lobb_num(5, 3)) == 35
assert int(lobb_num(3, 2)) == 5
assert int(lobb_num(4, 2)) == 20
Task: Write a function to check for a number at the end of a string.

Solution:
import re
def end_num(string):
    text = re.compile(r".*[0-9]$")
    if text.match(string):
        return True
    else:
        return False


Tests:
assert end_num('abcdef')==False
assert end_num('abcdef7')==True
assert end_num('abc')==False
Task: Write a python function to check whether the given string is made up of two alternating characters or not.

Solution:
def is_Two_Alter(s):  
    for i in range (len( s) - 2) : 
        if (s[i] != s[i + 2]) : 
            return False
    if (s[0] == s[1]): 
        return False
    return True


Tests:
assert is_Two_Alter("abab") == True
assert is_Two_Alter("aaaa") == False
assert is_Two_Alter("xyz") == False
Task: Write a function to rearrange positive and negative numbers in a given array using lambda function.

Solution:
def rearrange_numbs(array_nums):
  result = sorted(array_nums, key = lambda i: 0 if i == 0 else -1 / i)
  return result 


Tests:
assert rearrange_numbs([-1, 2, -3, 5, 7, 8, 9, -10])==[2, 5, 7, 8, 9, -10, -3, -1]
assert rearrange_numbs([10,15,14,13,-18,12,-20])==[10, 12, 13, 14, 15, -20, -18]
assert rearrange_numbs([-20,20,-10,10,-30,30])==[10, 20, 30, -30, -20, -10]
Task: Write a function to find if there is a triplet in the array whose sum is equal to a given value.

Solution:
def find_triplet_array(A, arr_size, sum): 
	for i in range( 0, arr_size-2): 
		for j in range(i + 1, arr_size-1): 
			for k in range(j + 1, arr_size): 
				if A[i] + A[j] + A[k] == sum: 
					return  A[i],A[j],A[k] 
					return True
	return False


Tests:
assert find_triplet_array([1, 4, 45, 6, 10, 8], 6, 22) == (4, 10, 8)
assert find_triplet_array([12, 3, 5, 2, 6, 9], 6, 24) == (12, 3, 9)
assert find_triplet_array([1, 2, 3, 4, 5], 5, 9) == (1, 3, 5)
Task: Write a function to find the sequences of one upper case letter followed by lower case letters.

Solution:
import re
def text_uppercase_lowercase(text):
        patterns = '[A-Z]+[a-z]+$'
        if re.search(patterns, text):
                return 'Found a match!'
        else:
                return ('Not matched!')


Tests:
assert text_uppercase_lowercase("AaBbGg")==('Found a match!')
assert text_uppercase_lowercase("aA")==('Not matched!')
assert text_uppercase_lowercase("PYTHON")==('Not matched!')
Task: Write a function to count coin change.

Solution:
def coin_change(S, m, n): 
    table = [[0 for x in range(m)] for x in range(n+1)] 
    for i in range(m): 
        table[0][i] = 1
    for i in range(1, n+1): 
        for j in range(m): 
            x = table[i - S[j]][j] if i-S[j] >= 0 else 0
            y = table[i][j-1] if j >= 1 else 0 
            table[i][j] = x + y   
    return table[n][m-1] 


Tests:
assert coin_change([1, 2, 3],3,4)==4
assert coin_change([4,5,6,7,8,9],6,9)==2
assert coin_change([4,5,6,7,8,9],6,4)==1
Task: Write a python function to multiply all items in the list.

Solution:
def multiply_list(items):
    tot = 1
    for x in items:
        tot *= x
    return tot


Tests:
assert multiply_list([1,-2,3]) == -6
assert multiply_list([1,2,3,4]) == 24
assert multiply_list([3,1,2,3]) == 18
Task: Write a function to remove all tuples with all none values in the given tuple list.

Solution:
def remove_tuple(test_list):
  res = [sub for sub in test_list if not all(ele == None for ele in sub)]
  return (str(res)) 


Tests:
assert remove_tuple([(None, 2), (None, None), (3, 4), (12, 3), (None, )] ) == '[(None, 2), (3, 4), (12, 3)]'
assert remove_tuple([(None, None), (None, None), (3, 6), (17, 3), (None,1 )] ) == '[(3, 6), (17, 3), (None, 1)]'
assert remove_tuple([(1, 2), (2, None), (3, None), (24, 3), (None, None )] ) == '[(1, 2), (2, None), (3, None), (24, 3)]'
Task: Write a function to perform chunking of tuples each of size n.

Solution:
def chunk_tuples(test_tup, N):
  res = [test_tup[i : i + N] for i in range(0, len(test_tup), N)]
  return (res) 


Tests:
assert chunk_tuples((10, 4, 5, 6, 7, 6, 8, 3, 4), 3) == [(10, 4, 5), (6, 7, 6), (8, 3, 4)]
assert chunk_tuples((1, 2, 3, 4, 5, 6, 7, 8, 9), 2) == [(1, 2), (3, 4), (5, 6), (7, 8), (9,)]
assert chunk_tuples((11, 14, 16, 17, 19, 21, 22, 25), 4) == [(11, 14, 16, 17), (19, 21, 22, 25)]
Task: Write a function to find a pair with the highest product from a given array of integers.

Solution:
def max_product(arr): 
    arr_len = len(arr) 
    if (arr_len < 2): 
        return None     
    x = arr[0]; y = arr[1]    
    for i in range(0, arr_len): 
        for j in range(i + 1, arr_len): 
            if (arr[i] * arr[j] > x * y): 
                x = arr[i]; y = arr[j] 
    return x,y   


Tests:
assert max_product([1, 2, 3, 4, 7, 0, 8, 4])==(7, 8)
assert max_product([0, -1, -2, -4, 5, 0, -6])==(-4, -6)
assert max_product([1, 3, 5, 6, 8, 9])==(8,9)
Task: Write a function to find the length of the shortest string that has both str1 and str2 as subsequences.

Solution:
def super_seq(X, Y, m, n):
	if (not m):
		return n
	if (not n):
		return m
	if (X[m - 1] == Y[n - 1]):
		return 1 + super_seq(X, Y, m - 1, n - 1)
	return 1 + min(super_seq(X, Y, m - 1, n),	super_seq(X, Y, m, n - 1))


Tests:
assert super_seq("AGGTAB", "GXTXAYB", 6, 7) == 9
assert super_seq("feek", "eke", 4, 3) == 5
assert super_seq("PARRT", "RTA", 5, 3) == 6
Task: Write a function to find maximum of two numbers.

Solution:
def max_of_two( x, y ):
    if x > y:
        return x
    return y


Tests:
assert max_of_two(10,20)==20
assert max_of_two(19,15)==19
assert max_of_two(-10,-20)==-10
Task: Write a python function to calculate the product of all the numbers of a given tuple.

Solution:
def mutiple_tuple(nums):
    temp = list(nums)
    product = 1 
    for x in temp:
        product *= x
    return product


Tests:
assert mutiple_tuple((4, 3, 2, 2, -1, 18)) == -864
assert mutiple_tuple((1,2,3)) == 6
assert mutiple_tuple((-2,-4,-6)) == -48
Task: Write a function to find n-th rencontres number.

Solution:
def binomial_coeffi(n, k): 
	if (k == 0 or k == n): 
		return 1
	return (binomial_coeffi(n - 1, k - 1) 
		+ binomial_coeffi(n - 1, k)) 
def rencontres_number(n, m): 
	if (n == 0 and m == 0): 
		return 1
	if (n == 1 and m == 0): 
		return 0
	if (m == 0): 
		return ((n - 1) * (rencontres_number(n - 1, 0)+ rencontres_number(n - 2, 0))) 
	return (binomial_coeffi(n, m) * rencontres_number(n - m, 0))


Tests:
assert rencontres_number(7, 2) == 924
assert rencontres_number(3, 0) == 2
assert rencontres_number(3, 1) == 3
Task: Write a function to calculate the height of the given binary tree.

Solution:
class Node: 
	def __init__(self, data): 
		self.data = data 
		self.left = None
		self.right = None
def max_height(node): 
	if node is None: 
		return 0 ; 
	else : 
		left_height = max_height(node.left) 
		right_height = max_height(node.right) 
		if (left_height > right_height): 
			return left_height+1
		else: 
			return right_height+1

Test setup: root = Node(1) 
root.left = Node(2) 
root.right = Node(3) 
root.left.left = Node(4) 
root.left.right = Node(5) 
root1 = Node(1);  
root1.left = Node(2);  
root1.right = Node(3);  
root1.left.left = Node(4);  
root1.right.left = Node(5);  
root1.right.right = Node(6);  
root1.right.right.right= Node(7);  
root1.right.right.right.right = Node(8)
root2 = Node(1) 
root2.left = Node(2) 
root2.right = Node(3) 
root2.left.left = Node(4) 
root2.left.right = Node(5)
root2.left.left.left = Node(6)
root2.left.left.right = Node(7)

Tests:
assert (max_height(root)) == 3
assert (max_height(root1)) == 5 
assert (max_height(root2)) == 4
Task: Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format.

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


Tests:
assert change_date_format('2026-01-02')=='02-01-2026'
assert change_date_format('2021-01-04')=='04-01-2021'
assert change_date_format('2030-06-06')=='06-06-2030'
Task: Write a function to count repeated items of a tuple.

Solution:
def count_tuplex(tuplex,value):  
  count = tuplex.count(value)
  return count


Tests:
assert count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7),4)==3
assert count_tuplex((2, 4, 5, 6, 2, 3, 4, 4, 7),2)==2
assert count_tuplex((2, 4, 7, 7, 7, 3, 4, 4, 7),7)==4
Task: Write a function that matches a string that has an a followed by zero or more b's by using regex.

Solution:
import re
def text_match(text):
        patterns = 'ab*?'
        if re.search(patterns,  text):
                return ('Found a match!')
        else:
                return ('Not matched!')


Tests:
assert text_match("msb") == 'Not matched!'
assert text_match("a0c") == 'Found a match!'
assert text_match("abbc") == 'Found a match!'
Task: Write a function to calculate the sum of series 1³+2³+3³+….+n³.

Solution:
import math 
def sum_series(number):
 total = 0
 total = math.pow((number * (number + 1)) /2, 2)
 return total


Tests:
assert sum_series(7)==784
assert sum_series(5)==225
assert sum_series(15)==14400
Task: Write a function to remove duplicate words from a given list of strings.

Solution:
def remove_duplic_list(l):
    temp = []
    for x in l:
        if x not in temp:
            temp.append(x)
    return temp


Tests:
assert remove_duplic_list(["Python", "Exercises", "Practice", "Solution", "Exercises"])==['Python', 'Exercises', 'Practice', 'Solution']
assert remove_duplic_list(["Python", "Exercises", "Practice", "Solution", "Exercises","Java"])==['Python', 'Exercises', 'Practice', 'Solution', 'Java']
assert remove_duplic_list(["Python", "Exercises", "Practice", "Solution", "Exercises","C++","C","C++"])==['Python', 'Exercises', 'Practice', 'Solution','C++','C']
Task: Write a function to convert camel case string to snake case string by using regex.

Solution:
import re
def camel_to_snake(text):
  str1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', text)
  return re.sub('([a-z0-9])([A-Z])', r'\1_\2', str1).lower()


Tests:
assert camel_to_snake('GoogleAssistant') == 'google_assistant'
assert camel_to_snake('ChromeCast') == 'chrome_cast'
assert camel_to_snake('QuadCore') == 'quad_core'
Task: Write a function to find the nth delannoy number.

Solution:
def dealnnoy_num(n, m): 
	if (m == 0 or n == 0) : 
		return 1
	return dealnnoy_num(m - 1, n) + dealnnoy_num(m - 1, n - 1) + dealnnoy_num(m, n - 1)


Tests:
assert dealnnoy_num(3, 4) == 129
assert dealnnoy_num(3, 3) == 63
assert dealnnoy_num(4, 5) == 681
Task: Write a function to calculate the sum of series 1²+2²+3²+….+n².

Solution:
def series_sum(number):
 total = 0
 total = (number * (number + 1) * (2 * number + 1)) / 6
 return total


Tests:
assert series_sum(6)==91
assert series_sum(7)==140
assert series_sum(12)==650
Task: Write a function to re-arrange the given tuples based on the given ordered list.

Solution:
def re_arrange_tuples(test_list, ord_list):
  temp = dict(test_list)
  res = [(key, temp[key]) for key in ord_list]
  return (res) 


Tests:
assert re_arrange_tuples([(4, 3), (1, 9), (2, 10), (3, 2)],  [1, 4, 2, 3]) == [(1, 9), (4, 3), (2, 10), (3, 2)]
assert re_arrange_tuples([(5, 4), (2, 10), (3, 11), (4, 3)],  [3, 4, 2, 3]) == [(3, 11), (4, 3), (2, 10), (3, 11)]
assert re_arrange_tuples([(6, 3), (3, 8), (5, 7), (2, 4)],  [2, 5, 3, 6]) == [(2, 4), (5, 7), (3, 8), (6, 3)]
Task: Write a function to count the most common character in a given string.

Solution:
from collections import Counter 
def max_char(str1):
    temp = Counter(str1) 
    max_char = max(temp, key = temp.get)
    return max_char


Tests:
assert max_char("hello world")==('l')
assert max_char("hello ")==('l')
assert max_char("python pr")==('p')
Task: Write a function to find three closest elements from three sorted arrays.

Solution:
import sys 

def find_closet(A, B, C, p, q, r): 
	diff = sys.maxsize 
	res_i = 0
	res_j = 0
	res_k = 0
	i = 0
	j = 0
	k = 0
	while(i < p and j < q and k < r): 
		minimum = min(A[i], min(B[j], C[k])) 
		maximum = max(A[i], max(B[j], C[k])); 
		if maximum-minimum < diff: 
			res_i = i 
			res_j = j 
			res_k = k 
			diff = maximum - minimum; 
		if diff == 0: 
			break
		if A[i] == minimum: 
			i = i+1
		elif B[j] == minimum: 
			j = j+1
		else: 
			k = k+1
	return A[res_i],B[res_j],C[res_k]


Tests:
assert find_closet([1, 4, 10],[2, 15, 20],[10, 12],3,3,2) == (10, 15, 10)
assert find_closet([20, 24, 100],[2, 19, 22, 79, 800],[10, 12, 23, 24, 119],3,5,5) == (24, 22, 23)
assert find_closet([2, 5, 11],[3, 16, 21],[11, 13],3,3,2) == (11, 16, 11)
Task: Write a function to sort a list of dictionaries using lambda function.

Solution:
def sorted_models(models):
 sorted_models = sorted(models, key = lambda x: x['color'])
 return sorted_models


Tests:
assert sorted_models([{'make':'Nokia', 'model':216, 'color':'Black'}, {'make':'Mi Max', 'model':2, 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color':'Blue'}])==[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'Mi Max', 'model': 2, 'color': 'Gold'}]
assert sorted_models([{'make':'Vivo', 'model':20,'color':'Blue'},{'make': 'oppo','model':17,'color':'Gold'},{'make':'Apple','model':11,'color':'red'}])==([{'make':'Vivo', 'model':20,'color':'Blue'},{'make': 'oppo','model':17,'color':'Gold'},{'make':'Apple','model':11,'color':'red'}])
assert sorted_models([{'make':'micromax','model':40,'color':'grey'},{'make':'poco','model':60,'color':'blue'}])==([{'make':'poco','model':60,'color':'blue'},{'make':'micromax','model':40,'color':'grey'}])
Task: Write a function to sort the given array by using heap sort.

Solution:
def heap_sort(arr):
    heapify(arr)  
    end = len(arr) - 1
    while end > 0:
        arr[end], arr[0] = arr[0], arr[end]
        shift_down(arr, 0, end - 1)
        end -= 1
    return arr

def heapify(arr):
    start = len(arr) // 2
    while start >= 0:
        shift_down(arr, start, len(arr) - 1)
        start -= 1
def shift_down(arr, start, end):
    root = start
    while root * 2 + 1 <= end:
        child = root * 2 + 1
        if child + 1 <= end and arr[child] < arr[child + 1]:
            child += 1
        if child <= end and arr[root] < arr[child]:
            arr[root], arr[child] = arr[child], arr[root]
            root = child
        else:
            return



Tests:
assert heap_sort([12, 2, 4, 5, 2, 3]) == [2, 2, 3, 4, 5, 12]
assert heap_sort([32, 14, 5, 6, 7, 19]) == [5, 6, 7, 14, 19, 32]
assert heap_sort([21, 15, 29, 78, 65]) == [15, 21, 29, 65, 78]
Task: Write a function to count the elements in a list until an element is a tuple.

Solution:
def count_elim(num):
  count_elim = 0
  for n in num:
    if isinstance(n, tuple):
        break
    count_elim += 1
  return count_elim


Tests:
assert count_elim([10,20,30,(10,20),40])==3
assert count_elim([10,(20,30),(10,20),40])==1
assert count_elim([(10,(20,30,(10,20),40))])==0
Task: Write a function to check if any list element is present in the given list.

Solution:
def check_element(test_tup, check_list):
  res = False
  for ele in check_list:
    if ele in test_tup:
      res = True
      break
  return (res) 


Tests:
assert check_element((4, 5, 7, 9, 3),  [6, 7, 10, 11]) == True
assert check_element((1, 2, 3, 4),  [4, 6, 7, 8, 9]) == True
assert check_element((3, 2, 1, 4, 5),  [9, 8, 7, 6]) == False
Task: Write a function to combine two given sorted lists using heapq module.

Solution:
from heapq import merge
def combine_lists(num1,num2):
  combine_lists=list(merge(num1, num2))
  return combine_lists


Tests:
assert combine_lists([1, 3, 5, 7, 9, 11],[0, 2, 4, 6, 8, 10])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
assert combine_lists([1, 3, 5, 6, 8, 9], [2, 5, 7, 11])==[1,2,3,5,5,6,7,8,9,11]
assert combine_lists([1,3,7],[2,4,6])==[1,2,3,4,6,7]
Task: Write a function to separate and print the numbers and their position of a given string.

Solution:
import re
def num_position(text):
 for m in re.finditer("\d+", text):
    return m.start()


Tests:
assert num_position("there are 70 flats in this apartment")==10
assert num_position("every adult have 32 teeth")==17
assert num_position("isha has 79 chocolates in her bag")==9
Task: Write a function to convert the given tuples into set.

Solution:
def tuple_to_set(t):
  s = set(t)
  return (s) 


Tests:
assert tuple_to_set(('x', 'y', 'z') ) == {'y', 'x', 'z'}
assert tuple_to_set(('a', 'b', 'c') ) == {'c', 'a', 'b'}
assert tuple_to_set(('z', 'd', 'e') ) == {'d', 'e', 'z'}
Task: Write a function to find the most common elements and their counts of a specified text.

Solution:
from collections import Counter 
def most_common_elem(s,a):
  most_common_elem=Counter(s).most_common(a)
  return most_common_elem


Tests:
assert most_common_elem('lkseropewdssafsdfafkpwe',3)==[('s', 4), ('e', 3), ('f', 3)] 
assert most_common_elem('lkseropewdssafsdfafkpwe',2)==[('s', 4), ('e', 3)]
assert most_common_elem('lkseropewdssafsdfafkpwe',7)==[('s', 4), ('e', 3), ('f', 3), ('k', 2), ('p', 2), ('w', 2), ('d', 2)]
Task: Write a python function to find the length of the shortest word.

Solution:
def len_log(list1):
    min=len(list1[0])
    for i in list1:
        if len(i)<min:
            min=len(i)
    return min


Tests:
assert len_log(["win","lose","great"]) == 3
assert len_log(["a","ab","abc"]) == 1
assert len_log(["12","12","1234"]) == 2
Task: Write a function to get an item of a tuple.

Solution:
def get_item(tup1,index):
  item = tup1[index]
  return item


Tests:
assert get_item(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),3)==('e')
assert get_item(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),-4)==('u')
assert get_item(("w", 3, "r", "e", "s", "o", "u", "r", "c", "e"),-3)==('r')
Task: Write a function to sort the given tuple list basis the total digits in tuple.

Solution:
def count_digs(tup):
  return sum([len(str(ele)) for ele in tup ]) 
def sort_list(test_list):
  test_list.sort(key = count_digs)
  return (str(test_list))


Tests:
assert sort_list([(3, 4, 6, 723), (1, 2), (12345,), (134, 234, 34)] ) == '[(1, 2), (12345,), (3, 4, 6, 723), (134, 234, 34)]'
assert sort_list([(3, 4, 8), (1, 2), (1234335,), (1345, 234, 334)] ) == '[(1, 2), (3, 4, 8), (1234335,), (1345, 234, 334)]'
assert sort_list([(34, 4, 61, 723), (1, 2), (145,), (134, 23)] ) == '[(1, 2), (145,), (134, 23), (34, 4, 61, 723)]'
Task: Write a function to display sign of the chinese zodiac for given year.

Solution:
def chinese_zodiac(year):
 if (year - 2000) % 12 == 0:
     sign = 'Dragon'
 elif (year - 2000) % 12 == 1:
     sign = 'Snake'
 elif (year - 2000) % 12 == 2:
     sign = 'Horse'
 elif (year - 2000) % 12 == 3:
     sign = 'sheep'
 elif (year - 2000) % 12 == 4:
     sign = 'Monkey'
 elif (year - 2000) % 12 == 5:
     sign = 'Rooster'
 elif (year - 2000) % 12 == 6:
     sign = 'Dog'
 elif (year - 2000) % 12 == 7:
     sign = 'Pig'
 elif (year - 2000) % 12 == 8:
     sign = 'Rat'
 elif (year - 2000) % 12 == 9:
     sign = 'Ox'
 elif (year - 2000) % 12 == 10:
     sign = 'Tiger'
 else:
     sign = 'Hare'
 return sign


Tests:
assert chinese_zodiac(1997)==('Ox')
assert chinese_zodiac(1998)==('Tiger')
assert chinese_zodiac(1994)==('Dog')
Task: Write a function to find the maximum of similar indices in two lists of tuples.

Solution:
def max_similar_indices(test_list1, test_list2):
  res = [(max(x[0], y[0]), max(x[1], y[1]))
   for x, y in zip(test_list1, test_list2)]
  return (res) 


Tests:
assert max_similar_indices([(2, 4), (6, 7), (5, 1)],[(5, 4), (8, 10), (8, 14)]) == [(5, 4), (8, 10), (8, 14)]
assert max_similar_indices([(3, 5), (7, 8), (6, 2)],[(6, 5), (9, 11), (9, 15)]) == [(6, 5), (9, 11), (9, 15)]
assert max_similar_indices([(4, 6), (8, 9), (7, 3)],[(7, 6), (10, 12), (10, 16)]) == [(7, 6), (10, 12), (10, 16)]
Task: Write a function to compute the value of ncr mod p.

Solution:
def nCr_mod_p(n, r, p): 
	if (r > n- r): 
		r = n - r 
	C = [0 for i in range(r + 1)] 
	C[0] = 1 
	for i in range(1, n + 1): 
		for j in range(min(i, r), 0, -1): 
			C[j] = (C[j] + C[j-1]) % p 
	return C[r] 


Tests:
assert nCr_mod_p(10, 2, 13) == 6
assert nCr_mod_p(11, 3, 14) == 11
assert nCr_mod_p(18, 14, 19) == 1
Task: Write a python function to find the minimun number of subsets with distinct elements.

Solution:
def subset(ar, n): 
    res = 0
    ar.sort() 
    for i in range(0, n) : 
        count = 1
        for i in range(n - 1): 
            if ar[i] == ar[i + 1]: 
                count+=1
            else: 
                break 
        res = max(res, count)  
    return res 


Tests:
assert subset([1, 2, 3, 4],4) == 1
assert subset([5, 6, 9, 3, 4, 3, 4],7) == 2
assert subset([1, 2, 3 ],3) == 1
Task: Write a function that gives profit amount if the given amount has profit else return none.

Solution:
def profit_amount(actual_cost,sale_amount): 
 if(actual_cost > sale_amount):
    amount = actual_cost - sale_amount
    return amount
 else:
    return None


Tests:
assert profit_amount(1500,1200)==300
assert profit_amount(100,200)==None
assert profit_amount(2000,5000)==None
Task: Write a function to find out, if the given number is abundant.

Solution:
def is_abundant(n):
    fctrsum = sum([fctr for fctr in range(1, n) if n % fctr == 0])
    return fctrsum > n


Tests:
assert is_abundant(12)==True
assert is_abundant(13)==False
assert is_abundant(9)==False
Task: Write a function to split the given string at uppercase letters by using regex.

Solution:
import re
def split_list(text):
  return (re.findall('[A-Z][^A-Z]*', text))


Tests:
assert split_list("LearnToBuildAnythingWithGoogle") == ['Learn', 'To', 'Build', 'Anything', 'With', 'Google']
assert split_list("ApmlifyingTheBlack+DeveloperCommunity") == ['Apmlifying', 'The', 'Black+', 'Developer', 'Community']
assert split_list("UpdateInTheGoEcoSystem") == ['Update', 'In', 'The', 'Go', 'Eco', 'System']
Task: Write a python function to get the position of rightmost set bit.

Solution:
import math
def get_First_Set_Bit_Pos(n):
     return math.log2(n&-n)+1


Tests:
assert get_First_Set_Bit_Pos(12) == 3
assert get_First_Set_Bit_Pos(18) == 2
assert get_First_Set_Bit_Pos(16) == 5
Task: Write a function to convert an integer into a roman numeral.

Solution:
def int_to_roman( num):
        val = [1000, 900, 500, 400,100, 90, 50, 40,10, 9, 5, 4,1]
        syb = ["M", "CM", "D", "CD","C", "XC", "L", "XL","X", "IX", "V", "IV","I"]
        roman_num = ''
        i = 0
        while  num > 0:
            for _ in range(num // val[i]):
                roman_num += syb[i]
                num -= val[i]
            i += 1
        return roman_num


Tests:
assert int_to_roman(1)==("I")
assert int_to_roman(50)==("L")
assert int_to_roman(4)==("IV")
Task: Write a python function to find the average of a list.

Solution:
def Average(lst): 
    return sum(lst) / len(lst) 


Tests:
assert Average([15, 9, 55, 41, 35, 20, 62, 49]) == 35.75
assert Average([4, 5, 1, 2, 9, 7, 10, 8]) == 5.75
assert Average([1,2,3]) == 2
Task: Write a function to solve tiling problem.

Solution:
def get_noOfways(n):
    if (n == 0):
        return 0;
    if (n == 1):
        return 1; 
    return get_noOfways(n - 1) + get_noOfways(n - 2);


Tests:
assert get_noOfways(4)==3
assert get_noOfways(3)==2
assert get_noOfways(5)==5