【发布时间】:2017-12-05 20:09:49
【问题描述】:
我从书中复制了这段代码:
lyst = {'Hi':'Hello'}
def changeWord(sentence):
def getWord(word):
lyst.get(word, word)
return ''.join(map(getWord, sentence.split()))
我收到此错误:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
cambiaPronome('ciao')
File "C:\Python33\2.py", line 6, in cambiaPronome
return ''.join(map(getWord, list(frase)))
TypeError: sequence item 0: expected str instance, NoneType found
怎么了?
【问题讨论】:
-
return ''.join(map(getWord, list(frase)))不在书中。为什么不向我们展示您编写的实际代码? -
您没有从
getWord方法返回任何内容。 -
对于任何感兴趣的人来说,这个错误确实发生在 pg 上。 236 篇 Python 基础:第一个程序 由 Kenneth Lambert 撰写,因此并非由 OP 发起。
-
@DSM,你是怎么找到的?
-
@PadraicCunningham:用谷歌搜索最不可能由初学者编写的代码行(
return行。)