index in for loops

Discussion in 'Python' started by manstey, May 17, 2006.

  1. manstey

    manstey Guest

    in for loops like the following:


    for letter in word:
    print letter

    Is it possible to get the position of letter for any iteration through
    the loop?

    so for examlpe letter=='a', and I want to know if it is the first or
    second 'a' in 'abcade'.

    can i do this by looking at a property of letter?
    manstey, May 17, 2006
    1. Advertisements

  2. for index, letter in enumerate(word):
    print index, letter
    Wojciech =?iso-8859-2?Q?Mu=B3a?=, May 17, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.