A
Ayushi Dalmia
I need to initialise a dictionary of dictionary with float values. I do not know the size of the dictionary beforehand. How can we do that in Python
I need to initialise a dictionary of dictionary with float values.
I do not know the size of the dictionary beforehand. How can we do
that in Python --
Ayushi Dalmia said:I need to initialise a dictionary of dictionary with float values. I do not know the size of the dictionary beforehand. How can we do that in Python
Unsure of what the floats have to do with it. Perhaps you meant
float KEYS.
I need to initialise a dictionary of dictionary with float values.I do not know the size of the dictionary beforehand. How can we dothat in Python --
Either
d = {}
or, if you want
from collections import defaultdict
d = defaultdict(float)
print(d["Hello"])
If you really do want a dict-of-dict that defaults to floats, you can
do
d = defaultdict(lambda: defaultdict(float))
print(d[3141]["Hello"])
-tkc
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.