0
所以我想要做的是創建一個函數,它讀入列表並創建一個沒有標點的新列表,使用循環。 到目前爲止,我有:使用循環從列表中刪除標點符號-python3
list=["This:","is","a","list."]
def depunctuate():
for i in range(0,len(list),1):
list1=""
for j in range(0,len(list[i]),1):
if(list[i][j] !=['(',')','?',':',';',',','.','!','/','"',"'"]):
list1+=list1[i][j]
cleanList+=[list1]
return cleanList
depunctuate()
所以,我正在尋找它返回是「這是一個列表」 不過我越來越
Traceback (most recent call last):
File "depunctuate.py", line 10, in <module>
depunctuate()
File "depunctuate.py", line 7, in depunctuate
tokens1 += tokens1[i][j]
IndexError: string index out of range
任何幫助表示讚賞, 謝謝!
我知道這會讓它變得更加複雜並且沒有必要,但我真的應該使用循環。這是我CS150課程中的一個項目 – user3338100