4 ms·
> why one wouldn’t just create a defaultdict(list)? One shouldn't even do that. groupby is supposed to assume that the input is already sorted by the given key
by pdonis 6y ago
> why one wouldn’t just create a defaultdict(list)?
One shouldn't even do that. groupby is supposed to assume that the input is already sorted by the given key, so it can be implemented as a generator. What's more, it should be implemented as a generator (that's the way the Python stlib's itertools.groupby does it), to avoid having to realize the entire iterable at once.
- ciupicri 6y agoThe Toolz version has a different purpose than the one from Python's stdlib (itertools). One is unsorted input, while the other one is for sorted input. The Toolz version is not a replacement and the documentation states > Not to be confused with ``itertools.groupby``