Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit babb22d

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

File tree

Expand file treeCollapse file tree

1 file changed

+8
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-3
lines changed

‎Doc/library/itertools.rst

Copy file name to clipboardExpand all lines: Doc/library/itertools.rst
+8-3Lines changed: 8 additions & 3 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.