在python中包含数组中的子数组

时间:2015-08-17 22:43:09

标签: python arrays

我很抱歉如果我的问题很愚蠢,但我无法找到解决方案......

我想知道是否有可能在python中创建一个数组,非常像json:

//Array that contains keys I would like to retain
$arr1 = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);

//Array that contains values I'd like to use
$arr2 = array(1=>123, 3=>123, 5=>123, 7=>123, 9=>123, 11=>123);

$result = array_fill_keys(
    $arr1,
    null
);
array_walk(
    $result,
    function(&$value, $key) use($arr2) {
        $value = (isset($arr2[$key])) ? $arr2[$key] : null;
    }
);
var_dump($result);

提前致谢。

2 个答案:

答案 0 :(得分:0)

您缺少逗号:

std::map<std::string, boost::any> any = {
  {"hh", 4},
  {"g", std::map<std::string, boost::any>{{"y", 2}} }
};

答案 1 :(得分:0)

你错过了一个逗号。

car = [
    ["Brand", "Citroen"],
    ["Model", "C4"],
    ["Details", "Lounge"],
    ["shift",
        [
            ["manual","5", "shifts"],
            ["automatic","5", "sequential"],
            ["automatic","5", "paddleshift"]
        ]
    ]
]

print(car)