T
Tim Chase
I stumbled across this oddity and was hoping folks on the list
might be able to provide a little understanding:
# swap scalars(2, 1)
# swap lists
# swap list contents...not so much...
The first two work as expected but the 3rd seems to leak some
internal abstraction. It seems to work if I force content-copying:
or even just
but not
Is this a bug, something Python should smack the programmer for
trying, or just me pushing the wrong edges?
Thanks,
-tkc
might be able to provide a little understanding:
# swap scalars(2, 1)
# swap lists
([4, 5, 6], [1, 2, 3])>>> a,b = [1,2,3],[4,5,6]
>>> a,b = b,a
>>> a,b
# swap list contents...not so much...
([4, 5, 6], [4, 5, 6])>>> m,n = [1,2,3],[4,5,6]
>>> m[:],n[:] = n,m
>>> m,n
The first two work as expected but the 3rd seems to leak some
internal abstraction. It seems to work if I force content-copying:
>>> m[:],n[:] = n[:],m[:]
or even just
>>> m[:],n[:] = n,m[:]
but not
>>> m[:],n[:] = n[:],m
Is this a bug, something Python should smack the programmer for
trying, or just me pushing the wrong edges?
Thanks,
-tkc