list to dict?

Sean Ross sross at
Wed Mar 12 05:19:02 CET 2003

>>> seq = ["name=matt","sex=male","age=24"]
>>> m = dict([s.split('=') for s in seq])
>>> m
{'age': '24', 'name': 'matt', 'sex': 'male'}


m = dict(map(lambda s:  s.split('='), seq))


"Matt Neuber" <mneuber at> wrote in message
news:8fc3c459.0303111859.7ebbd60a at
> This is probably a pretty "newbish" question but...
> Say I have a list, and it looks something like
> ["name=matt","sex=male","age=24"] (etcetera) and I wanted to convert
> it to a dictionary: {'name': 'matt', 'sex': 'male', 'age': '24'} and
> so forth.
> Is there an easy way to do this? I've tried a number of things, but I
> have run into problems because of the literals...

More information about the Python-list mailing list