moving items in a list

Erik Max Francis max at alcyone.com
Fri Jan 10 23:03:35 EST 2003


sismex01 at hebmex.com wrote:

> In this form ("a,b = b,a"), what actually happens behind
> curtains is that, first, a tuple is created with (b,a),
> and then, that same (temporary) tuple is unpacked into
> (a,b).  It might take more time to do this operation,
> than to do something like:
> 
>   _ = a
>   a = b
>   b = _
> 
> where "_" is some temporary variable.

... and if this trivial difference in speed is really enough to make or
break your application, I submit that Python was the wrong choice of
languages for it in the first place.

Go for readability, not simply speed.  When two forms are equally
readable, pick the one that's naturally faster.  When you're not sure,
don't worry about it.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ I sleep and dream that life is / All beauty
\__/ Lamya
    WebVal / http://www.alcyone.com/pyos/webval/
 URL scanner, maintainer, and validator in Python.




More information about the Python-list mailing list