3 ms·
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
by ciupicri 6y ago
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#Avoiding_dots https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Avo......