【发布时间】:2014-03-04 22:54:14
【问题描述】:
我有一本字典,我需要从 index s 开始迭代字典(不是第一个)。我是这么写的
def _get_cell_end_offset(self, d, s, n):
for e in d[s:]:
if e != 0 and d[e][0][1] == ".ends" and d[s][1][1] == n:
return e
字典创建所以这个d = {},我添加了元素所以d[i] = l
但是在结果中有一个类似
的错误"Traceback (most recent call last):
File "./main.py", line 23, in <module>
ss = netlist._get_cell_end_offset(s, 9, "NR2_V20_2")
File "/home/ubuntu/synop/net.py", line 16, in _get_cell_end_offset
for e in d[s:]:
TypeError: unhashable type"
我的这种类型的字典
(1, [['START', '.SUBCKT'], ['PIN', 'NR2_V20_1'], ['PIN', 'VDD'], ['PIN', 'VSS'], ['PIN', 'VBP'], ['PIN', 'VBN'], ['PIN', 'X'], ['PIN', 'A1'], ['PIN', 'A2']])
(2, [['ELEMENT', 'R1'], ['PIN', 'X:F93'], ['PIN', 'X:195'], ['PIN', '6.014590e+00']])
(3, [['ELEMENT', 'Cg15'], ['PIN', 'ln_N_76:291'], ['PIN', 'VSS'], ['PIN', '2.133320e-17']])
.........................................................................................
.........................................................................................
.........................................................................................
怎么办?
【问题讨论】:
-
你在这里使用了错误的数据结构,字典不支持索引/切片并且它们是无序的。
标签: python loops for-loop dictionary indexing