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:
            yield i
        not_prime.update(range(i*i, n, i))

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, i))
    return prime

Switch to more optimal non-generator solution
Switch to more optimal non-generator solution

  def sieve(n):
-     return list(primes(n))
- 
- 
- def primes(n):
      if n < 2:
+         return []
-         raise StopIteration
-     yield 2
      not_prime = set()
+     prime = [2]
      for i in range(3, n+1, 2):
          if i not in not_prime:
-             yield i
+             prime.append(i)
-         not_prime.update(range(i*i, n, i))
+             not_prime.update(range(i*i, n, i))
+     return prime
  
Switch to more optimal non-generator solution
## Code Before:
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:
            yield i
        not_prime.update(range(i*i, n, i))

## Instruction:
Switch to more optimal non-generator solution
## Code After:
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, i))
    return prime
