[python-advocacy] example code

Roy Smith roy at panix.com
Thu Nov 12 17:46:49 CET 2009

> # Loop list
> print "Python is ... "
> for index, each in enumerate(python):
>     print index + 1, each

Idiomatic python doesn't loop, it iterates.  That's more than just
nit-picking words.  The iterator concept is fundamental.  It's not just
that we have iterators, but that there's a standard iterator protocol so
all iterators look and feel the same (as opposed to, say, C++, where every
time I use an iterator I need to look up how the iterator for this
particular class works, because they're all different).

What you want to do is demonstrate how iterators work (i.e. how easy they
are to use).  The extra fluff with enumerate and printing the numbers just
obscures the main point you're trying to make.  I suggest:

# Loop list
print "Python is ... "
for attribute in python:
    print attribute

More information about the Advocacy mailing list