Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43677 > unrolled thread

Re: a couple of things I don't understand wrt lists

Started byChris Angelico <rosuav@gmail.com>
First post2013-04-17 01:43 +1000
Last post2013-04-17 01:43 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: a couple of things I don't understand wrt lists Chris Angelico <rosuav@gmail.com> - 2013-04-17 01:43 +1000

#43677 — Re: a couple of things I don't understand wrt lists

FromChris Angelico <rosuav@gmail.com>
Date2013-04-17 01:43 +1000
SubjectRe: a couple of things I don't understand wrt lists
Message-ID<mailman.669.1366126994.3114.python-list@python.org>
On Wed, Apr 17, 2013 at 1:37 AM, aaB <mecagonoisician@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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web