Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def list_overlap(num_range, random_elements):
- a = random.sample(range(num_range), random.randint(0, random_elements))
- b = random.sample(range(num_range), random.randint(0, random_elements))
- c = []
- d = []
- result = []
- # to determine the longer list
- if len(a) > len(b):
- c = a
- d = b
- else:
- c = b
- d = a
- # to append the common elements
- for i in c:
- if i in d:
- result.append(i)
- print(result)
- list_overlap(20, 15)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement