a question regarding conciseness

Paul Rubin phr-n2002a at nightsong.com
Wed Feb 20 20:36:53 EST 2002


magnus at thinkware.se (Magnus Lyckå) writes:
> Rajarshi Guha <rxg218 at psu.edu> wrote in message news:<a50umn$1dou at r02n01.cac.psu.edu>...
> > Why can't I use d.keys().sort() directly? 
> 
> Because .sort() is not a function that returns a sorted
> copy of it's input. It sorts the list in-place and returns
> none. A sort method returning a copy would use much more
> memory.

But there's no reason sort couldn't sort in place and return the list.
d.keys() already makes a temporary list with the keys in it after all.
The temporary list can be sorted in place without disturbing the
dictionary.



More information about the Python-list mailing list