动态查找列表中的第二个number
方法:先找到第一个2所在位置fist_index,切片new_list=names[index+1:]得到新的列表,
再从新列表中找第一个2的位置second_index.最终第二个2的位置为first_index+second_index+1
代码:
names = ['apple', 'rice', 'jack', 'rose', 2, 'girl', 'boy', 2, 'heather', 2]
first_index = names.index(2)
new_list = names[first_index + 1:]
second_index = new_list.index(2)
second_loction = first_index + second_index + 1 # 第二个2的位置
print('第二个2 的位置为:', second_loction)