a couple of things I don't understand wrt lists

Chris Angelico rosuav at gmail.com
Tue Apr 16 11:43:06 EDT 2013


On Wed, Apr 17, 2013 at 1:37 AM, aaB <mecagonoisician at gmail.com> wrote:
> but when I do:
>
> for i in rule:
>   print rule[i]

When you iterate over rule, you don't iterate over the indices, but
over the values themselves. Try this:

for i in rule:
    print i

Incidentally, "for i in range(rule)" isn't actually going to work;
what you would have used is "for i in range(len(rule))". Be careful
with that sort of thing; it's usually safest to actually copy and
paste from an interactive session, rather than reconstruct manually.
Sometimes it's not obvious whether it was a copy/paste problem or the
cause of your underlying confusion.

ChrisA



More information about the Python-list mailing list