def sieve(n):
    if n < 2:
        return []
    not_prime = set()
    prime = [2]
    for i in range(3, n+1, 2):
        if i not in not_prime:
            prime.append(i)
            not_prime.update(range(i*i, n+1, i))
    return prime

def sieve(n):
    return list(primes(n))


def primes(n):
    if n < 2:
        raise StopIteration
    yield 2
    not_prime = set()
    for i in range(3, n+1, 2):
        if i not in not_prime:
            not_prime.update(range(i*i, n+1, i))
            yield i

Revert back to a generator - it's actually slight faster
Revert back to a generator - it's actually slight faster
