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 th
David Pratt wrote:
> I have string text with language text records that looks like this:
>
> 'en' | 'the brown cow' | 'fr' | 'la vache brun'
Pardonnez-moi, but I thought "how now brown cow" translated into
something like "comme maintenant vache brune" -- something about the
adjectives agreeing
On Friday 01 July 2005 12:35 am, David Pratt wrote:
> Wow Robert that is incredible python magic! I am trying to figure out
> what this is doing since my attempts were regex and some long string
> splitting and collection.
Try it out in the interpreter:
Test data:
>>> test = "'en' | 'the brown
"David Pratt"
> Thanks George! You guys are great! I am always learning. Python is
> awesome!!
Yeap, that was the reaction of many/most of us when we stumbled upon
python. Welcome aboard !
George
--
http://mail.python.org/mailman/listinfo/python-list
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], transla
"David Pratt" wrote:
> Wow Robert that is incredible python magic! I am trying to figure out
> what this is doing since my attempts were regex and some long string
> splitting and collection.
>
> Ok. So it is a list comprehension and then collection. What is zip
> doing in the second line?
>
> R
Pretty amazing Devan! Great regex! Thank you.
Regards,
David
On Friday, July 1, 2005, at 02:29 AM, Devan L wrote:
> One line solution.
> dict(re.findall(r"'(.+?)' \| '(.+?)'(?:\s\||$)",yourtexthere))
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mai
Wow Robert that is incredible python magic! I am trying to figure out
what this is doing since my attempts were regex and some long string
splitting and collection.
Ok. So it is a list comprehension and then collection. What is zip
doing in the second line?
Regards
David
On Friday, July 1,
"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 i
One line solution.
dict(re.findall(r"'(.+?)' \| '(.+?)'(?:\s\||$)",yourtexthere))
--
http://mail.python.org/mailman/listinfo/python-list
David Pratt wrote:
> I have string text with language text records that looks like this:
>
> 'en' | 'the brown cow' | 'fr' | 'la vache brun'
>
> Two or more language records can exist in each string (example above
> shows 2 - but could contain more)
> The second vertical line character in the ex
David Pratt wrote:
> I have string text with language text records that looks like this:
>
> 'en' | 'the brown cow' | 'fr' | 'la vache brun'
>
> Two or more language records can exist in each string (example above
> shows 2 - but could contain more)
> The second vertical line character in the ex
I have string text with language text records that looks like this:
'en' | 'the brown cow' | 'fr' | 'la vache brun'
Two or more language records can exist in each string (example above
shows 2 - but could contain more)
The second vertical line character in the example above is the record
break
13 matches
Mail list logo