python:字典到字符串,自定义格式? [英] python: dictionary to string, custom format?
本文介绍了python:字典到字符串,自定义格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我仅显示密钥,每行新行:
currently I'm displaying keys only, each in new line:
'<br/>'.join(mydict)
如何显示他们像键 ::
how do I display them like key:: value, each in the new line?
推荐答案
通过 dict.items ()
将产生一个键的迭代器,值tuple:
Go through the dict.items()
iterator that will yield a key, value tuple:
'<br/>'.join(['%s:: %s' % (key, value) for (key, value) in d.items()])
这篇关于python:字典到字符串,自定义格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文