【发布时间】:2014-02-21 18:02:32
【问题描述】:
我需要在字典中创建一个集合。
dicInvertedIndex = {}
docID = 1
for i in string:
if condition:
docID += 1
dicInvertedIndex[i] = [1, set(docID)]
我有一个错误:
dicInvertedIndex[i] = [1, set(docID)]
TypeError: 'int' object is not iterable
在我尝试这个之前,我在字典中创建了一个列表并且它有效。
dicInvertedIndex[i] = [ 1 , [ docID ] ]
而且它有效。我需要用我的文档的键和 (int, set()) 的值创建一个字典
点赞dic["awake"] = [5, {2, 30, 99, 234}]
本来我用的是list,但是速度很慢,我想用set。
【问题讨论】:
-
not iterable听起来像是for循环。仔细检查string中的内容。 -
您应该询问如何解决您的基本问题,而不是为什么您尝试的解决方案不起作用。
-
好的,谢谢。我问另一个问题
标签: python linux windows dictionary set