Last active
May 11, 2025 00:59
-
-
Save jorenham/456edb0413539064a26d64f16d2c1ffe to your computer and use it in GitHub Desktop.
Python walrus prime numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools, typing | |
def primes(n: int, /) -> typing.Generator[int]: | |
yield next(sieve := itertools.count(prime := 2)) | |
for _ in range(n): | |
yield (prime := next(sieve := filter(prime.__rmod__, sieve))) |
Author
jorenham
commented
Oct 8, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment