No swap function in Python?
skip at pobox.com
Wed May 30 18:00:39 CEST 2001
>> Finally, if the behaviour is guaranteed, is this an efficient way of
>> doing a swap?
Relatively speaking, yes it is efficient. Still, you do wind up creating
and deleting a tuple as a result, which while not terribly expensive is not
without cost. "(a,b) = (b,a)" compiles to (approximately):
It's easy to see how you can use the runtime stack without going through the
Any peephole optimizer can do this for you... ;-)
More information about the Python-list