Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43677
| References | <20130416153701.GA18377@gmail.com> |
|---|---|
| Date | 2013-04-17 01:43 +1000 |
| Subject | Re: a couple of things I don't understand wrt lists |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.669.1366126994.3114.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: a couple of things I don't understand wrt lists Chris Angelico <rosuav@gmail.com> - 2013-04-17 01:43 +1000
csiph-web