Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create a dictionary using two lists in python? [duplicate]

x = ['1', '2', '3', '4']
y = [[1,0],[2,0],[3,0],[4,]]

I want to create a dictionary so the x and y values would correspond like this:

1: [1,0], 2: [2,0]

and etc

like image 591
Kara Avatar asked Mar 03 '13 06:03

Kara


1 Answers

You can use zip function: dict(zip(x, y))

>>> x = ['1', '2', '3', '4']
... y = [[1,0],[2,0],[3,0],[4,]]
>>> dict(zip(x, y))
0: {'1': [1, 0], '2': [2, 0], '3': [3, 0], '4': [4]}
like image 103
Igonato Avatar answered Oct 26 '22 22:10

Igonato