index()
will give the first occurrence of an item in a list. Is there a neat trick which returns all indices in a list for an element?
You can use a list comprehension:
indices = [i for i, x in enumerate(my_list) if x == "whatever"]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments