Splitting string into dictionary
Christopher Subich
spam.csubich+block at block.subich.spam.com
Sat Jul 2 13:30:20 EDT 2005
Robert Kern wrote:
> David Pratt wrote:
>
>> I have string text with language text records that looks like this:
>>
>> 'en' | 'the brown cow' | 'fr' | 'la vache brun'
> translations = [x.strip(" '") for x in line.split('|')]
> d = dict(zip(translations[::2], translations[1::2]))
One caevat is that this assumes that the proto-list doesn't have any '|'
inside the actual text.
More information about the Python-list
mailing list