📌  相关文章
📜  获取列表python代码示例中的所有出现索引

📅  最后修改于: 2022-03-11 14:45:42.869000             🧑  作者: Mango

代码示例1
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]