Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: a couple of things I don't understand wrt lists

Thread Tools

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

Chris Angelico
Posts: n/a
On Wed, Apr 17, 2013 at 1:37 AM, aaB <(E-Mail Removed)> 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.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
a couple of things I don't understand wrt lists aaB Python 7 04-17-2013 06:46 PM
A couple of things from H&S Frank C Programming 18 09-10-2009 07:44 PM
Re: Lists of lists and tuples, and finding things within them Daniel Nogradi Python 3 11-10-2006 07:57 AM
Automating a couple of things in Windows -=rjh=- NZ Computing 7 05-22-2006 05:17 AM
Better way to do a couple things? Jon Bond HTML 2 08-08-2003 04:42 PM