【发布时间】:2017-05-03 17:58:31
【问题描述】:
在测试它们是否已经存在后,我正在尝试将一些键添加到我的字典中。但是我好像不能做测试,每次得到TypeError "argument of type 'type' not iterable。
这基本上是我的代码:
dictionary = dict
sentence = "What the heck"
for word in sentence:
if not word in dictionary:
dictionary.update({word:1})
我也试过if not dictionary.has_key(word),但也没有用,所以我真的很困惑。
【问题讨论】:
标签: python if-statement dictionary testing typeerror