我有字典:
dict = {"basic": {"last_name":["tomson", "brown"], "first_name":["paul", "max"]}}
我想编写将其转换为此的函数:
table = [["tomson", "paul"],
["brown", "max"]]
对于
terminaltables
模块:from terminaltables import AsciiTable
table_data = [["last_name", "first_name"]]
table_data.append(table)
ascii_table = AsciiTable(table_data)
print "\n" + ascii_table.table + "\n"
结果:
+----------+-----------+
|last_name |first_name |
+----------+-----------+
|tomson |paul |
|brown |max |
+----------+-----------+
请帮我!我的英语很抱歉:)
最佳答案
如果还需要“旋转”列表:
table = [list(reversed(x)) for x in zip(*dict['basic'].values())]
关于python - 在Python中一一转换数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31589788/