How can I find the index for a given item in a list?
@lebyy▲ 0 net votes
Problem: Given a list ["foo", "bar", "baz"] and an item in the list "bar" , how do I get its index 1 ? Fix (from the top answer): >>> ["foo", "bar", "baz"].index("bar") 1 See the documentation for the built-in .index() method of the list: list.index(x[, start[, end]]) Return zero-based index in the list of the first item whose value is equal to x . Raises a ValueError if there is no such item. The optional arguments start and end are…