-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5list_overlap.py
More file actions
47 lines (37 loc) · 1.03 KB
/
Copy path5list_overlap.py
File metadata and controls
47 lines (37 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
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.
Extras:
Randomly generate two lists to test this
Write this in one line of Python (don’t worry if you can’t figure this out
at this point - we’ll get to it soon)
"""
import random
a = []
b = []
c = []
d = []
e = []
def overlap():
overlap_list = []
for num in a:
if num in b:
if num in overlap_list:
continue
overlap_list.append(num)
print(overlap_list)
def random_list(length):
names = [a,b,c,d,e]
counter = 0
while counter < len(names):
while length != 0:
names[counter].append(random.randint(0,100))
length -= 1
print(names[counter])
counter += 1
random_list(10)
overlap()