reusing parts of a string in RE matches?

Mirco Wahab wahab at chemie.uni-halle.de
Thu May 11 16:58:17 EDT 2006


Hi John

> Ah, I see the difference. In Python you get a list of tuples, so there 
> seems to be a little extra work to do to get the number out.

Dohh, after two cups of coffee
ans several bars of chocolate
I eventually mad(e) it ;-)

In Python, you have to deconstruct
the 2D-lists (here: long list of
short lists [a,2] ...) by
'slicing the slice':

   char,num = list[:][:]

in a loop and using the apropriate element then:

   import re

   t = 'a1a2a3Aa4a35a6b7b8c9c';
   r =  r'(\w)(?=(.)\1)'
   l = re.findall(r, t)

   for a,b in (l[:][:]) : print  b

In the moment, I find this syntax
awkward and arbitary, but my mind
should change if I'm adopted more
to this in the end ;-)

Regards,

M.



More information about the Python-list mailing list