I find myself needing to iterate over a list made of dictionaries and I need, for every iteration, the name of which dictionary I\'m iterating on.
Here\'s an MWE (the co
The following doesn't work on standard dictionaries, but does work just fine with collections dictionaries and counters:
from collections import Counter
# instantiate Counter ditionary
test= Counter()
# create an empty name attribute field
test.name = lambda: None
# set the "name" attribute field to "name" = "test"
setattr(test.name, 'name', 'test')
# access the nested name field
print(test.name.name)
It's not the prettiest solution, but it is easy to implement and access.