Translating python dictionary to C++

前端 未结 7 1030
-上瘾入骨i
-上瘾入骨i 2020-11-30 00:57

I have python code that contains the following code.

d = {}

d[(0,0)] = 0
d[(1,2)] = 1
d[(2,1)] = 2
d[(2,3)] = 3
d[(3,2)] = 4

for (i,j) in d:
    print d[(         


        
相关标签:
7条回答
  • 2020-11-30 01:34

    Do you want to call an optimized C++ routine via Python? If so, read on:

    Often times I use PyYaml when dealing with dictionaries in Python. Perhaps you could link in something like LibYAML or yamlcpp to:

    1. Translate a Python dictionary into a YAML string
    2. Use Python to call a C++ function wrapped using something like SWIG, taking the YAML string as a parameter.
    3. Use a C++ library to parse the YAML & obtain a std::map object
    4. Operate on std::map object

    Warning: I have never tried this, but using everyone's favorite search engine on "yaml std::map" yields lots of interesting links

    0 讨论(0)
提交回复
热议问题