reusing parts of a string in RE matches?

Mirco Wahab wahab at chemie.uni-halle.de
Thu May 11 17:08:31 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

(l sould implicitly be decoded
  sequentially as l[:][->a : ->b]
  in the loop context.)

In the moment, I find this syntax
somehow hard to remember, 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