I have a list like:
x = ['user=inci', 'password=1234', 'age=12', 'number=33']
I want to convert x to a dict like:
{'user': 'inci', 'password': 1234, 'age': 12, 'number': 33}
what's the quickest way?
You can do this with a simple one liner:
dict(item.split('=') for item in x)
List comprehensions (or generator expressions) are generally faster than using map
with lambda
and are normally considered more readable, see here.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments