I am looking at some code that has a lot of sort calls using comparison functions, and it seems like it should be using key functions.
If you were to change se
As stated by previous commenters, attrgetter is slightly faster, but for a lot of situations the difference is marginal (~microseconds).
Regarding readability, I personally prefer lambda as it's a construct that people will have seen before in different contexts, so it will probably be easier for others to read and understand.
One other caveat is that your IDE should be able to signal a typo on the attr name when using lambda, unlike using attrgetter.
In general I tend to choose the construct that does not require an extra import if the alternative is easy enough to write and read.