-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx10.py
More file actions
18 lines (13 loc) · 733 Bytes
/
Ex10.py
File metadata and controls
18 lines (13 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
'''This week’s exercise is going to be revisiting an old exercise (see Exercise 5), except require the solution in a different way.
Take two lists, say for example these two:
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
and write a program that returns a list that contains only the elements that are common between the lists (without duplicates).
Make sure your program works on two lists of different sizes.'''
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
if len(b) > len(a):
c = [num for num in b if num in a]
else:
c= [num for num in a if num in b]
print(f"Unique elements between both the lists {c}")