如何从两个列表创建字典?

1 python dictionary list

我有两个不同的列表,我需要它们像这样显示。我觉得我已经很接近了,但该程序不起作用。另外,带有的版本zip在这里对我不起作用。

>>> list_to_dict(["a", "b"], ["13", "7" ])
{ "a": "13", "b": "7" }
Run Code Online (Sandbox Code Playgroud)

这就是我现在所拥有的:

def lists_to_dict():
    x = ['a', 'b']
    y = ['13', '7']
    d = {}
    for i in range(len(x)):
        d[x[i]] = y[i]
    return d

lists_to_dict()
Run Code Online (Sandbox Code Playgroud)

Cha*_* S. 5

dict(zip(x,y))应该就是你所需要的。