list to dict?

Max M maxm at mxm.dk
Wed Mar 12 02:13:01 EST 2003


Raymond Hettinger wrote:

>>>>s = ["name=matt","sex=male","age=24"]
>>>>dict(map(str.split, s, '='*len(s)))


It was a brilliant idea to make dict take a sequence of 2d sequences as 
an init paramter in 2.2. Most of the examples I have seen using it are 
really short, sweet and obvious.

Though I would probably find this example a little clearer:

s = ["name=matt","sex=male","age=24"]
print dict([pair.split('=') for pair in s])

 >>> {'age': '24', 'name': 'matt', 'sex': 'male'}

-- 

hilsen/regards Max M Rasmussen, Denmark

http://www.futureport.dk/
Fremtiden, videnskab, skeptiscisme og transhumanisme





More information about the Python-list mailing list