I read the post: How to find all occurrences of an element in a list? How to find all occurrences of an element in a list?
The answer given was:
indices = [i for i, x in enumerate(my_list) if x == "whatever"]
I know this is list comprehension but I cannot break this code down and understand it. Can someone please piece meal it for me?
If do the following code:I know enumerate will just create a tuple:
l=['a','b','c','d']
enumerate(l)
output:
(0, 'a')
(1, 'b')
(2, 'c')
(3, 'd')
If there's a simpler way I'd be open to that too.