Given a list [\"foo\", \"bar\", \"baz\"] and an item in the list \"bar\", how do I get its index (1) in Python?
[\"foo\", \"bar\", \"baz\"]
\"bar\"
1
All indexes with the zip function:
get_indexes = lambda x, xs: [i for (y, i) in zip(xs, range(len(xs))) if x == y] print get_indexes(2, [1, 2, 3, 4, 5, 6, 3, 2, 3, 2]) print get_indexes('f', 'xsfhhttytffsafweef')