need to get an index for an item in a list

Peter Hansen peter at engcorp.com
Sun Jul 3 15:31:09 EDT 2005


nephish at xit.net wrote:
> i need to be able to get the index for an item in a list.

> any ideas?

Fire up the interactive interpreter and learn to use it to help 
yourself.  In this case, the most useful thing might be to know about 
the dir() builtin method, which you can use on a list like so:

dir([])

Note in the output the presence of the "index" method...  I'll leave it 
up to you to read the docs to learn more about how to use it, or you can 
just experiment at the prompt to see how it works.

-Peter



More information about the Python-list mailing list