3 ms·
The risk of identifier collisions with itemgetter seems really low. I've never had a problem with from operator import itemgetter sort(values, key=itemgett
by dpwm 8y ago
The risk of identifier collisions with itemgetter seems really low. I've never had a problem with
from operator import itemgetter
sort(values, key=itemgetter(2))
The main problem is the effort of typing the import, but last time I checked itemgetter performed a bit better.
To me it depends on what I'm writing. If it's a library where performance will matter then it's the itemgetter approach. If it's a script it will be the lambda.