I am using the Counter class in Python to count the number of words in a key of a large python dictionary. I am creating a new dictionary with the keys being incremented numbers and the values being the return of the counter function. This is what my new dictionary looks like:
TP = {1:Counter({u'x':1, u'b':1, u'H':3}),2:Counter({u'j':1, u'm':4, u'e':2})...}
What I want to do, if possible, is remove the Counter and the parentheses ( and ) so that my dictionary looks like:
TP = {1:{u'x':1, u'b':1, u'H':3}, 2:{u'j':1, u'm':4, u'e':2}...}
If that’s not possible, can someone please tell me how to access the nested dictionaries inside the ()? Thank you
I don’t see any point of doing this,
Counteris a subclass ofdictand supports all of it’s methods so you should have no problems leaving it as is, although just for the sake of this question I will convert it back to a normaldict:For Python 2.7+ (as suggested by @Blender)
Iterating through subdictionaries eg: