Skip to content

Get list index of a list item in Python

If you want to find the index of an list element, you can use the list.index() method:

elements = ["foo", "bar", "baz"]
elements.index("bar") # Returns 1


Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.