用lambda解包元组?

时间:2017-08-14 23:20:55

标签: python python-3.x lambda tuples

我试图将Python 2中构建的拼写检查器转换为Python 3.我无法理解这一行。

$makes = [
    [
        "Ford",
        "1"
    ],
    [
        "Chevrolet",
        "1"
    ],
    [
        "VW",
        "1"
    ],
    [
        "Fiat",
        "3"
    ]
];

$colors = [
    "#581845",
    "#900C3F",
    "#C70039",
    "#FF5733",
    "#FFC300",
    "#DAF7A6"
];

foreach($makes as &$currMakeTuple)
{
    $currMakeTuple[] = array_shift($colors);
}

print_r($makes);

Array
(
    [0] => Array
        (
            [0] => Ford
            [1] => 1
            [2] => #581845
        )

    [1] => Array
        (
            [0] => Chevrolet
            [1] => 1
            [2] => #900C3F
        )

    [2] => Array
        (
            [0] => VW
            [1] => 1
            [2] => #C70039
        )

    [3] => Array
        (
            [0] => Fiat
            [1] => 3
            [2] => #FF5733
        )

)

我发现了几个outlist = sorted(as_list, key=lambda (term, (freq, dist)): (dist, -freq)) 解包问题和答案,但我无法理解实际发生的情况以及如何转换此特定行。

0 个答案:

没有答案