get all occurrence indices in list python

Solutions on MaxInterview for get all occurrence indices in list python by the best coders in the world

showing results for - "get all occurrence indices in list python"
Jonah
10 Feb 2017
1a_list = [1, 2, 3, 1]
2
3indices = []
4for i in range(len(a_list)):
5   if a_list[i] == 1:
6      indices.append(i)
7
8# more concise way
9a_list = [1, 2, 3, 1]
10indices = [index for index, element in enumerate(a_list) if element == 1]