beginList[j] = 0
// filters actual prime numbers.
ans = [x for x in beginList if x != 0]
// precondition
assert isinstance(ans, list), ""ans" must been from type list"
After Change
primes = [True for x in xrange(N + 1)]
for p in xrange(2, sqrt(N) + 1):
if (primes[p]):
for i in xrange(p*p, N + 1, p):
primes[i] = False