Hi,
I need to store a list of dictionaries in cython and decided to go with the `vector[map[string, int]]` setup as I don't know the size of the list.
Currently I'm trying the below
%%cython
# distutils: language = c++
from libcpp.string cimport string
from libcpp.map cimport map
from libcpp.vector cimport vector
cdef vector[map[string, int]] categories
cdef map[string, int]* categories_i
for i in range(2):
categories_i = new map[string, int]
categories_i[<string>'foo'] = 1
categories_i[<string>'bar'] = 2
categories.pushback(categories_i)
print categories[0][<string>'foo']
But I get a
"Expected an identifier before '='" error... I understand that the error stems from the creation of the new map object (categories_i = new map[string, int]) but unsure how I should proceed.
Or is there an easier way to declare and use the python equivalent of list of dicts in cython?
Thanks,
R