python - Parse dict of dicts to string -
i have dictionary following structure :
{1: {'message': u'test', 'user': u'user1'}, 2: {'message': u'test2', 'user': u'user2'}}
i'd create string containing values inner dictionary in form :
string = "<span>test1</span><span>user1</span><br /> <span>test2</span>..."
i've tried dict.keys()
, dict.values()
, (k,v) k, v in dict
cannot make work. proper way ?
>>> d={1: {'message': u'test', 'user': u'user1'}, 2: {'message': u'test2', 'user': u'user2'}} >>> ''.join('<span>%(message)s</span><span>%(user)s</span><br/>' % v k,v in sorted(d.items())) u'<span>test</span><span>user1</span><br/><span>test2</span><span>user2</span><br/>'
Comments
Post a Comment