我有一个列表与两个项目,每个项目是一个字典。现在我想打印这个项目,但是因为这些都是字符串,所以python写的是字典而不是名字。任何建议?打印列表项目 - python
sep_st = {0.0: [1.0, 'LBRG'], 0.26: [31.0, 'STIG']}
sep_dy = {0.61: [29.0, 'STIG'], 0.09: [25.0, 'STIG']}
sep = [sep_st, sep_dy]
for item in sep:
for values in sorted(item.keys()):
p.write (str(item)) # here is where I want to write just the name of list element into a file
p.write (str(values))
p.write (str(item[values]) +'\n')
您可以添加预期的输出吗? –
'字典'没有名字。这是对变量如何工作的误解。你可以在'dict'里面放一个'name'键,如果这是你需要的,就查找它。 – khelwood
@BhargavRao:而不是“sep_st”它写入整个字典,而不只是名称 – Fatemeh