3 ms·
reduce() is still available in the functools module. I highly recommend to become familiar with the functools, itertools and collections modules to anybody usi
by dorfsmay 8y ago
reduce() is still available in the functools module.
I highly recommend to become familiar with the functools, itertools and collections modules to anybody using Python and not using them regularly.
- stochastic_monk 8y agoI’ve really come to miss reduce in Python’s builtins since std::accumulate has become a staple in my C++ development. It seems surprising that with Python 3’s increased support for functional concepts, it would relegate reduce to the standard library.
- masklinn 8y agoNot really, increasing support for functional concept was never a goal of Python 3 (or at all), it was mostly incidental and it did regress in other ways than just shoving the (relatively little used due to the existence of min/max/any/all) out of the builtins e.g. while extended unpacking was added, unpacking iterable function parameters was removed.
- geezerjay 8y ago+1 for the std::accumulate reference, and I'll add an honorable mention of std::transform which since C++17 also runs in parallel.
- _asummers 8y agoThis is broadly true across language. In Java, it was Collections, List, Elixir it's Enum, Python is your mentioned stdlib namespaces. Knowing your collection-ey stdlib functions will only help your code be more idiomatic and likely performant.
- black-tea 8y agoIndeed, those modules are essential for doing anything in Python beyond small scripts.