On Wed, Oct 22, 2003, Guido van Rossum wrote: > > I think that for reductions the gains are less clear. The initializer > for the result variable and the call that updates its are no longer > boilerplate, because they vary for each use; plus the name of the > result variable should be chosen carefully because it indicates what > kind of result it is (e.g. a sum or product). So, leaving out the > condition for now, the pattern or idiom is: > > <result> = <initializer> > for <variable> in <iterable>: > <result> = <expression> > > (Where <expression> uses <result> and <variable>.) Actually, even that doesn't quite capture the expressiveness needed, because <expression> needs in some cases to be a sequence of statements and there needs to be an opportunity for a finalizer to run after the for loop (e.g. average()). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "It is easier to optimize correct code than to correct optimized code." --Bill Harlan
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4