python - Saving dictionary keys as strings -
i have following dictionary:
ordereddict([(u'b1', ordereddict([(u'ip', u'199.0.0.1'), (u'port', u'1122')])), (u'b2', ordereddict([(u'ip', u'199.0.0.1'), (u'port', u'1123')]))])
i want create string take keys dictionary , join them put :
in between, result be
(b1:b2)
there can lot of keys in dictionary. can me out that?
use str.join
>>> collections import ordereddict >>> dic = ordereddict([(u'b1', ordereddict([(u'ip', u'199.0.0.1'), (u'port', u'1122')])), (u'b2', ordereddict([(u'ip', u'199.0.0.1'), (u'port', u'1123')]))]) >>> ":".join(dic) u'b1:b2'
Comments
Post a Comment