我一直有这个循环,应该遍历并保存与本书中的所有单词列表的麻烦。Python循环,遍历一个字符串:'int'对象是不可迭代的
我得到的错误是:'int' object is not iterable
。
def create_word_dict()
word_list = open("mobydick.txt", "r")
all_list = word_list.read()
all_list = all_list.split()
word_list.close()
for index in len(all_list):
all_list[index] = parseString(all_list[index])
return all_list
# Removes punctuation marks from a string
def parseString (st):
s = ""
for ch in st:
if ch.isalpha() or ch.isspace():
s += ch
else:
s += ""
return s #return was outside code block
它说'int'对象是不可迭代的 – Needhelp
我编辑你的帖子来修复所有的缩进。你究竟有什么问题? – abe