0
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]

for i in a:
    if i not in b:
        a.remove(i)
print(a)

Output:

[1, 1, 2, 3, 5, 8, 13, 34, 89]

My question: Why is the code removed only the numbers 21 and 55 from list "a" and not all the not common numbers in both lists (21, 34, 55, 89) from list "a"

Karuch
  • 1
  • 1

0 Answers0