Splitting string into dictionary

David Pratt fairwinds at eastlink.ca
Fri Jul 1 07:57:05 CEST 2005


Thanks George!  You guys are great!  I am always learning.  Python is 
awesome!!

On Friday, July 1, 2005, at 02:33 AM, George Sakkis wrote:

> "Robert Kern" wrote:
>
>> Ignore the last message.
>>
>> translations = [x.strip(" '") for x in line.split('|')]
>> d = dict(zip(translations[::2], translations[1::2]))
>
> Or in case you're working with a lot and/or huge records, the second
> line can be more efficiently written as:
>
> from itertools import izip, islice
> d = dict(izip(islice(translations,0,None,2),
>               islice(translations,1,None,2)))
>
> George
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list