Suresh Jeevanandam wrote:
> I got it:
> dict([k.split('=') for k in s.split(',')])
> 
> Suresh Jeevanandam wrote:
> 
>>Given a string
>>s = 'a=1,b=2'
>>
>>I want to create a dictionary {'a': '1', 'b': '2'}
>>
>>I did,
>>
>>dict(map(lambda k: k.split('='), s.split(',')))
>>
>>Is it possible to get rid of the lambda here, without having to define 
>>another function just for this.
>>
>>Is this the easiest/straight-forward way to do this?
>>

In Python 2.4 you don't even need to construct the list, you can just 
use a generator expression instead:

dict(k.split('=') for k in s.split(','))

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to