mr44/mbsearch huggingface dataset:
Task: Write a function to generate all sublists of a given list.

Solution:
from itertools import combinations
def sub_lists(my_list):
	subs = []
	for i in range(0, len(my_list)+1):
	  temp = [list(x) for x in combinations(my_list, i)]
	  if len(temp)>0:
	    subs.extend(temp)
	return subs


Tests:
assert sub_lists([10, 20, 30, 40])==[[], [10], [20], [30], [40], [10, 20], [10, 30], [10, 40], [20, 30], [20, 40], [30, 40], [10, 20, 30], [10, 20, 40], [10, 30, 40], [20, 30, 40], [10, 20, 30, 40]]
assert sub_lists(['X', 'Y', 'Z'])==[[], ['X'], ['Y'], ['Z'], ['X', 'Y'], ['X', 'Z'], ['Y', 'Z'], ['X', 'Y', 'Z']]
assert sub_lists([1,2,3])==[[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]
Task: Write a function to check whether the given string is ending with only alphanumeric characters or not using regex.

Solution:
import re 
regex = '[a-zA-z0-9]$'
def check_alphanumeric(string): 
	if(re.search(regex, string)): 
		return ("Accept") 
	else: 
		return ("Discard") 


Tests:
assert check_alphanumeric("dawood@") == 'Discard'
assert check_alphanumeric("skdmsam326") == 'Accept'
assert check_alphanumeric("cooltricks@") == 'Discard'
Task: Write a function to find all anagrams of a string in a given list of strings using lambda function.

Solution:
from collections import Counter 
def anagram_lambda(texts,str):
  result = list(filter(lambda x: (Counter(str) == Counter(x)), texts)) 
  return result


Tests:
assert anagram_lambda(["bcda", "abce", "cbda", "cbea", "adcb"],"abcd")==['bcda', 'cbda', 'adcb']
assert anagram_lambda(["recitals"," python"], "articles" )==["recitals"]
assert anagram_lambda([" keep"," abcdef"," xyz"]," peek")==[" keep"]
Task: Write a function to find the occurrences of n most common words in a given text.

Solution:
from collections import Counter
import re
def n_common_words(text,n):
  words = re.findall('\w+',text)
  n_common_words= Counter(words).most_common(n)
  return list(n_common_words)


Tests:
assert n_common_words("python is a programming language",1)==[('python', 1)]
assert n_common_words("python is a programming language",1)==[('python', 1)]
assert n_common_words("python is a programming language",5)==[('python', 1),('is', 1), ('a', 1), ('programming', 1), ('language', 1)]
Task: Write a function to find the length of the longest sub-sequence such that elements in the subsequences are consecutive integers.

Solution:
def find_longest_conseq_subseq(arr, n): 
	ans = 0
	count = 0
	arr.sort() 
	v = [] 
	v.append(arr[0]) 
	for i in range(1, n): 
		if (arr[i] != arr[i - 1]): 
			v.append(arr[i]) 
	for i in range(len(v)): 
		if (i > 0 and v[i] == v[i - 1] + 1): 
			count += 1
		else: 
			count = 1
		ans = max(ans, count) 
	return ans 


Tests:
assert find_longest_conseq_subseq([1, 2, 2, 3], 4) == 3
assert find_longest_conseq_subseq([1, 9, 3, 10, 4, 20, 2], 7) == 4
assert find_longest_conseq_subseq([36, 41, 56, 35, 44, 33, 34, 92, 43, 32, 42], 11) == 5
Task: Write a function to find palindromes in a given list of strings using lambda function.

Solution:
def palindrome_lambda(texts):
  result = list(filter(lambda x: (x == "".join(reversed(x))), texts))
  return result


Tests:
assert palindrome_lambda(["php", "res", "Python", "abcd", "Java", "aaa"])==['php', 'aaa']
assert palindrome_lambda(["abcd", "Python", "abba", "aba"])==['abba', 'aba']
assert palindrome_lambda(["abcd", "abbccbba", "abba", "aba"])==['abbccbba', 'abba', 'aba']
Task: Write a function to print n-times a list using map function.

Solution:
def ntimes_list(nums,n):
    result = map(lambda x:n*x, nums) 
    return list(result)


Tests:
assert ntimes_list([1, 2, 3, 4, 5, 6, 7],3)==[3, 6, 9, 12, 15, 18, 21]
assert ntimes_list([1, 2, 3, 4, 5, 6, 7],4)==[4, 8, 12, 16, 20, 24, 28]
assert ntimes_list([1, 2, 3, 4, 5, 6, 7],10)==[10, 20, 30, 40, 50, 60, 70]
Task: Write a function to check whether the given month name contains 31 days or not.

Solution:
def check_monthnumb(monthname2):
  if(monthname2=="January" or monthname2=="March"or monthname2=="May" or monthname2=="July" or monthname2=="Augest" or monthname2=="October" or monthname2=="December"):
    return True
  else:
    return False


Tests:
assert check_monthnumb("February")==False
assert check_monthnumb("January")==True
assert check_monthnumb("March")==True
Task: Write a python function to add a minimum number such that the sum of array becomes even.

Solution:
def min_Num(arr,n):  
    odd = 0
    for i in range(n): 
        if (arr[i] % 2): 
            odd += 1 
    if (odd % 2): 
        return 1
    return 2


Tests:
assert min_Num([1,2,3,4,5,6,7,8,9],9) == 1
assert min_Num([1,2,3,4,5,6,7,8],8) == 2
assert min_Num([1,2,3],3) == 2
Task: Write a python function to find the length of the last word in a given string.

Solution:
def length_Of_Last_Word(a): 
    l = 0
    x = a.strip() 
    for i in range(len(x)): 
        if x[i] == " ": 
            l = 0
        else: 
            l += 1
    return l 


Tests:
assert length_Of_Last_Word("python language") == 8
assert length_Of_Last_Word("PHP") == 3
assert length_Of_Last_Word("") == 0
Task: Write a function to remove sublists from a given list of lists, which are outside a given range.

Solution:
def remove_list_range(list1, leftrange, rigthrange):
   result = [i for i in list1 if (min(i)>=leftrange and max(i)<=rigthrange)]
   return result


Tests:
assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],13,17)==[[13, 14, 15, 17]]
assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],1,3)==[[2], [1, 2, 3]]
assert remove_list_range([[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7], [9, 11], [13, 14, 15, 17]],0,7)==[[2], [0], [1, 2, 3], [0, 1, 2, 3, 6, 7]]
Task: Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.

Solution:
def sum_positivenum(nums):
  sum_positivenum = list(filter(lambda nums:nums>0,nums))
  return sum(sum_positivenum)


Tests:
assert sum_positivenum([2, 4, -6, -9, 11, -12, 14, -5, 17])==48
assert sum_positivenum([10,15,-14,13,-18,12,-20])==50
assert sum_positivenum([19, -65, 57, 39, 152,-639, 121, 44, 90, -190])==522
Task: Write a python function to check whether the given strings are rotations of each other or not.

Solution:
def are_Rotations(string1,string2): 
    size1 = len(string1) 
    size2 = len(string2) 
    temp = '' 
    if size1 != size2: 
        return False
    temp = string1 + string1 
    if (temp.count(string2)> 0): 
        return True
    else: 
        return False


Tests:
assert are_Rotations("abc","cba") == False
assert are_Rotations("abcd","cdba") == False
assert are_Rotations("abacd","cdaba") == True
Task: Write a function to check if a nested list is a subset of another nested list.

Solution:
def check_subset(list1,list2): 
    return all(map(list1.__contains__,list2)) 


Tests:
assert check_subset([[1, 3], [5, 7], [9, 11], [13, 15, 17]] ,[[1, 3],[13,15,17]])==True
assert check_subset([[1, 2], [2, 3], [3, 4], [5, 6]],[[3, 4], [5, 6]])==True
assert check_subset([[[1, 2], [2, 3]], [[3, 4], [5, 7]]],[[[3, 4], [5, 6]]])==False
Task: Write a function to solve the fibonacci sequence using recursion.

Solution:
def fibonacci(n):
  if n == 1 or n == 2:
    return 1
  else:
    return (fibonacci(n - 1) + (fibonacci(n - 2)))


Tests:
assert fibonacci(7) == 13
assert fibonacci(8) == 21
assert fibonacci(9) == 34
Task: Write a python function to check if the string is a concatenation of another string.

Solution:
def check_Concat(str1,str2):
    N = len(str1)
    M = len(str2)
    if (N % M != 0):
        return False
    for i in range(N):
        if (str1[i] != str2[i % M]):
            return False         
    return True


Tests:
assert check_Concat("abcabcabc","abc") == True
assert check_Concat("abcab","abc") == False
assert check_Concat("aba","ab") == False
Task: Write a function to find the minimum difference in the tuple pairs of given tuples.

Solution:
def min_difference(test_list):
  temp = [abs(b - a) for a, b in test_list]
  res = min(temp)
  return (res) 


Tests:
assert min_difference([(3, 5), (1, 7), (10, 3), (1, 2)]) == 1
assert min_difference([(4, 6), (12, 8), (11, 4), (2, 13)]) == 2
assert min_difference([(5, 17), (3, 9), (12, 5), (3, 24)]) == 6
Task: Write a python function to find lcm of two positive integers.

Solution:
def lcm(x, y):
   if x > y:
       z = x
   else:
       z = y
   while(True):
       if((z % x == 0) and (z % y == 0)):
           lcm = z
           break
       z += 1
   return lcm


Tests:
assert lcm(4,6) == 12
assert lcm(15,17) == 255
assert lcm(2,6) == 6
Task: Write a python function to sort the given string.

Solution:
def sort_String(str) : 
    str = ''.join(sorted(str)) 
    return (str) 


Tests:
assert sort_String("cba") == "abc"
assert sort_String("data") == "aadt"
assert sort_String("zxy") == "xyz"
Task: Write a function to check if the given tuple contains only k elements.

Solution:
def check_tuples(test_tuple, K):
  res = all(ele in K for ele in test_tuple)
  return (res) 


Tests:
assert check_tuples((3, 5, 6, 5, 3, 6),[3, 6, 5]) == True
assert check_tuples((4, 5, 6, 4, 6, 5),[4, 5, 6]) == True
assert check_tuples((9, 8, 7, 6, 8, 9),[9, 8, 1]) == False
Task: Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex.

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


Tests:
assert text_match("aabbbbd") == 'Not matched!'
assert text_match("aabAbbbc") == 'Not matched!'
assert text_match("accddbbjjjb") == 'Found a match!'
Task: Write a python function to find number of solutions in quadratic equation.

Solution:
def Check_Solution(a,b,c) : 
    if ((b*b) - (4*a*c)) > 0 : 
        return ("2 solutions") 
    elif ((b*b) - (4*a*c)) == 0 : 
        return ("1 solution") 
    else : 
        return ("No solutions") 


Tests:
assert Check_Solution(2,5,2) == "2 solutions"
assert Check_Solution(1,1,1) == "No solutions"
assert Check_Solution(1,2,1) == "1 solution"
Task: Write a function to find the sum of first even and odd number of a given list.

Solution:
def sum_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)


Tests:
assert sum_even_odd([1,3,5,7,4,1,6,8])==5
assert sum_even_odd([1,2,3,4,5,6,7,8,9,10])==3
assert sum_even_odd([1,5,7,9,10])==11
Task: Write a function to caluclate perimeter of a parallelogram.

Solution:
def parallelogram_perimeter(b,h):
  perimeter=2*(b*h)
  return perimeter


Tests:
assert parallelogram_perimeter(10,20)==400
assert parallelogram_perimeter(15,20)==600
assert parallelogram_perimeter(8,9)==144
Task: Write a function to find numbers divisible by m and n from a list of numbers using lambda function.

Solution:
def div_of_nums(nums,m,n):
 result = list(filter(lambda x: (x % m == 0 and x % n == 0), nums)) 
 return result


Tests:
assert div_of_nums([19, 65, 57, 39, 152, 639, 121, 44, 90, 190],2,4)==[ 152,44]
assert div_of_nums([1, 2, 3, 5, 7, 8, 10],2,5)==[10]
assert div_of_nums([10,15,14,13,18,12,20],10,5)==[10,20]
Task: Write a python function to check whether all the bits are within a given range or not.

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


Tests:
assert all_Bits_Set_In_The_Given_Range(10,2,1) == True 
assert all_Bits_Set_In_The_Given_Range(5,2,4) == False
assert all_Bits_Set_In_The_Given_Range(22,2,3) == True
Task: Write a python function to check whether the two given strings are isomorphic to each other or not.

Solution:
def is_Isomorphic(str1,str2):          
    dict_str1 = {}
    dict_str2 = {}
    for i, value in enumerate(str1):
        dict_str1[value] = dict_str1.get(value,[]) + [i]        
    for j, value in enumerate(str2):
        dict_str2[value] = dict_str2.get(value,[]) + [j]
    if sorted(dict_str1.values()) == sorted(dict_str2.values()):
        return True
    else:
        return False


Tests:
assert is_Isomorphic("paper","title") == True
assert is_Isomorphic("ab","ba") == True
assert is_Isomorphic("ab","aa") == False
Task: Write a function to add all the numbers in a list and divide it with the length of the list.

Solution:
def sum_num(numbers):
    total = 0
    for x in numbers:
        total += x
    return total/len(numbers) 


Tests:
assert sum_num((8, 2, 3, 0, 7))==4.0
assert sum_num((-10,-20,-30))==-20.0
assert sum_num((19,15,18))==17.333333333333332
Task: Write a python function to check whether the given number is odd or not using bitwise operator.

Solution:
def is_odd(n) : 
    if (n^1 == n-1) :
        return True; 
    else :
        return False; 


Tests:
assert is_odd(5) == True
assert is_odd(6) == False
assert is_odd(7) == True
Task: Write a function to substract the elements of the given nested tuples.

Solution:
def substract_elements(test_tup1, test_tup2):
  res = tuple(tuple(a - b for a, b in zip(tup1, tup2))
   for tup1, tup2 in zip(test_tup1, test_tup2))
  return (res) 


Tests:
assert substract_elements(((1, 3), (4, 5), (2, 9), (1, 10)), ((6, 7), (3, 9), (1, 1), (7, 3))) == ((-5, -4), (1, -4), (1, 8), (-6, 7))
assert substract_elements(((13, 4), (14, 6), (13, 10), (12, 11)), ((19, 8), (14, 10), (12, 2), (18, 4))) == ((-6, -4), (0, -4), (1, 8), (-6, 7))
assert substract_elements(((19, 5), (18, 7), (19, 11), (17, 12)), ((12, 9), (17, 11), (13, 3), (19, 5))) == ((7, -4), (1, -4), (6, 8), (-2, 7))
Task: Write a function to reverse each list in a given list of lists.

Solution:
def reverse_list_lists(lists):
    for l in lists:
        l.sort(reverse = True)
    return lists 


Tests:
assert reverse_list_lists([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])==[[4, 3, 2, 1], [8, 7, 6, 5], [12, 11, 10, 9], [16, 15, 14, 13]]
assert reverse_list_lists([[1,2],[2,3],[3,4]])==[[2,1],[3,2],[4,3]]
assert reverse_list_lists([[10,20],[30,40]])==[[20,10],[40,30]]
Task: Write a python function to find the index of an extra element present in one sorted array.

Solution:
def find_Extra(arr1,arr2,n) : 
    for i in range(0, n) : 
        if (arr1[i] != arr2[i]) : 
            return i 
    return n 


Tests:
assert find_Extra([1,2,3,4],[1,2,3],3) == 3
assert find_Extra([2,4,6,8,10],[2,4,6,8],4) == 4
assert find_Extra([1,3,5,7,9,11],[1,3,5,7,9],5) == 5
Task: Write a python function to check whether the given two numbers have same number of digits or not.

Solution:
def same_Length(A,B): 
    while (A > 0 and B > 0): 
        A = A / 10; 
        B = B / 10; 
    if (A == 0 and B == 0): 
        return True; 
    return False; 


Tests:
assert same_Length(12,1) == False
assert same_Length(2,2) == True
assert same_Length(10,20) == True
Task: Write a function to remove multiple spaces in a string.

Solution:
import re
def remove_spaces(text):
 return (re.sub(' +',' ',text))


Tests:
assert remove_spaces('python  program')==('python program')
assert remove_spaces('python   programming    language')==('python programming language')
assert remove_spaces('python                     program')==('python program')
Task: Write a python function to get the last element of each sublist.

Solution:
def Extract(lst): 
    return [item[-1] for item in lst] 


Tests:
assert Extract([[1, 2, 3], [4, 5], [6, 7, 8, 9]]) == [3, 5, 9]
assert Extract([['x', 'y', 'z'], ['m'], ['a', 'b'], ['u', 'v']]) == ['z', 'm', 'b', 'v']
assert Extract([[1, 2, 3], [4, 5]]) == [3, 5]
Task: Write a function to convert the given string of float type into tuple.

Solution:
def float_to_tuple(test_str):
  res = tuple(map(float, test_str.split(', ')))
  return (res) 


Tests:
assert float_to_tuple("1.2, 1.3, 2.3, 2.4, 6.5") == (1.2, 1.3, 2.3, 2.4, 6.5)
assert float_to_tuple("2.3, 2.4, 5.6, 5.4, 8.9") == (2.3, 2.4, 5.6, 5.4, 8.9)
assert float_to_tuple("0.3, 0.5, 7.8, 9.4") == (0.3, 0.5, 7.8, 9.4)
Task: Write a function to find the maximum sum of subsequences of given array with no adjacent elements.

Solution:
def max_sum_subseq(A):
    n = len(A)
    if n == 1:
        return A[0]
    look_up = [None] * n
    look_up[0] = A[0]
    look_up[1] = max(A[0], A[1])
    for i in range(2, n):
        look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i])
        look_up[i] = max(look_up[i], A[i])
    return look_up[n - 1]


Tests:
assert max_sum_subseq([1, 2, 9, 4, 5, 0, 4, 11, 6]) == 26
assert max_sum_subseq([1, 2, 9, 5, 6, 0, 5, 12, 7]) == 28
assert max_sum_subseq([1, 3, 10, 5, 6, 0, 6, 14, 21]) == 44
Task: Write a function to sort a list in increasing order by the last element in each tuple from a given list of non-empty tuples.

Solution:
def last(n):
   return n[-1]
def sort_list_last(tuples):
  return sorted(tuples, key=last)


Tests:
assert sort_list_last([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)])==[(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)] 
assert sort_list_last([(9,8), (4, 7), (3,5), (7,9), (1,2)])==[(1,2), (3,5), (4,7), (9,8), (7,9)] 
assert sort_list_last([(20,50), (10,20), (40,40)])==[(10,20),(40,40),(20,50)]
Task: Write a python function to check whether the word is present in a given sentence or not.

Solution:
def is_Word_Present(sentence,word): 
    s = sentence.split(" ") 
    for i in s:  
        if (i == word): 
            return True
    return False


Tests:
assert is_Word_Present("machine learning","machine") == True
assert is_Word_Present("easy","fun") == False
assert is_Word_Present("python language","code") == False
Task: Write a function to extract specified number of elements from a given list, which follow each other continuously.

Solution:
from itertools import groupby 
def extract_elements(numbers, n):
    result = [i for i, j in groupby(numbers) if len(list(j)) == n] 
    return result


Tests:
assert extract_elements([1, 1, 3, 4, 4, 5, 6, 7],2)==[1, 4]
assert extract_elements([0, 1, 2, 3, 4, 4, 4, 4, 5, 7],4)==[4]
assert extract_elements([0,0,0,0,0],5)==[0]
Task: Write a python function to check whether an array can be sorted or not by picking only the corner elements.

Solution:
def check(arr,n): 
    g = 0 
    for i in range(1,n): 
        if (arr[i] - arr[i - 1] > 0 and g == 1): 
            return False
        if (arr[i] - arr[i] < 0): 
            g = 1
    return True


Tests:
assert check([3,2,1,2,3,4],6) == True
assert check([2,1,4,5,1],5) == True
assert check([1,2,2,1,2,3],6) == True
Task: Write a function where a string will start with a specific number.

Solution:
import re
def match_num(string):
    text = re.compile(r"^5")
    if text.match(string):
        return True
    else:
        return False


Tests:
assert match_num('5-2345861')==True
assert match_num('6-2345861')==False
assert match_num('78910')==False
Task: Write a function to find the smallest multiple of the first n numbers.

Solution:
def smallest_multiple(n):
    if (n<=2):
      return n
    i = n * 2
    factors = [number  for number in range(n, 1, -1) if number * 2 > n]
    while True:
        for a in factors:
            if i % a != 0:
                i += n
                break
            if (a == factors[-1] and i % a == 0):
                return i


Tests:
assert smallest_multiple(13)==360360
assert smallest_multiple(2)==2
assert smallest_multiple(1)==1
Task: Write a function to combine two dictionaries by adding values for common keys.

Solution:
from collections import Counter
def add_dict(d1,d2):
   add_dict = Counter(d1) + Counter(d2)
   return add_dict


Tests:
assert add_dict({'a': 100, 'b': 200, 'c':300},{'a': 300, 'b': 200, 'd':400})==({'b': 400, 'd': 400, 'a': 400, 'c': 300}) 
assert add_dict({'a': 500, 'b': 700, 'c':900},{'a': 500, 'b': 600, 'd':900})==({'b': 1300, 'd': 900, 'a': 1000, 'c': 900}) 
assert add_dict({'a':900,'b':900,'d':900},{'a':900,'b':900,'d':900})==({'b': 1800, 'd': 1800, 'a': 1800})
Task: Write a python function to count the total unset bits from 1 to n.

Solution:
def count_Unset_Bits(n) :  
    cnt = 0;  
    for i in range(1,n + 1) : 
        temp = i;  
        while (temp) :  
            if (temp % 2 == 0) : 
                cnt += 1;  
            temp = temp // 2;  
    return cnt;  


Tests:
assert count_Unset_Bits(2) == 1
assert count_Unset_Bits(5) == 4
assert count_Unset_Bits(14) == 17
Task: Write a function to return true if the given number is even else return false.

Solution:
def even_num(x):
  if x%2==0:
     return True
  else:
    return False


Tests:
assert even_num(13.5)==False
assert even_num(0)==True
assert even_num(-9)==False
Task: Write a python function to find the sum of squares of binomial co-efficients.

Solution:
def factorial(start,end): 
    res = 1 
    for i in range(start,end + 1): 
        res *= i      
    return res 
def sum_of_square(n): 
   return int(factorial(n + 1, 2 * n)  /factorial(1, n)) 


Tests:
assert sum_of_square(4) == 70
assert sum_of_square(5) == 252
assert sum_of_square(2) == 6
Task: Write a function to extract year, month and date from a url by using regex.

Solution:
import re
def extract_date(url):
        return re.findall(r'/(\d{4})/(\d{1,2})/(\d{1,2})/', url)


Tests:
assert extract_date("https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-norman-tells-author/") == [('2016', '09', '02')]
assert extract_date("https://www.indiatoday.in/movies/celebrities/story/wp/2020/11/03/odeof-sushant-singh-rajput-s-death-his-brother-in-law-shares-advice-for-fans-1749646/") == [('2020', '11', '03')]
assert extract_date("https://economictimes.indiatimes.com/news/economy/2020/12/29/finance/pension-assets-under-pfrda-touch-rs-5-32-lakh-crore/articleshow/79736619.cms") == [('2020', '12', '29')]
Task: Write a function to print the first n lucky numbers.

Solution:
def lucky_num(n):
 List=range(-1,n*n+9,2)
 i=2
 while List[i:]:List=sorted(set(List)-set(List[List[i]::List[i]]));i+=1
 return List[1:n+1]


Tests:
assert lucky_num(10)==[1, 3, 7, 9, 13, 15, 21, 25, 31, 33] 
assert lucky_num(5)==[1, 3, 7, 9, 13]
assert lucky_num(8)==[1, 3, 7, 9, 13, 15, 21, 25]
Task: Write a function to find the fixed point in the given array.

Solution:
def find_fixed_point(arr, n): 
	for i in range(n): 
		if arr[i] is i: 
			return i 
	return -1


Tests:
assert find_fixed_point([-10, -1, 0, 3, 10, 11, 30, 50, 100],9) == 3
assert find_fixed_point([1, 2, 3, 4, 5, 6, 7, 8],8) == -1
assert find_fixed_point([0, 2, 5, 8, 17],5) == 0
Task: Write a function to find the previous palindrome of a specified number.

Solution:
def previous_palindrome(num):
    for x in range(num-1,0,-1):
        if str(x) == str(x)[::-1]:
            return x


Tests:
assert previous_palindrome(99)==88
assert previous_palindrome(1221)==1111
assert previous_palindrome(120)==111
Task: Write a function to validate a gregorian date.

Solution:
import datetime
def check_date(m, d, y):
    try:
        m, d, y = map(int, (m, d, y))
        datetime.date(y, m, d)
        return True
    except ValueError:
        return False


Tests:
assert check_date(11,11,2002)==True
assert check_date(13,11,2002)==False
assert check_date('11','11','2002')==True
Task: Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm.

Solution:
def maximum_product(nums):
    import heapq
    a, b = heapq.nlargest(3, nums), heapq.nsmallest(2, nums)
    return max(a[0] * a[1] * a[2], a[0] * b[0] * b[1])


Tests:
assert maximum_product( [12, 74, 9, 50, 61, 41])==225700
assert maximum_product([25, 35, 22, 85, 14, 65, 75, 25, 58])==414375
assert maximum_product([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1])==2520