[Python-checkins] [3.12] Add more recipe tests. Make the factor recipe a bit faster and clearer. (GH-106817) (GH-106818)
rhettinger
webhook-mailer at python.org
Sun Jul 16 22:48:01 EDT 2023
https://github.com/python/cpython/commit/9c00dc02cf87d6edecc47586a9aac1fde1517868
commit: 9c00dc02cf87d6edecc47586a9aac1fde1517868
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2023-07-16T21:47:58-05:00
summary:
[3.12] Add more recipe tests. Make the factor recipe a bit faster and clearer. (GH-106817) (GH-106818)
files:
M Doc/library/itertools.rst
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index f88525456ff93..730736bbb59ed 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -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:
@@ -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))
More information about the Python-checkins
mailing list