Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save demian711/9a8e4e3f9969dd2d1c985c8adde01634 to your computer and use it in GitHub Desktop.
Save demian711/9a8e4e3f9969dd2d1c985c8adde01634 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.
import random
a = []
b = []
c = []
for i in range(5):
a.append(random.randrange(1, 100))
for i in range(10):
b.append(random.randrange(1, 100))
print a
print b
for elementa in a:
for elementb in b:
if elementa == elementb:
if elementa not in c:
c.append(elementa)
print c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment