-4

I want to create an equivalent data structure I used in a C++ assignment for python. I'm having trouble figuring out how to do this. The structure is given below -

 map < string, map < string, vector < int > > > invertedIndex;

Can you please point me in the right direction?

Edit : I know that list and dict are equivalents for vector and map respectively, I should have specified if there is a single line code in which I can initial this same data structure in python.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

Try defaultdict:

import collections, functools
inverted_index = collections.defaultdict(functools.partial(defaultdict, list))

Every dictionary key which doesn't exists will now automatically get created, although you are able to use any type unlike in the statically typed C++.

kb1000
  • 320
  • 1
  • 10