[Python-ideas] Allow key='attribute_name' to various sorting functions
Antoine Pitrou
solipsis at pitrou.net
Fri Apr 12 10:41:03 CEST 2013
Le Fri, 12 Apr 2013 09:48:57 +1000,
Steven D'Aprano <steve at pearwood.info> a
écrit :
>
> If we allow sorted etc. to guess what the caller wants with strings,
> should it also guess what they want with integers?
>
> key=3 equivalent to key=lambda obj: obj[3]
>
> Hmmm... tempting... that would make sorting tuples by a specific
> field really easy, which is an extremely common use case, and unlike
> strings, there's no ambiguity.
>
>
> So... -1 on allowing key='string' shortcuts, +0 on allowing key=3
> shortcuts.
-1 on both :-)
Regards
Antoine.
More information about the Python-ideas
mailing list