index()
will just give the first occurrence of an item in a list. Is there a neat trick which returns all indices in a list?
Answer
You can use a list comprehension:
indices = [i for i, x in enumerate(my_list) if x == "whatever"]
index()
will just give the first occurrence of an item in a list. Is there a neat trick which returns all indices in a list?
Answer
You can use a list comprehension:
indices = [i for i, x in enumerate(my_list) if x == "whatever"]
In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...
No comments:
Post a Comment