Interesting "gotme"

Andrew Henshaw andrew_dot_henshaw_at_earthling_dot_net
Thu Jan 18 22:50:02 EST 2001


I got bit by this for a couple of minutes the other day. Perhaps mentioning
it here will help someone else.  On the other hand, perhaps I'm the only
person silly enough to not see this right away.

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.

Cheers,

AH





More information about the Python-list mailing list