Created
May 23, 2016 21:25
-
-
Save demian711/9a8e4e3f9969dd2d1c985c8adde01634 to your computer and use it in GitHub Desktop.
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 = [] | |
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