This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Anran Yang
Recipients Anran Yang, docs@python
Date 2017-09-25.12:11:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1506341496.0.0.82723851335.issue31575@psf.upfronthosting.co.za>
In-reply-to
Content
At the end of the Functional Programming HOWTO document (https://docs.python.org/3.7/howto/functional.html) the usage of reduce/lambda/for loops are compared and discussed. However, the example for reduce seems sub-optimal and thus the discussion is not that efficient. The example:

total = functools.reduce(lambda a, b: (0, a[1] + b[1]), items)[1]

could be changed to:

total = functools.reduce(lambda total, item: total + item[1], items, 0)

which is much more readable and is actually not much inferior to the loop one (though the sum approach is still more concise).
History
Date User Action Args
2017-09-25 12:11:36Anran Yangsetrecipients: + Anran Yang, docs@python
2017-09-25 12:11:35Anran Yangsetmessageid: <1506341496.0.0.82723851335.issue31575@psf.upfronthosting.co.za>
2017-09-25 12:11:35Anran Yanglinkissue31575 messages
2017-09-25 12:11:35Anran Yangcreate