Created
September 18, 2020 16:12
-
-
Save timeowilliams/0b716f1a67437c82f298eca5e64045ee to your computer and use it in GitHub Desktop.
Practice Python 10: Comparing Lists
This file contains hidden or 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
| b = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
| a = [1,1,2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] | |
| c = [] | |
| d = [] | |
| if len(a) > len(b): | |
| for i in a: | |
| if i in b: | |
| c.append(i) | |
| elif len(a) < len(b): | |
| for i in b: | |
| if i in a: | |
| c.append(i) | |
| elif len(a) == len(b): | |
| for i in a: | |
| if i in b: | |
| c.append(i) | |
| print(c) | |
| i = 0 | |
| d = [alpha for alpha in b if alpha in a] | |
| for i in range(len(d)-2): | |
| if d[i] == d[i+1]: | |
| d.remove(d[i]) | |
| print(d) | |
| #d = [alpha for alpha in b if alpha in a and alpha not in b[alpha:]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment