Sort comprehensions? (Re: longest sequence)

Ian Bicking ianb at colorstudy.com
Tue Feb 18 19:12:20 EST 2003


On Tue, 2003-02-18 at 18:02, Greg Ewing (using news.cis.dfn.de) wrote:
> Maybe list comprehensions should have a sorting clause:
> 
>    [x for x in stuff sortedby x.key]

That would be great!  Sorting kind of sucks right now -- you have to
make some non-intuitive sort function for most cases (or use an
equivalent lambda), when almost always you are just trying to say that
you want to sort on some attribute or key, not the object itself.

Plus there's the common complaint that .sort() doesn't return a value,
which frequently means you have to create a temporary variable where you
otherwise wouldn't have, or you have to create an annoyingly small idiom
by defining your own sorted() function.  This would solve that.

-- 
Ian Bicking  ianb at colorstudy.com  http://colorstudy.com
4869 N. Talman Ave., Chicago, IL 60625  /  773-275-7241
"There is no flag large enough to cover the shame of 
 killing innocent people" -- Howard Zinn






More information about the Python-list mailing list