Skip to content

Instantly share code, notes, and snippets.

@ehedaoo
Created May 9, 2017 04:45
Show Gist options
  • Save ehedaoo/082ba052debfa6c4bff6ef4fd4b10c3e to your computer and use it in GitHub Desktop.
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.
# 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