Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将带有键和值列表的字典转换为矩阵_Python_Python 3.x_Dictionary_Matrix - Fatal编程技术网

Python 将带有键和值列表的字典转换为矩阵

Python 将带有键和值列表的字典转换为矩阵,python,python-3.x,dictionary,matrix,Python,Python 3.x,Dictionary,Matrix,如何将这样的字典{1:[0,1,2],2:[3,4,5]}转换为矩阵[[1,0,1,2],[2,3,4,5]]?遍历字典,并将键和值追加到更大的列表中 dct = {1: [0, 1, 2], 2:[3, 4, 5]} lst = [[key]+value for key,value in dct.items()] print(lst) #[[1, 0, 1, 2], [2, 3, 4, 5]]

如何将这样的字典{1:[0,1,2],2:[3,4,5]}转换为矩阵[[1,0,1,2],[2,3,4,5]]?

遍历字典,并将键和值追加到更大的列表中

dct =  {1: [0, 1, 2], 2:[3, 4, 5]}
lst = [[key]+value for key,value in dct.items()]
print(lst)
#[[1, 0, 1, 2], [2, 3, 4, 5]]