在列表中查找字符串的索引

时间:2014-05-02 20:00:20

标签: python indexing find

我试图在列表中找到一个字符串的索引,即使字符串不是我想要一个响应告诉我它没有,这里是我的代码。

S是我试图找到索引的列表 linez是一个打开的txt文件,包含逗号分隔字符串的行,它也按照我的意愿行事,所以它可以工作。 如果可能的话,我需要一个函数来给我索引为false,即使字符串不在列表中而不是erro,谢谢

for q in range(9,19):
    xcox=linez[q]
    co=xcox.split(' ')
    g=list.index(co,'COREQ')+1
    h=list.index(co,'TIMES1')
    m=co[g:h]
    x=len(m)
    for i in range(x):
        g=list.index(S,m[i])
        print(g)

错误:

Traceback (most recent call last):
  File "C:\Python33\Python Projects\ProjectPython.py", line 153, in <module>
    g=list.index(S,m[i])
ValueError: 'MECN2000,' is not in list
>>> 

0 个答案:

没有答案