Chr*_*ell 0 python dictionary list
例如,如果我有两个列表:
listA = [1, 2, 3, 4, 5]
listB = [red, blue, orange, black, grey]
Run Code Online (Sandbox Code Playgroud)
我试图弄清楚如何在两列中的两个参数列表中显示元素,分配1: red, 2: blue...等等.
必须在不使用内置zip功能的情况下完成此操作.
小智 7
>>> listA = [1, 2, 3, 4, 5]
>>> listB = ["red", "blue", "orange", "black", "grey"]
>>> dict(zip(listA, listB))
{1: 'red', 2: 'blue', 3: 'orange', 4: 'black', 5: 'grey'}
Run Code Online (Sandbox Code Playgroud)