Python Mystery Theatre -- Episode 3: Extend this
Jack Diederich
jack at performancedrivers.com
Tue Jul 22 06:26:22 EDT 2003
On Tue, Jul 22, 2003 at 10:49:41AM +0100, Harvey Thomas wrote:
> Raymond Hettinger wrote:
> > i, j, a[i], a[j], swaps = j, i, a[j], a[i], swaps+1
>
> It's a quick and dirty bubble sort. Not sure what's wrong without running the code, but it looks wrong to mess around with the loop indices. Perhaps the swapping line should read
> a[i], a[j], swaps = a[j], a[i], swaps+1. BTW isn't there an indentation error in the code?
> >
I didn't bother checking if the side effect in that line was ruinous or not,
but it certainly is frightening. Here is my test of the same abuse
>>> l = list('abc')
>>> l
['a', 'b', 'c']
>>> (i, l[i], i, l[i]) = (0,'X',1,'Y')
>>> l
['X', 'Y', 'c']
Could we call that undefined, just to scare people from using it? Showing
up to their office with a bat is sometimes impractical.
-jack
More information about the Python-list
mailing list