2024-09-24 02:28:29 发布
网友
我正在查看其他人的代码以使其适合我自己的here,我在第44行中遇到了这个问题:
scores = {word: tfidf(word, blob, bloblist) for word in blob.words}
在Python2.7.6中尝试此操作时,在单词for后面的空格中出现语法错误。为什么是无效语法,代码中到底发生了什么?你知道吗
for
词典理解是backported only to 2.7 not to 2.6, from 3.1
Dictionary and set comprehensions ({ i: i*2 for i in range(3)}).
因此,在Python2.6中的等价物是
dict((word, tfidf(word, blob, bloblist)) for word in blob.words)
但是通过名单会稍微快一点
dict([(word, tfidf(word, blob, bloblist)) for word in blob.words])
词典理解是backported only to 2.7 not to 2.6, from 3.1
因此,在Python2.6中的等价物是
但是通过名单会稍微快一点
相关问题 更多 >
编程相关推荐