A one-liner that returns the list of prime numbers up to n. The inner lambda is the sieve.
1 2 3 4 | primes = lambda n: filter(lambda x, m=set(): not (x in m or m.update(range(x,n,x))), range(2,n))
>>> primes(13)
[2, 3, 5, 7, 11]
|
Tags: sieve
A one-liner that returns the list of prime numbers up to n. The inner lambda is the sieve.
1 2 3 4 | primes = lambda n: filter(lambda x, m=set(): not (x in m or m.update(range(x,n,x))), range(2,n))
>>> primes(13)
[2, 3, 5, 7, 11]
|