【发布时间】:2016-05-17 00:56:34
【问题描述】:
我有一个问题。我试图将其他问题的信息放在一起,但没有成功。 假设我有以下格式的数据:
file_list = ["f1", "f2", "f3"]
inner_dict = {1: "one", 2: "two", 3: "three"}
outer_dict = {}
for f in file_list:
outer_dict[f] = inner_dict
我的目标是通过以下方式打印(保存到文件中):
f1, 1, one
f1, 2, two
f1, 3, three
f2, 1, one
f2, 2, two
f2, 3, three
f3, 1, one
f3, 2, two
f3, 3, three
为了这个目标,我开始关注outer_dict的项目,并设法将它们分开打印,但我不知道如何进一步加入(更重要的是,如果这是最直接的方法)。
for key, value in outer_dict.items():
inn_keys = value.keys()
inn_values = value.values()
b1 = "\n".join([str(x) for x in inn_keys] )
b2 = "\n".join([str(x) for x in inn_values] )
感谢您的任何建议。
【问题讨论】:
标签: python python-2.7 dictionary join python-2.x