picassooo

方法一

摘自Python查找列表中某个元素返回所有下标

 

方法二

name = [\'hello\', \'world\', \'a\', \'b\', \'c\', 1, 2, 3, \'hello\', \'world\', \'a\', \'b\', \'c\', 1, 2, 3]
first_pos = 0
for i in range(name.count(\'a\')):
    new_list = name[first_pos:]
    next_pos = new_list.index(2) + 1
    print(\'find \', first_pos + new_list.index(\'a\'))
    first_pos += next_pos

# 运行结果:
#   find  2
#   find  10

摘自:Python 查找list中的某个元素的所有的下标方法

 

分类:

技术点:

相关文章:

  • 2021-06-12
  • 2022-01-08
  • 2021-04-07
  • 2021-12-04
  • 2021-12-04
  • 2021-11-06
  • 2021-05-31
  • 2021-11-20
猜你喜欢
  • 2021-12-19
  • 2021-07-25
  • 2021-04-03
  • 2021-07-31
  • 2021-12-26
  • 2021-08-08
  • 2021-05-11
相关资源
相似解决方案