problem of converting a list to dict

Matt Nordhoff mnordhoff at mattnordhoff.com
Wed Jan 9 23:54:32 CET 2008


bsneddon wrote:
> This seemed to work for me if you are using 2.4 or greater and
> like list comprehension.
>>>> dict([ tuple(a.split("=")) for a in mylist[1:-1]])
> {'mike': 'manager', 'paul': 'employee', 'tom': 'boss'}
> 
> should be faster than looping

That's what he's doing (well, a generator expression, not a listcomp).
It's just split across multiple lines (ew).
-- 



More information about the Python-list mailing list