-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement]: Add operator replacement for operator.itemgetter and operator.attrgetter #321
Comments
I think this would be a good addition, especially if you are doing something like this: a = sorted(b, key=lambda x: (x[3], x[2], x[1], x[0]))
# vs
a = sorted(b, key=itemgetter(3, 2, 1, 0)) One concern I have is that |
Yeah, they could maybe different rules then or something. itemgetter seems to have no real downsides though. I could imagine someone may want to enable the itemgetter rule, but not the attrgetter. |
Thank you @Skylion007 for opening this! |
Overview
Expand operator replacement rules with operator.itemgetter / operator.attrgetter
Proposal
Mostly people do not know that operator.itemgetter and operator.attrgetter exist. They can be often very useful especially for sorting. For example:
becomes
This becomes even more important in complex situations where you accessing multiple attributes or items at once. See https://stackoverflow.com/questions/11287207/why-should-i-use-operator-itemgetterx-instead-of-x for examples where it can help.
The text was updated successfully, but these errors were encountered: