New submission from Anran Yang: 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). ---------- assignee: docs@python components: Documentation messages: 302950 nosy: Anran Yang, docs@python priority: normal severity: normal status: open title: Functional Programming HOWTO sub-optimal example for reduce versions: Python 3.5, Python 3.6, Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue31575> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com