mr44/mbsearch huggingface dataset:
Task: Write a function to sort a list of lists by length and value.

Solution:
def sort_sublists(list1):
      list1.sort()  
      list1.sort(key=len)
      return  list1


Tests:
assert sort_sublists([[2], [0], [1, 3], [0, 7], [9, 11], [13, 15, 17]])==[[0], [2], [0, 7], [1, 3], [9, 11], [13, 15, 17]]
assert sort_sublists([[1], [2, 3], [4, 5, 6], [7], [10, 11]])==[[1], [7], [2, 3], [10, 11], [4, 5, 6]]
assert sort_sublists([["python"],["java","C","C++"],["DBMS"],["SQL","HTML"]])==[['DBMS'], ['python'], ['SQL', 'HTML'], ['java', 'C', 'C++']]
Task: Write a function to find whether an array is subset of another array.

Solution:
def is_subset(arr1, m, arr2, n): 
	hashset = set() 
	for i in range(0, m): 
		hashset.add(arr1[i]) 
	for i in range(0, n): 
		if arr2[i] in hashset: 
			continue
		else: 
			return False
	return True		


Tests:
assert is_subset([11, 1, 13, 21, 3, 7], 6, [11, 3, 7, 1], 4) == True
assert is_subset([1, 2, 3, 4, 5, 6], 6, [1, 2, 4], 3) == True
assert is_subset([10, 5, 2, 23, 19], 5, [19, 5, 3], 3) == False
Task: Write a python function to count the total set bits from 1 to n.

Solution:
def count_Set_Bits(n) :  
    n += 1; 
    powerOf2 = 2;   
    cnt = n // 2;  
    while (powerOf2 <= n) : 
        totalPairs = n // powerOf2;  
        cnt += (totalPairs // 2) * powerOf2;  
        if (totalPairs & 1) : 
            cnt += (n % powerOf2) 
        else : 
            cnt += 0
        powerOf2 <<= 1;    
    return cnt;  


Tests:
assert count_Set_Bits(16) == 33
assert count_Set_Bits(2) == 2
assert count_Set_Bits(14) == 28
Task: Write a python function to convert a string to a list.

Solution:
def Convert(string): 
    li = list(string.split(" ")) 
    return li 


Tests:
assert Convert('python program') == ['python','program']
assert Convert('Data Analysis') ==['Data','Analysis']
assert Convert('Hadoop Training') == ['Hadoop','Training']
Task: Write a function to count unique keys for each value present in the tuple.

Solution:
from collections import defaultdict 
def get_unique(test_list):
  res = defaultdict(list)
  for sub in test_list:
    res[sub[1]].append(sub[0])
  res = dict(res)
  res_dict = dict()
  for key in res:
    res_dict[key] = len(list(set(res[key])))
  return (str(res_dict)) 


Tests:
assert get_unique([(3, 4), (1, 2), (2, 4), (8, 2), (7, 2), (8, 1), (9, 1), (8, 4), (10, 4)] ) == '{4: 4, 2: 3, 1: 2}'
assert get_unique([(4, 5), (2, 3), (3, 5), (9, 3), (8, 3), (9, 2), (10, 2), (9, 5), (11, 5)] ) == '{5: 4, 3: 3, 2: 2}'
assert get_unique([(6, 5), (3, 4), (2, 6), (11, 1), (8, 22), (8, 11), (4, 3), (14, 3), (11, 6)] ) == '{5: 1, 4: 1, 6: 2, 1: 1, 22: 1, 11: 1, 3: 2}'
Task: Write a function to access the initial and last data of the given tuple record.

Solution:
def front_and_rear(test_tup):
  res = (test_tup[0], test_tup[-1])
  return (res) 


Tests:
assert front_and_rear((10, 4, 5, 6, 7)) == (10, 7)
assert front_and_rear((1, 2, 3, 4, 5)) == (1, 5)
assert front_and_rear((6, 7, 8, 9, 10)) == (6, 10)
Task: Write a python function to check whether the product of digits of a number at even and odd places is equal or not.

Solution:
def product_Equal(n): 
    if n < 10: 
        return False
    prodOdd = 1; prodEven = 1
    while n > 0: 
        digit = n % 10
        prodOdd *= digit 
        n = n//10
        if n == 0: 
            break; 
        digit = n % 10
        prodEven *= digit 
        n = n//10
    if prodOdd == prodEven: 
        return True
    return False


Tests:
assert product_Equal(2841) == True
assert product_Equal(1234) == False
assert product_Equal(1212) == False
Task: Write a function to remove duplicates from a list of lists.

Solution:
import itertools
def remove_duplicate(list1):
 list.sort(list1)
 remove_duplicate = list(list1 for list1,_ in itertools.groupby(list1))
 return remove_duplicate


Tests:
assert remove_duplicate([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])==[[10, 20], [30, 56, 25], [33], [40]] 
assert remove_duplicate(["a", "b", "a", "c", "c"] )==["a", "b", "c"]
assert remove_duplicate([1, 3, 5, 6, 3, 5, 6, 1] )==[1, 3, 5, 6]
Task: Write a function to check if the given tuple contains all valid values or not.

Solution:
def check_valid(test_tup):
  res = not any(map(lambda ele: not ele, test_tup))
  return (res) 


Tests:
assert check_valid((True, True, True, True) ) == True
assert check_valid((True, False, True, True) ) == False
assert check_valid((True, True, True, True) ) == True
Task: Write a python function to count the number of distinct power of prime factor of given number.

Solution:
def count_Fac(n):  
    m = n 
    count = 0
    i = 2
    while((i * i) <= m): 
        total = 0
        while (n % i == 0): 
            n /= i 
            total += 1 
        temp = 0
        j = 1
        while((temp + j) <= total): 
            temp += j 
            count += 1
            j += 1 
        i += 1
    if (n != 1): 
        count += 1 
    return count 


Tests:
assert count_Fac(24) == 3
assert count_Fac(12) == 2
assert count_Fac(4) == 1
Task: Write a function to convert the given string of integers into a tuple.

Solution:
def str_to_tuple(test_str):
  res = tuple(map(int, test_str.split(', ')))
  return (res) 


Tests:
assert str_to_tuple("1, -5, 4, 6, 7") == (1, -5, 4, 6, 7)
assert str_to_tuple("1, 2, 3, 4, 5") == (1, 2, 3, 4, 5)
assert str_to_tuple("4, 6, 9, 11, 13, 14") == (4, 6, 9, 11, 13, 14)
Task: Write a function to find the perimeter of a rombus.

Solution:
def rombus_perimeter(a):
  perimeter=4*a
  return perimeter


Tests:
assert rombus_perimeter(10)==40
assert rombus_perimeter(5)==20
assert rombus_perimeter(4)==16
Task: Write a function to calculate the standard deviation.

Solution:
import math
import sys
def sd_calc(data):
    n = len(data)
    if n <= 1:
        return 0.0
    mean, sd = avg_calc(data), 0.0
    for el in data:
        sd += (float(el) - mean)**2
    sd = math.sqrt(sd / float(n-1))
    return sd
def avg_calc(ls):
    n, mean = len(ls), 0.0
    if n <= 1:
        return ls[0]
    for el in ls:
        mean = mean + float(el)
    mean = mean / float(n)
    return mean


Tests:
assert sd_calc([4, 2, 5, 8, 6])== 2.23606797749979
assert sd_calc([1,2,3,4,5,6,7])==2.160246899469287
assert sd_calc([5,9,10,15,6,4])==4.070217029430577
Task: Write a function to create a list taking alternate elements from another given list.

Solution:
def alternate_elements(list1):
    result=[]
    for item in list1[::2]:
        result.append(item)
    return result 


Tests:
assert alternate_elements(["red", "black", "white", "green", "orange"])==['red', 'white', 'orange']
assert alternate_elements([2, 0, 3, 4, 0, 2, 8, 3, 4, 2])==[2, 3, 0, 8, 4]
assert alternate_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9]
Task: Write a function that matches a string that has an a followed by zero or more b's.

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("ac")==('Found a match!')
assert text_match("dc")==('Not matched!')
assert text_match("abba")==('Found a match!')
Task: Write a function to add a dictionary to the tuple.

Solution:
def add_dict_to_tuple(test_tup, test_dict):
  test_tup = list(test_tup)
  test_tup.append(test_dict)
  test_tup = tuple(test_tup)
  return (test_tup) 


Tests:
assert add_dict_to_tuple((4, 5, 6), {"MSAM" : 1, "is" : 2, "best" : 3} ) == (4, 5, 6, {'MSAM': 1, 'is': 2, 'best': 3})
assert add_dict_to_tuple((1, 2, 3), {"UTS" : 2, "is" : 3, "Worst" : 4} ) == (1, 2, 3, {'UTS': 2, 'is': 3, 'Worst': 4})
assert add_dict_to_tuple((8, 9, 10), {"POS" : 3, "is" : 4, "Okay" : 5} ) == (8, 9, 10, {'POS': 3, 'is': 4, 'Okay': 5})
Task: Write a function to find a path with the maximum average over all existing paths for the given square matrix of size n*n.

Solution:
M = 100
def maxAverageOfPath(cost, N): 
	dp = [[0 for i in range(N + 1)] for j in range(N + 1)] 
	dp[0][0] = cost[0][0] 
	for i in range(1, N): 
		dp[i][0] = dp[i - 1][0] + cost[i][0] 
	for j in range(1, N): 
		dp[0][j] = dp[0][j - 1] + cost[0][j] 
	for i in range(1, N): 
		for j in range(1, N): 
			dp[i][j] = max(dp[i - 1][j], 
						dp[i][j - 1]) + cost[i][j] 
	return dp[N - 1][N - 1] / (2 * N - 1)


Tests:
assert maxAverageOfPath([[1, 2, 3], [6, 5, 4], [7, 3, 9]], 3) == 5.2
assert maxAverageOfPath([[2, 3, 4], [7, 6, 5], [8, 4, 10]], 3) == 6.2
assert maxAverageOfPath([[3, 4, 5], [8, 7, 6], [9, 5, 11]], 3) == 7.2
Task: Write a function to filter the height and width of students which are stored in a dictionary.

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


Tests:
assert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},6.0,70)=={'Cierra Vega': (6.2, 70)}
assert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},5.9,67)=={'Cierra Vega': (6.2, 70),'Kierra Gentry': (6.0, 68)}
assert filter_data({'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)},5.7,64)=={'Cierra Vega': (6.2, 70),'Alden Cantrell': (5.9, 65),'Kierra Gentry': (6.0, 68),'Pierre Cox': (5.8, 66)}
Task: Write a function to count the same pair in two given lists using map function.

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


Tests:
assert count_same_pair([1, 2, 3, 4, 5, 6, 7, 8],[2, 2, 3, 1, 2, 6, 7, 9])==4
assert count_same_pair([0, 1, 2, -1, -5, 6, 0, -3, -2, 3, 4, 6, 8],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==11
assert count_same_pair([2, 4, -6, -9, 11, -12, 14, -5, 17],[2, 1, 2, -1, -5, 6, 4, -3, -2, 3, 4, 6, 8])==1
Task: Write a function to calculate the sum of all digits of the base to the specified power.

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


Tests:
assert power_base_sum(2,100)==115
assert power_base_sum(8,10)==37
assert power_base_sum(8,15)==62
Task: Write a function to extract values between quotation marks of the given string by using regex.

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


Tests:
assert extract_quotation('Cortex "A53" Based "multi" tasking "Processor"') == ['A53', 'multi', 'Processor']
assert extract_quotation('Cast your "favorite" entertainment "apps"') == ['favorite', 'apps']
assert extract_quotation('Watch content "4k Ultra HD" resolution with "HDR 10" Support') == ['4k Ultra HD', 'HDR 10']
Task: Write a function to multiply the adjacent elements of the given tuple.

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


Tests:
assert multiply_elements((1, 5, 7, 8, 10)) == (5, 35, 56, 80)
assert multiply_elements((2, 4, 5, 6, 7)) == (8, 20, 30, 42)
assert multiply_elements((12, 13, 14, 9, 15)) == (156, 182, 126, 135)
Task: Write a function to remove all characters except letters and numbers using regex

Solution:
import re 
def remove_char(S):
  result = re.sub('[\W_]+', '', S) 
  return result


Tests:
assert remove_char("123abcjw:, .@! eiw") == '123abcjweiw'
assert remove_char("Hello1234:, ! Howare33u") == 'Hello1234Howare33u'
assert remove_char("Cool543Triks@:, Make@987Trips") == 'Cool543TriksMake987Trips'
Task: Write a function to sum elements in two lists.

Solution:
def sum_list(lst1,lst2):
  res_list = [lst1[i] + lst2[i] for i in range(len(lst1))] 
  return res_list


Tests:
assert sum_list([10,20,30],[15,25,35])==[25,45,65]
assert sum_list([1,2,3],[5,6,7])==[6,8,10]
assert sum_list([15,20,30],[15,45,75])==[30,65,105]
Task: Write a function to add two lists using map and lambda function.

Solution:
def add_list(nums1,nums2):
  result = map(lambda x, y: x + y, nums1, nums2)
  return list(result)


Tests:
assert add_list([1, 2, 3],[4,5,6])==[5, 7, 9]
assert add_list([1,2],[3,4])==[4,6]
assert add_list([10,20],[50,70])==[60,90]
Task: Write a function to remove consecutive duplicates of a given list.

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


Tests:
assert consecutive_duplicates([0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4 ])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4]
assert consecutive_duplicates([10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10])==[10, 15, 19, 18, 17, 26, 17, 18, 10]
assert consecutive_duplicates(['a', 'a', 'b', 'c', 'd', 'd'])==['a', 'b', 'c', 'd']
Task: Write a function to find the lateral surface area of a cone.

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


Tests:
assert lateralsurface_cone(5,12)==204.20352248333654
assert lateralsurface_cone(10,15)==566.3586699569488
assert lateralsurface_cone(19,17)==1521.8090132193388
Task: Write a function to replace all occurrences of spaces, commas, or dots with a colon.

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


Tests:
assert replace_specialchar('Python language, Programming language.')==('Python:language::Programming:language:')
assert replace_specialchar('a b c,d e f')==('a:b:c:d:e:f')
assert replace_specialchar('ram reshma,ram rahim')==('ram:reshma:ram:rahim')
Task: Write a function to find the index of the first occurrence of a given number in a sorted array.

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


Tests:
assert find_first_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 1
assert find_first_occurrence([2, 3, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 2
assert find_first_occurrence([2, 4, 1, 5, 6, 6, 8, 9, 9, 9], 6) == 4
Task: Write a python function to find sum of products of all possible subarrays.

Solution:
def sum_Of_Subarray_Prod(arr,n):
    ans = 0
    res = 0
    i = n - 1
    while (i >= 0):
        incr = arr[i]*(1 + res)
        ans += incr
        res = incr
        i -= 1
    return (ans)


Tests:
assert sum_Of_Subarray_Prod([1,2,3],3) == 20
assert sum_Of_Subarray_Prod([1,2],2) == 5
assert sum_Of_Subarray_Prod([1,2,3,4],4) == 84
Task: Write a python function to toggle bits of the number except the first and the last bit.

Solution:
def set_middle_bits(n):  
    n |= n >> 1; 
    n |= n >> 2; 
    n |= n >> 4; 
    n |= n >> 8; 
    n |= n >> 16;  
    return (n >> 1) ^ 1
def toggle_middle_bits(n): 
    if (n == 1): 
        return 1
    return n ^ set_middle_bits(n) 


Tests:
assert toggle_middle_bits(9) == 15
assert toggle_middle_bits(10) == 12
assert toggle_middle_bits(11) == 13
Task: Write a function to locate the left insertion point for a specified value in sorted order.

Solution:
import bisect
def left_insertion(a, x):
    i = bisect.bisect_left(a, x)
    return i


Tests:
assert left_insertion([1,2,4,5],6)==4
assert left_insertion([1,2,4,5],3)==2
assert left_insertion([1,2,4,5],7)==4
Task: Write a function to check whether the given string is starting with a vowel or not using regex.

Solution:
import re 
regex = '^[aeiouAEIOU][A-Za-z0-9_]*'
def check_str(string): 
	if(re.search(regex, string)): 
		return ("Valid") 
	else: 
		return ("Invalid") 


Tests:
assert check_str("annie") == 'Valid'
assert check_str("dawood") == 'Invalid'
assert check_str("Else") == 'Valid'
Task: Write a function to calculate the geometric sum of n-1.

Solution:
def geometric_sum(n):
  if n < 0:
    return 0
  else:
    return 1 / (pow(2, n)) + geometric_sum(n - 1)


Tests:
assert geometric_sum(7) == 1.9921875
assert geometric_sum(4) == 1.9375
assert geometric_sum(8) == 1.99609375
Task: Write a python function to find the index of smallest triangular number with n digits.

Solution:
import math 
def find_Index(n): 
    x = math.sqrt(2 * math.pow(10,(n - 1))); 
    return round(x); 


Tests:
assert find_Index(2) == 4
assert find_Index(3) == 14
assert find_Index(4) == 45
Task: Write a function to convert the given tuple to a key-value dictionary using adjacent elements.

Solution:
def tuple_to_dict(test_tup):
  res = dict(test_tup[idx : idx + 2] for idx in range(0, len(test_tup), 2))
  return (res) 


Tests:
assert tuple_to_dict((1, 5, 7, 10, 13, 5)) == {1: 5, 7: 10, 13: 5}
assert tuple_to_dict((1, 2, 3, 4, 5, 6)) == {1: 2, 3: 4, 5: 6}
assert tuple_to_dict((7, 8, 9, 10, 11, 12)) == {7: 8, 9: 10, 11: 12}
Task: Write a python function to check whether all the characters are same or not.

Solution:
def all_Characters_Same(s) :
    n = len(s)
    for i in range(1,n) :
        if s[i] != s[0] :
            return False
    return True


Tests:
assert all_Characters_Same("python") == False
assert all_Characters_Same("aaa") == True
assert all_Characters_Same("data") == False
Task: Write a function to caluclate the area of a tetrahedron.

Solution:
import math
def area_tetrahedron(side):
  area = math.sqrt(3)*(side*side)
  return area


Tests:
assert area_tetrahedron(3)==15.588457268119894
assert area_tetrahedron(20)==692.8203230275509
assert area_tetrahedron(10)==173.20508075688772
Task: Write a function to rotate a given list by specified number of items to the right direction.

Solution:
def rotate_right(list1,m,n):
  result =  list1[-(m):]+list1[:-(n)]
  return result


Tests:
assert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],3,4)==[8, 9, 10, 1, 2, 3, 4, 5, 6]
assert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2,2)==[9, 10, 1, 2, 3, 4, 5, 6, 7, 8]
assert rotate_right([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],5,2)==[6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8]
Task: Write a function to check if the given tuple has any none value or not.

Solution:
def check_none(test_tup):
  res = any(map(lambda ele: ele is None, test_tup))
  return (res) 


Tests:
assert check_none((10, 4, 5, 6, None)) == True
assert check_none((7, 8, 9, 11, 14)) == False
assert check_none((1, 2, 3, 4, None)) == True
Task: Write a function to find numbers within a given range where every number is divisible by every digit it contains.

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


Tests:
assert divisible_by_digits(1,22)==[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
assert divisible_by_digits(1,15)==[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15]
assert divisible_by_digits(20,25)==[22, 24]
Task: Write a function to find area of a sector.

Solution:
def sector_area(r,a):
    pi=22/7
    if a >= 360:
        return None
    sectorarea = (pi*r**2) * (a/360)
    return sectorarea


Tests:
assert sector_area(4,45)==6.285714285714286
assert sector_area(9,45)==31.82142857142857
assert sector_area(9,360)==None
Task: Write a function to find the longest common subsequence for the given three string sequence.

Solution:
def lcs_of_three(X, Y, Z, m, n, o): 
	L = [[[0 for i in range(o+1)] for j in range(n+1)] 
		for k in range(m+1)] 
	for i in range(m+1): 
		for j in range(n+1): 
			for k in range(o+1): 
				if (i == 0 or j == 0 or k == 0): 
					L[i][j][k] = 0
				elif (X[i-1] == Y[j-1] and
					X[i-1] == Z[k-1]): 
					L[i][j][k] = L[i-1][j-1][k-1] + 1
				else: 
					L[i][j][k] = max(max(L[i-1][j][k], 
					L[i][j-1][k]), 
									L[i][j][k-1]) 
	return L[m][n][o]


Tests:
assert lcs_of_three('AGGT12', '12TXAYB', '12XBA', 6, 7, 5) == 2
assert lcs_of_three('Reels', 'Reelsfor', 'ReelsforReels', 5, 8, 13) == 5 
assert lcs_of_three('abcd1e2', 'bc12ea', 'bd1ea', 7, 6, 5) == 3
Task: Write a function to put spaces between words starting with capital letters in a given string by using regex.

Solution:
import re
def capital_words_spaces(str1):
  return re.sub(r"(\w)([A-Z])", r"\1 \2", str1)


Tests:
assert capital_words_spaces("Python") == 'Python'
assert capital_words_spaces("PythonProgrammingExamples") == 'Python Programming Examples'
assert capital_words_spaces("GetReadyToBeCodingFreak") == 'Get Ready To Be Coding Freak'
Task: Write a function to sort a given list of strings of numbers numerically.

Solution:
def sort_numeric_strings(nums_str):
    result = [int(x) for x in nums_str]
    result.sort()
    return result


Tests:
assert sort_numeric_strings( ['4','12','45','7','0','100','200','-12','-500'])==[-500, -12, 0, 4, 7, 12, 45, 100, 200]
assert sort_numeric_strings(['2','3','8','4','7','9','8','2','6','5','1','6','1','2','3','4','6','9','1','2'])==[1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8, 9, 9]
assert sort_numeric_strings(['1','3','5','7','1', '3','13', '15', '17','5', '7 ','9','1', '11'])==[1, 1, 1, 3, 3, 5, 5, 7, 7, 9, 11, 13, 15, 17]
Task: Write a function to add the given tuple to the given list.

Solution:
def add_tuple(test_list, test_tup):
  test_list += test_tup
  return (test_list) 


Tests:
assert add_tuple([5, 6, 7], (9, 10)) == [5, 6, 7, 9, 10]
assert add_tuple([6, 7, 8], (10, 11)) == [6, 7, 8, 10, 11]
assert add_tuple([7, 8, 9], (11, 12)) == [7, 8, 9, 11, 12]
Task: Write a function to check if the given array represents min heap or not.

Solution:
def check_min_heap(arr, i):
    if 2 * i + 2 > len(arr):
        return True
    left_child = (arr[i] <= arr[2 * i + 1]) and check_min_heap(arr, 2 * i + 1)
    right_child = (2 * i + 2 == len(arr)) or (arr[i] <= arr[2 * i + 2] 
                                      and check_min_heap(arr, 2 * i + 2))
    return left_child and right_child


Tests:
assert check_min_heap([1, 2, 3, 4, 5, 6], 0) == True
assert check_min_heap([2, 3, 4, 5, 10, 15], 0) == True
assert check_min_heap([2, 10, 4, 5, 3, 15], 0) == False
Task: Write a function to find the nth jacobsthal number.

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


Tests:
assert jacobsthal_num(5) == 11
assert jacobsthal_num(2) == 1
assert jacobsthal_num(4) == 5
Task: Write a function to find minimum k records from tuple list.

Solution:
def min_k(test_list, K):
  res = sorted(test_list, key = lambda x: x[1])[:K]
  return (res) 


Tests:
assert min_k([('Manjeet', 10), ('Akshat', 4), ('Akash', 2), ('Nikhil', 8)], 2) == [('Akash', 2), ('Akshat', 4)]
assert min_k([('Sanjeev', 11), ('Angat', 5), ('Akash', 3), ('Nepin', 9)], 3) == [('Akash', 3), ('Angat', 5), ('Nepin', 9)]
assert min_k([('tanmay', 14), ('Amer', 11), ('Ayesha', 9), ('SKD', 16)], 1) == [('Ayesha', 9)]
Task: Write a function to find common index elements from three lists.

Solution:
def extract_index_list(l1, l2, l3):
    result = []
    for m, n, o in zip(l1, l2, l3):
        if (m == n == o):
            result.append(m)
    return result


Tests:
assert extract_index_list([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7])==[1, 7]
assert extract_index_list([1, 1, 3, 4, 5, 6, 7],[0, 1, 2, 3, 4, 6, 5],[0, 1, 2, 3, 4, 6, 7])==[1, 6]
assert extract_index_list([1, 1, 3, 4, 6, 5, 6],[0, 1, 2, 3, 4, 5, 7],[0, 1, 2, 3, 4, 5, 7])==[1, 5]
Task: Write a function to find the second smallest number in a list.

Solution:
def second_smallest(numbers):
  if (len(numbers)<2):
    return
  if ((len(numbers)==2)  and (numbers[0] == numbers[1]) ):
    return
  dup_items = set()
  uniq_items = []
  for x in numbers:
    if x not in dup_items:
      uniq_items.append(x)
      dup_items.add(x)
  uniq_items.sort()    
  return  uniq_items[1] 


Tests:
assert second_smallest([1, 2, -8, -2, 0, -2])==-2
assert second_smallest([1, 1, -0.5, 0, 2, -2, -2])==-0.5
assert second_smallest([2,2])==None