问题:RuntimeError: dictionary changed size during iteration
#问题代码
for k in headerTable.keys():
if headerTable[k]< minSup:
del(headerTable[k])
#修改+list()
for k in list(headerTable.keys()):
if headerTable[k]< minSup:
del(headerTable[k])
字典在遍历时不能进行修改,建议转成列表或集合处理。
问题:AttributeError: 'str' object has no attribute 'inc'
#问题代码
if items[0] in inTree.children:
inTree.children[items[0].inc(count)]
# 为[]位置标错
if items[0] in inTree.children:
inTree.children[items[0]].inc(count)
问题:TypeError: '<' not supported between instances of 'treeNode' and 'treeNode'
#修改前
bigL = [v[0] for v in sorted(headerTable.items(),key = lambda p: p[1])]
#修改后
bigL = [v[0] for v in sorted(headerTable.items(), key=lambda p: str(p[1]))]