Skip to content

Commit

Permalink
Add more recipe tests. Make the factor() recipe a bit faster and clea…
Browse files Browse the repository at this point in the history
…rer.
  • Loading branch information
rhettinger committed Jul 17, 2023
1 parent 48956cc commit 94ab7c9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1049,11 +1049,10 @@ The following recipes have a more mathematical flavor:
# factor(1_000_000_000_000_403) --> 1000000000000403
for prime in sieve(math.isqrt(n) + 1):
while True:
quotient, remainder = divmod(n, prime)
if remainder:
if n % prime:
break
yield prime
n = quotient
n //= prime
if n == 1:
return
if n > 1:
Expand Down Expand Up @@ -1354,6 +1353,12 @@ The following recipes have a more mathematical flavor:
>>> set(sieve(10_000)).isdisjoint(carmichael)
True

>>> list(factor(99)) # Code example 1
[3, 3, 11]
>>> list(factor(1_000_000_000_000_007)) # Code example 2
[47, 59, 360620266859]
>>> list(factor(1_000_000_000_000_403)) # Code example 3
[1000000000000403]
>>> list(factor(0))
[]
>>> list(factor(1))
Expand Down

0 comments on commit 94ab7c9

Please sign in to comment.