How to iterate through dictionary of dictionaries in python -
i want iterate through dictionary of dictionary. want divide values each dict.. e.g., 0.5/0.4, 0.3/0.2, , 0.1/0.1 find max, haven't reached there yet. iteration appreciated.
#!/usr/bin/env python2 dict = {('a', 0.5): ('b', 0.4), ('c', 0.3): ("d", 0.2), ('e', 0.1): ('f', 0.1)} keys, values in dict: print "key: %s" % keys print "values: %f" % values keys1, values1 in dict[keys]: print "key1: %s" % keys1 print "values1: %f" % values1
however error:
key: values: 0.500000 traceback (most recent call last):
file "test.py", line 8, in keys1, values1 in dict[keys]: keyerror: 'a'
first rename variable dict
d
.
this not dictionary of dictionary. dictionary containing tuples key, , values.
for k, v in d.items(): = k[1] b = v[1] print(a/b)
Comments
Post a Comment