Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获取系列中的索引?_Python_List - Fatal编程技术网

Python 如何获取系列中的索引?

Python 如何获取系列中的索引?,python,list,Python,List,我的数据集包含以下标签: s=['A','A','A','B','B','B','C','C','C','D','D','D','D','D'] 我想知道如何获得第一个元素B的索引和C的最后一个元素第一个元素B的索引 s.index('B') 最后一个元素C的索引 len(s) - s[::-1].index('C') - 1

我的数据集包含以下标签:

s=['A','A','A','B','B','B','C','C','C','D','D','D','D','D']


我想知道如何获得第一个元素
B
的索引和
C
的最后一个元素第一个元素B的索引

s.index('B')
最后一个元素C的索引

len(s) - s[::-1].index('C') - 1