4 ms·
I generally agree that it's not worth importing operator just to get access to itemgetter. operator module has a few other nice functions though.
by ehsankia 4y ago
I generally agree that it's not worth importing operator just to get access to itemgetter. operator module has a few other nice functions though.
- kzrdude 4y agoWhat's your favourite operator feature?
- Etherlord87 4y agoI'm not the same person, but there's not much in operator module that can't be done by simply using an operator symbol. It's useful to use in e.g. map(), but you could use lambdas instead (for some performance overhead as mentioned). operator.countOf() is perhaps the hardest to reimplement in lambda, as it's more reliable than lambda x: x.count() - for example it will work for dictionary.values() as well.