If I have this dictionary with python :
{'143534':[23,12,45],'123765':[33,89,90],'148987':[98,65,80]}
I need to place a matrix like this:
23,33,98
12,89,65
45,90,80
Any suggestions?
If I have this dictionary with python :
{'143534':[23,12,45],'123765':[33,89,90],'148987':[98,65,80]}
I need to place a matrix like this:
23,33,98
12,89,65
45,90,80
Any suggestions?
You can use zip
:
>>> d = {'143534': [23, 12, 45], '123765': [33, 89, 90], '148987':[98, 65, 80]}
>>> d.values()
[[23, 12, 45], [33, 89, 90], [98, 65, 80]]
>>> zip(*d.values())
[(23, 33, 98), (12, 89, 65), (45, 90, 80)]
With the values
method you get the values for each dictionary element. Now, as zip
expects a certain amount of iterables (lists or tuples), we are passing each one using *
. That is, what is happening to zip
is:
>>> zip([23, 12, 45], [33, 89, 90], [98, 65, 80])
[(23, 33, 98), (12, 89, 65), (45, 90, 80)]