Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Improve speed. Reduce auxiliary memory to 16.6% of the main array. (G…
…H-98294)

(cherry picked from commit 3a639bb)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
  • Loading branch information
rhettinger authored and miss-islington committed Oct 15, 2022
commit f8a14d2089220b84e3f2a327087cab8aaec07fe9
9 changes: 5 additions & 4 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -822,12 +822,13 @@ which incur interpreter overhead.
def sieve(n):
"Primes less than n"
# sieve(30) --> 2 3 5 7 11 13 17 19 23 29
data = bytearray([1]) * n
data[:2] = 0, 0
data = bytearray((0, 1)) * (n // 2)
data[:3] = 0, 0, 0
limit = math.isqrt(n) + 1
for p in compress(range(limit), data):
data[p*p : n : p] = bytearray(len(range(p*p, n, p)))
return iter_index(data, 1)
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([])

def flatten(list_of_lists):
"Flatten one level of nesting"
Expand Down