Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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.



The 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``




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: