Created
January 21, 2017 14:06
-
-
Save mariopepe/98e83da30198acfa11a34a80397b94ae to your computer and use it in GitHub Desktop.
05 List Overlap
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
# 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. | |
# exercise from http://www.practicepython.org/exercise/2014/03/05/05-list-overlap.html | |
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 = [] | |
# Create list c | |
for num in a: | |
if num in b: | |
c.append(num) | |
# convert list c to 'set' to remove duplicates | |
c = set(c) | |
# reconvert to list | |
c = list(c) | |
print(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment