Handling sorted dictionaries
loial
admin at loial.co.uk
Tue Apr 17 04:01:55 EDT 2007
The following code gives the error
d=sortedmachines[machine]
TypeError: list indices must be integers
What works for the unsorted dictionary does not work for the sorted
dictionary.
Can anyone help?
machinekey = "111111"
machines = {}
machines[machinekey]=[1,0,0,0,0,0,0,0,0,0,0,0,0]
machinekey = "222222"
machines[machinekey]=[0,1,0,0,0,0,0,0,0,0,0,0,0]
ddd=0
for machine in machines.keys():
d=machines[machine]
print machine
print d [ddd]
sortedmachines=sorted(machines)
for machine in sortedmachines:
d=sortedmachines[machine]
print machine
print d [ddd]
More information about the Python-list
mailing list