Skip to content

Instantly share code, notes, and snippets.

@ehedaoo
Created May 9, 2017 04:44
Show Gist options
  • Save ehedaoo/4db147950300b8f890a848a2d41ae4d2 to your computer and use it in GitHub Desktop.
Save ehedaoo/4db147950300b8f890a848a2d41ae4d2 to your computer and use it in GitHub Desktop.
Take two 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 lists, say for example these two:
# a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
# b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
# 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.
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
c = []
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