get all occurrence indices in list python

a_list = [1, 2, 3, 1]

indices = []
for i in range(len(a_list)):
   if a_list[i] == 1:
      indices.append(i)

# more concise way
a_list = [1, 2, 3, 1]
indices = [index for index, element in enumerate(a_list) if element == 1]

Here is what the above code is Doing:
1. enumerate(a_list) returns a list of tuples, where each tuple is of the form (index, element).
2. The list comprehension then goes through each tuple in the list returned by enumerate(a_list) and keeps the index if the element is equal to 1.