FAQ

# 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

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 9 | next ›
Discussion Overview
groupadvocacy @
categoriespython
postedNov 12, '09 at 4:00p
activeNov 13, '09 at 2:55p
posts9
users6
websitepython.org

People

Translate

site design / logo © 2019 Grokbase