I am using a sieve to return all primes under N
:
def prime_gen(n):
a = [x for x in range(2, n+1)]
for b in range(2, round(n**.5)):
c = 2
while b*c <= n:
if b*c in a:
a.remove(b*c)
c += 1
return(a)
Is the conditional if b*c in a
iterating through the list again? Without using a different algorithm entirely, how do I make this code more efficient and pythonic?