Finding the index of an item in a list

后端 未结 30 3257
你的背包
你的背包 2020-11-21 05:28

Given a list [\"foo\", \"bar\", \"baz\"] and an item in the list \"bar\", how do I get its index (1) in Python?

30条回答
  •  臣服心动
    2020-11-21 05:43

    a = ["foo","bar","baz",'bar','any','much']
    
    indexes = [index for index in range(len(a)) if a[index] == 'bar']
    

提交回复
热议问题