将两个列表转换为Python中的字典列表

jac*_*ill 2 python dictionary list python-2.7

我有两个列表,例如:

L = [1, 2]
S = ['B', 'C']
Run Code Online (Sandbox Code Playgroud)

如何将它们组合成这样的字典:

X = {'B': 1, 'C': 2}
Run Code Online (Sandbox Code Playgroud)

列表的长度始终相同,但可以包含任意数量的项目.

Bre*_*arn 7

这是一个单行:

dict(zip(S, L))
Run Code Online (Sandbox Code Playgroud)