ok, so how do I return a sorted list without doing it in place

Phlip phlip_cpp at my-deja.com
Sat Feb 17 01:21:59 CET 2001


Proclaimed Sean 'Shaleh' Perry from the mountaintops:

> So, several of us informed Philip that list.sort() is in place and returns
> nothing.  How do i accomplish:
> 
> for key in dict.keys().sort():
>   print "%s -> %s" % (key, dict[key])
> 
> ???
> 
> I know I can do:
> 
> list = dict.keys()
> list.sort()
> .....
> 
> but it is just plain annoying.

I don't know why a more useful return value couldn't have been supplied, 
for call chaining like this at least, but Mr. Manners reminds the Gentle 
Poster that one should not cram too much stuff on one command line. Leave 
that for Perl or C++ coders.

-- 
  Phlip                          phlip_cpp at my-deja.com
============ http://c2.com/cgi/wiki?PhlIp ============
  --  My opinions are those of your employer  --



More information about the Python-list mailing list