|
| 1 | +# Take two lists, say for example these two: |
| 2 | + |
| 3 | +# a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] |
| 4 | +# b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] |
| 5 | +# and write a program that returns a list that contains only the elements that are common between the |
| 6 | +# lists (without duplicates). Make sure your program works on two lists of different sizes. |
| 7 | + |
| 8 | +a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 13, 13, 13, 13, 12] |
| 9 | +b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13, 13] |
| 10 | +c = [] |
| 11 | +for n in b: |
| 12 | + if n in b: |
| 13 | + if n not in c: |
| 14 | + c.append(n) |
| 15 | +print(c) |
0 commit comments