[英]How to print values of a dictionary of lists in separate columns in Python?
I have a dictionary which contains a dictionary of lists:我有一本字典,其中包含一个列表字典:
data = {'team A': {'id': ['1', '2'], 'name': ['AAA', 'BBB']}, 'team B': {'id': ['3', '4'], 'name': ['XXX', 'YYY']}
I want to iterate over this dictionary and print values like:我想遍历这本字典并打印如下值:
|team A| 1 | AAA |
|team A| 2 | BBB |
|team B| 3 | XXX |
|team B| 4 | YYY |
How do I do this in Python?我如何在 Python 中执行此操作?
I tried iterating over the main dictionary, but I'm struggling to print the values in the way I want it with the '|'我尝试遍历主字典,但我正在努力使用“|”以我想要的方式打印值in separate columns在单独的列中
By using the dict.values()
This will allow you to return to a list containing all the values of your dictionary, without having to specify any key.通过使用dict.values()
这将允许您返回包含字典所有值的列表,而无需指定任何键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.