Interesting "gotme"

Erik Max Francis max at alcyone.com
Fri Jan 19 00:29:21 EST 2001


Andrew Henshaw wrote:

> I had a list that I wanted to sort, except that I wanted the 0th
> element to
> stay put.  So I smugly coded:
> 
> a[1:].sort()
> 
> and went on my merry way.  Later, I tracked down a bug  to the fact
> that I
> really had not sorted a[1:].  Of course, I had sorted a copy of a[1:],
> which
> was immediately discarded.

Yep.  List slices make copies.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Youth is a period of missed opportunities.
\__/ Cyril Connolly
    REALpolitik / http://www.realpolitik.com/
 Get your own customized newsfeed online in realtime ... for free!



More information about the Python-list mailing list