diff options
author | Raymond Hettinger <python@rcn.com> | 2010-03-28 18:08:15 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2010-03-28 18:08:15 (GMT) |
commit | d282b931a3d7b33fcddff15904b465ec8d54ba8f (patch) | |
tree | f7b23cf7aa1dc03af7c95bebe2674821db474f8d /Doc | |
parent | 5b027f87b5d62943d858082c5af84ab0636c0881 (diff) | |
download | cpython-d282b931a3d7b33fcddff15904b465ec8d54ba8f.zip cpython-d282b931a3d7b33fcddff15904b465ec8d54ba8f.tar.gz cpython-d282b931a3d7b33fcddff15904b465ec8d54ba8f.tar.bz2 |
Add a note on optimizing the itertools recipes for production.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/itertools.rst | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index a978c1a..4f82a27 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -784,3 +784,9 @@ which incur interpreter overhead. except exception: pass +Note, many of the above recipes can be optimized by replacing global lookups +with local variables defined as default values. For example, the +*dotproduct* recipe can be written as:: + + def dotproduct(vec1, vec2, sum=sum, imap=imap, mul=operator.mul): + return sum(imap(mul, vec1, vec2)) |