Re:Functools – The Power of Higher-Order Functions in Python
by sfvisser on Friday July 09, 2021 @02:56AM
(#27781113)
It's common in other languages as well (at least Haskell) and a bit surprising at first. However, a `.sortBy(fn).groupBy(fn)` is easy and of similar efficiency and when you actually need the local-only `groupBy()` you're happy it's there.
A bit more expressive overall.
At least it is better than lodash' useless groupBy which creates this weird key value mapping, loses order and converts keys to string and what not.
Re:Functools – The Power of Higher-Order Functions in Python
by zmmmmm on Friday July 09, 2021 @03:07AM
(#27781171)
yep, that's a good example of what I refer to as IKEA assembling your groupby. You need to put something like 3 parts together before it does what you want, and they aren't that intuitive (or they only are in retrospect).
Re:Functools – The Power of Higher-Order Functions in Python
by olejorgenb on Friday July 09, 2021 @06:02AM
(#27782126)
The resulting groups are also iterators which are exhaustible. It's good if you're running group by on a huge dataset to save some memory, but for everyday operations it's another trap to fall into.
Re:Functools – The Power of Higher-Order Functions in Python
by silvester23 on Friday July 09, 2021 @02:37AM
(#27781015)
Yes, for itertools.groupby to work as most people would expect, the data needs to be sorted by the grouping key first. That may obviously cause a significant performance hit.
Re:Functools – The Power of Higher-Order Functions in Python
by orojackson on Friday July 09, 2021 @09:27AM
(#27783446)
Toolz seems to have it.
https://toolz.readthedocs.io/en/latest/streaming-analytics.h...
https://docs.python.org/3/library/itertools.html#itertools.g...