0

I am trying to make a dictionary of dictionaries, where the default values in the interior dictionary have a default value of 0.0.

For example, it might look something like this: {'Jack':{'foo':0.0, 'bar':1.4, ...}, 'Mike': {'foo':6.2, ...} }

I want to initialize all of the words to a 0.0 value so that I can simply say:

for word in document:
    my_dictionary['Jack'][word] += 1.4

I have tried using defaultdict(dict) and Counter but I can't say for sure if those are the right strategy here.

Any thoughts?

Jack Ryan
  • 1,255
  • 12
  • 25

1 Answers1

0

Try this instead:

my_dictionary = defautltdict(lambda: defaultdict(float))
Moses Koledoye
  • 71,737
  • 8
  • 101
  • 114