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

Discussion in 'Python' started by Chris Angelico, Apr 16, 2013.

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


    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
     
    Chris Angelico, Apr 16, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Nogradi
    Replies:
    3
    Views:
    368
    Dennis Lee Bieber
    Nov 10, 2006
  2. aaB
    Replies:
    7
    Views:
    164
    Steven D'Aprano
    Apr 17, 2013
  3. Terry Jan Reedy
    Replies:
    0
    Views:
    125
    Terry Jan Reedy
    Apr 16, 2013
  4. Dave Angel
    Replies:
    0
    Views:
    115
    Dave Angel
    Apr 16, 2013
  5. Ethan Furman
    Replies:
    0
    Views:
    98
    Ethan Furman
    Apr 16, 2013
Loading...

Share This Page