[Tutor] Keeping change-in-place vs. copy methods straight

Alan Gauld alan.gauld at btinternet.com
Sun May 4 13:28:59 CEST 2014


On 04/05/14 11:31, Steven D'Aprano wrote:
> On Sun, May 04, 2014 at 10:00:08AM +0100, Alan Gauld wrote:
>
>> For the specific case of sort you can always use
>> the sorted() function which does return a reference
>> (not a copy!) to the sorted item.
>
> sorted() does make a copy of the list:

Really? That's a bummer.
I assumed (never assume!) that it returned a reference to the original.
I really, really, hate the way Python handles this :-(


> Perhaps you meant that it didn't copy the individual items inside the
> list?

Nah, I just got it wrong!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list