【发布时间】:2016-06-01 17:42:24
【问题描述】:
我想从这个数组中删除单词“hello”,但我得到了“index out of bounds”错误。我检查了len(token)的范围;是(0,5)。
代码如下:
token=['hi','hello','how','are','you']
stop='hello'
for i in range(len(token)):
if(token[i]==stop):
del(token[i])
【问题讨论】:
-
我尝试将其用作解决方法,但得到相同的错误代码“ m=(len(tokens)); n=(len(stop)); for i in range(m): print (i) for j in range(n): print(j) if(tokens[i] == stop[j]): del(token[i]) m=m-1 " 但是将它添加到新列表有帮助.谢谢
标签: python list indexoutofboundsexception