On Friday, September 9, 2016 at 11:51:25 AM UTC+5:30, Rustom Mody wrote:
> And if the original 'a' looked something like
> >>> a="p:1,q:2,r:42"
> 
> then you probably want something like:
> 
> >>> {k:v for item in a.split(',') for k,v in [item.split(':')]}
> {'q': '2', 'p': '1', 'r': '42'}
> >>>

Well if the a did look like
>>> a="a:1,b:2,c:42"

what we would need is likely to be
>>> {k:int(v) for item in a.split(',') for k,v in [item.split(':')]}
{'a': 1, 'c': 42, 'b': 2}

Likely, but not necessary -- eg we would not want leading zeroes in a 
phone number to disappear
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to