【发布时间】:2018-05-14 03:39:01
【问题描述】:
在以下代码行中出现 IndexError: list index out of range:
if tweetSplit[i] != "":
在我的代码中:
tweetSplit = tweet.split(' ')
for i in range(len(tweetSplit)):
#print (i)
if not tweetSplit:
break
if tweetSplit[i] != "":
#print (tweetSplit[i])
#print (tweetSplit[i][:1])
if tweetSplit[i][:1] == '@':
del tweetSplit[i]
我认为通过使用“if not tweetSplit”检查 tweetSplit 是否为空,我不会遇到超出范围的错误。 这是完整的错误:
Traceback (most recent call last):
File "parseTweets.py", line 55, in <module>
if tweetSplit[i] != "":
IndexError: list index out of range
【问题讨论】:
-
请向我们展示完整的追溯。
标签: python del index-error