I have a dict like this:
{1: ['1,2,3', '4,5,6', '7,8']}
the dict can be variable in the number of list items but always 1 dict item. How do I merge it to
{1: ['1,2,3,4,5,6,7,8']}
?
Thanks
I have a dict like this:
{1: ['1,2,3', '4,5,6', '7,8']}
the dict can be variable in the number of list items but always 1 dict item. How do I merge it to
{1: ['1,2,3,4,5,6,7,8']}
?
Thanks
>>> d
{1: ['1,2,3', '4,5,6', '7,8'], 2: ['9,10', '11']}
>>> for k,v in d.iteritems():
... d[k] = [",".join(v)]
...
>>> d
{1: ['1,2,3,4,5,6,7,8'], 2: ['9,10,11']}
in your case, you just need concat a string.
But if you want to merge the collection, try this:
a = [1, 2, 3]
b = [3, 4, 5]
a.extend(b)
print a
[1, 2, 3, 3, 4, 5]