【发布时间】:2018-06-16 19:25:55
【问题描述】:
我有以下字典:
dct = {'F': [0, 0, 0, 1], 'T': [0, 3, 0, 4], 'B': [1, 1, 0, 1], 'K': [2, 2, 0, 1], 'J': [2, 4, 0, 2], 'Bxx': [4, 4, 0, 1]}
我想将其转换为以下二维数组:
ultimate_list = [['F', 0, 0, 0, 1], ['T', 0, 3, 0, 4], ['B', 1, 1, 0, 1], ['K', 2, 2, 0, 1], ['J', 2, 4, 0, 2], ['Bxx', 4, 4, 0, 1]]
到目前为止,我已经完成了以下操作,但并没有完全得到我正在寻找的输出:
final_list = []
for k, v in dct.items():
final_list.append([k, v])
flat_list = []
for sublist in final_list:
for item in sublist:
flat_list.append(item)
print(flat_list)
哪个输出这个:
flat_list = ['F', [0, 0, 0, 1], 'T', [0, 3, 0, 4], 'B', [1, 1, 0, 1], 'K', [2, 2, 0, 1], 'J', [2, 4, 0, 2], 'Bxx', [4, 4, 0, 1]]
【问题讨论】:
-
@coldspeed 对不起,谢谢。我认为它现在已修复。
标签: python python-3.x list dictionary