# Answer 1
def is_sublist(list,sublist):
if len(sublist) == 0:
return True
if len(list) == 0:
return False
if list[:len(sublist)] == sublist:
return True
return is_sublist(list[1:],sublist)
= [2,4,3,5,7]
a = [4,3]
b = [3,7]
c
print("Sublist is ",is_sublist(a,b))
print("Sublist is ",is_sublist(a,c))
Sublist is True
Sublist is False
# Answer 2
=["Red","Green","Orange","White"]
color1=["Black","Green","White","Pink"]
color2= set(color1)
set1 = set(color2)
set2 = set1.intersection(set2)
common_items print(set1)
print(set2)
print("Common items in the list are",common_items)
{'Green', 'Orange', 'White', 'Red'}
{'Green', 'Black', 'White', 'Pink'}
Common items in the list are {'Green', 'White'}
# Answer 3
=[1,2,3,4]
list1=[1,2]
list2= [x for x in list1 if x not in list2]
difference print("Difference between two lists is",difference)
Difference between two lists is [3, 4]
# Answer 4
import numpy as np
def generate_permutations(list):
if len(list) == 0:
return [[]]
= []
permutations for i in range(len(list)):
= np.delete(list, i)
rest for p in generate_permutations(rest):
list[i]] + p)
permutations.append([
return permutations
= [1, 2, 3]
input_list = generate_permutations(np.array(input_list))
permutations
print("The permutations of the",input_list," are - ",[list(p) for p in permutations])
The permutations of the [1, 2, 3] are - [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
# Answer 5
=[10,20,30,20,10,50,60,40,80,50,40]
a = set(a)
remove_duplicateprint("The elements after removing the duplicate are", remove_duplicate)
The elements after removing the duplicate are {40, 10, 80, 50, 20, 60, 30}