[Python-checkins] r47048 - sandbox/trunk/Doc/functional.rst
andrew.kuchling
python-checkins at python.org
Tue Jun 20 20:23:43 CEST 2006
Author: andrew.kuchling
Date: Tue Jun 20 20:23:43 2006
New Revision: 47048
Modified:
sandbox/trunk/Doc/functional.rst
Log:
Tweak example
Modified: sandbox/trunk/Doc/functional.rst
==============================================================================
--- sandbox/trunk/Doc/functional.rst (original)
+++ sandbox/trunk/Doc/functional.rst Tue Jun 20 20:23:43 2006
@@ -830,10 +830,15 @@
Personally I try to avoid lambdas, favoring short nested
``def`` statements like this::
- def combine_freq (a, b):
- return 0, a[1] + b[1]
+ def output_total_freq (items):
+ """Takes a list of (element, frequency count) tuples
+ and returns the total number of occurrences.
+ """
- print reduce(combine_freq, items)[1]
+ def combine (a, b):
+ return 0, a[1] + b[1]
+
+ return reduce(combine_freq, items)[1]
You might disagree that this style is better.
More information about the Python-checkins
mailing list