Here is my code:
def f(x): return x%2!=0 and x%3!=0
primes = filter(f , range (6,50))
for x in primes:
for a in filter(f, range(2,x-1)):
if x%a == 0:
primes.remove(x);
print(primes)
I get this error:
File "primes.py", line 12, in <module>
primes.remove(x);
ValueError: list.remove(x): x not in list
But the funny thing is if i write like that:
def f(x): return x%2!=0 and x%3
primes = filter(f , range (6,20))
for x in primes:
for a in filter(f, range(2,x-1)):
if x%a == 0:
primes.remove(x);
print(primes)
Why? and how can i fix it?