【问题标题】:Equivalent data structure in python 3 of a complex structure in C++C ++中复杂结构的python 3中的等效数据结构
【发布时间】:2018-03-31 13:52:04
【问题描述】:

我想创建一个等效的数据结构,我在 python 的 C++ 赋值中使用。我很难弄清楚如何做到这一点。结构如下 -

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

你能指出我正确的方向吗?

编辑:我知道 list 和 dict 分别是 vector 和 map 的等价物,我应该指定是否有单行代码可以在 python 中初始化相同的数据结构。

【问题讨论】:

标签: python c++ python-3.x data-structures


【解决方案1】:

试试defaultdict:

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

现在将自动创建每个不存在的字典键,尽管您可以使用与静态类型 C++ 不同的任何类型。

【讨论】:

    猜你喜欢
    • 2014-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-08
    • 2011-12-23
    • 1970-01-01
    相关资源
    最近更新 更多