I came across this prime sieve using the enumerate function which I vaguely understand, I understand the general idea behind the code, i.e. turning all the non-prime values in the list of 'True' to 'False' and then out of that creating a prime list. But I'm not exactly sure how to interpret the code after line 5, is is_prime a function or a variable? I'm slightly confused
def prime_sieve(n):
sieve = [True] * n #Generates a list of 'True' of length n
sieve[:2] = [False, False] # 0 and 1 are not primes
primes = []
for prime, is_prime in enumerate(sieve):
if not is_prime:
continue
primes.append(prime)
for not_prime in range(prime*prime, n, prime):
sieve[not_prime] = False
return primes, sieve