【发布时间】:2014-06-08 06:22:23
【问题描述】:
当我在字符串words 上运行以下代码时:
def word_feats(words):
return dict([(word, True) for word in words])
print(word_feats("I love this sandwich."))
我得到的是字母而不是单词的输出字典理解:
{'a': True, ' ': True, 'c': True, 'e': True, 'd': True, 'I': True, 'h': True, 'l': True, 'o': True, 'n': True, 'i': True, 's': True, 't': True, 'w': True, 'v': True, '.': True}
我做错了什么?
【问题讨论】:
标签: python string for-loop iteration string-iteration