For Counter Variable

Tim Chase python.list at tim.thechases.com
Sun Sep 23 20:05:23 EDT 2012


On 09/23/12 18:52, Alec Taylor wrote:
> You can always use a counter if you don't like our fancy for-each loops;
> 
> foolist = [1,24,24,234,23,423,4]
> for i in xrange(len(foolist)):
>     print foolist[i]

http://www.seas.upenn.edu/~lignos/py_antipatterns.html

The first one on the list of anti-patterns is doing exactly this.
Just don't.  Ewww.  Inefficient, ugly, and harder to read.

Part of learning to write in Python is, well, learning to write
*Python*, not {C,C++,Java,PHP}-in-Python.

-tkc







More information about the Python-list mailing list