dict indexed by lists - ?
Alexander
Alexander_Zatvornitskiy at p131.f3.n5025.z2.fidonet.org
Thu Feb 3 18:47:10 EST 2005
Hello All!
I'am trying to make something like this:
CPT={ ['b0','c0']:1, ['b0','c1']:0, ['b1','c0']:3, ['b1','c1']:1 }
but python says "TypeError: list objects are unhashable"
I can replace list with touple: CPT={ ('b0','c0'):1, ('b0','c1'):0, ...and so
on. But, where is one problem: indexes (or, more precisely, keys) are generated
dynamically, like code below! I can't do it with touples.
key=[]
for up in uplinks:
key.append(up.state(0))
and, later, modifying it like this:
key[2]=up.next_state()
...
print CPT[key]
Any suggestions?
Alexander, zatv at bk.ru
More information about the Python-list
mailing list