Skip to content

Commit babb22d

Browse files
authored
Add more recipe tests. Make the factor recipe a bit faster and clearer. (GH-106817)
1 parent 48956cc commit babb22d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Doc/library/itertools.rst

+8-3
Original file line numberDiff line numberDiff line change
@@ -1049,11 +1049,10 @@ The following recipes have a more mathematical flavor:
10491049
# factor(1_000_000_000_000_403) --> 1000000000000403
10501050
for prime in sieve(math.isqrt(n) + 1):
10511051
while True:
1052-
quotient, remainder = divmod(n, prime)
1053-
if remainder:
1052+
if n % prime:
10541053
break
10551054
yield prime
1056-
n = quotient
1055+
n //= prime
10571056
if n == 1:
10581057
return
10591058
if n > 1:
@@ -1354,6 +1353,12 @@ The following recipes have a more mathematical flavor:
13541353
>>> set(sieve(10_000)).isdisjoint(carmichael)
13551354
True
13561355

1356+
>>> list(factor(99)) # Code example 1
1357+
[3, 3, 11]
1358+
>>> list(factor(1_000_000_000_000_007)) # Code example 2
1359+
[47, 59, 360620266859]
1360+
>>> list(factor(1_000_000_000_000_403)) # Code example 3
1361+
[1000000000000403]
13571362
>>> list(factor(0))
13581363
[]
13591364
>>> list(factor(1))

0 commit comments

Comments
 (0)