A small suggestion for Python

ssthapa at harper.uchicago.edu ssthapa at harper.uchicago.edu
Tue Jan 16 12:29:59 EST 2001


Alex Martelli <aleaxit at yahoo.com> wrote:
>"Matt Dunford" <kno at jtan.com> wrote in message
>> I have no problem with it.  But just to be pendantic, your return_sorted
>def
>> doesn't do what I'm trying to get at.  I'm thinking more along the lines
>of
>>
>> def return_sorted(alist):
>>     import copy
>>     sorted = copy.copy(alist)
>>     sorted.sort()
>>     return sorted
>
>I would call this return_sorted_copy.  It's not needed, often, and in
>particular
>it is not for the idiom you mentioned -- why make a totally needless copy of
>the temporary list that .keys returns?  I'm anything but a speed freak, but
>I
>don't normally copy data just for the fun of it:-).

    Also there are times when making copies is not possible or would be 
the wrong thing to do.  For example if the array contains objects representing
email messages which you sort based on time.  Copying the emails may not be 
pratical especially if they contain large attachments.

-- 
------------------------------------------------------------------
			    |
Suchandra Thapa             | "There are only two kinds of math books. 
s-thapaNO at SPAMuchicago.edu  | Those you cannot read beyond the first 
			    | sentence, and those you cannot read 
			    | beyond the first page."
			    |                       -C.N. Yang
------------------------------------------------------------------



More information about the Python-list mailing list