Hacker News new | past | comments | ask | show | jobs | submit login

It's the avoiding dots pattern [1].

The idea is that referencing the `append` method in the for grouping loop, i.e. doing

    d[key(item)].append(item)
takes more time than rebuilding the _rv_ groups dictionary with lists instead of `append` methods. Of course, a benchmark should be run and see how much longer the input sequence needs to be than the resulting groups, for this to happen.

[1]: https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Avo......




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: