Python{ ‘Good’ : ‘0’, ‘Bad’ :’9′, ‘Lazy’ : ‘7’}
I need to access the key names dynamically in a program. Eg.
a= raw_input (" which is the final attribute:")
for i in python.items():
if python.items()[i] == a:
finalAttribute = python.items()[i]
This giving me error saying
Traceback (most recent call last):
File "C:/Python27/test1.py", line 11, in <module>
if somedict.items()[i] == a:
TypeError: list indices must be integers, not tuple
Try:
Also, I don’t know what you meant when you named your variable “finalAttribute”, but I feel obliged to remind you that Python makes no guarantees about the order of dictionary keys.