Get name of dictionary
You should also consider adding a "name" key to each dictionary.
The names would be:
for dc in dict_list:
# Insert command that should replace ???
print 'The name of the dictionary is: ', dc['name']
Don't use a dict_list
, use a dict_dict
if you need their names. In reality, though, you should really NOT be doing this. Don't embed meaningful information in variable names. It's tough to get.
dict_dict = {'dict1':dict1, 'dicta':dicta, 'dict666':dict666}
for name,dict_ in dict_dict.items():
print 'the name of the dictionary is ', name
print 'the dictionary looks like ', dict_
Alternatively make a dict_set
and iterate over locals()
but this is uglier than sin.
dict_set = {dict1,dicta,dict666}
for name,value in locals().items():
if value in dict_set:
print 'the name of the dictionary is ', name
print 'the dictionary looks like ', value
Again: uglier than sin, but it DOES work.