Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 75cd865 commit d3ed992Copy full SHA for d3ed992
1 file changed
Doc/library/itertools.rst
@@ -1030,13 +1030,16 @@ The following recipes have a more mathematical flavor:
1030
def sieve(n):
1031
"Primes less than n."
1032
# sieve(30) --> 2 3 5 7 11 13 17 19 23 29
1033
+ if n > 2:
1034
+ yield 2
1035
+ start = 3
1036
data = bytearray((0, 1)) * (n // 2)
- data[:3] = 0, 0, 0
1037
limit = math.isqrt(n) + 1
- for p in compress(range(limit), data):
1038
+ for p in iter_index(data, 1, start, limit):
1039
+ yield from iter_index(data, 1, start, p*p)
1040
data[p*p : n : p+p] = bytes(len(range(p*p, n, p+p)))
- data[2] = 1
- return iter_index(data, 1) if n > 2 else iter([])
1041
+ start = p*p
1042
+ yield from iter_index(data, 1, start)
1043
1044
def factor(n):
1045
"Prime factors of n."
0 commit comments