Created
May 9, 2017 04:45
-
-
Save ehedaoo/082ba052debfa6c4bff6ef4fd4b10c3e to your computer and use it in GitHub Desktop.
Take two random lists 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Take two random lists | |
# 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. | |
import random | |
a = random.sample(range(100), 10) | |
b = random.sample(range(100), 15) | |
c = [] | |
print(a) | |
print(b) | |
for num in a: | |
if num in b: | |
c.append(num) | |
print(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment