I'm trying to make a program that removes everything that is not in list x
from list a
. But it only removes even numbers from the list a
. Here's my code:
n = int(input())
a = []
for i in range(1, n + 1):
a.append(str(i))
x = [s for s in input().split()]
for o in a:
if o not in x:
a.remove(o)
print(a)