Re: using target words from arrays in regex, pythons version of perls 'map'

2006-05-16 Thread Edward Elliott
John Machin wrote: > Would you believe "steps 3 & 4"? How about "two pops and a pass?" Quick! Lower the cone of silence! -- Edward Elliott UC Berkeley School of Law (Boalt Hall) complangpython at eddeye dot net -- http://mail.python.org/mailman/listinfo/python-list

Re: using target words from arrays in regex, pythons version of perls 'map'

2006-05-15 Thread Paul McGuire
"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Mon, 15 May 2006 19:41:39 -0500, Lance Hoffmeyer > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > > I would have something similar to perl above: > > > > > > targets = ['OVERALL RATING', > >

Re: using target words from arrays in regex, pythons version of perls 'map'

2006-05-15 Thread John Machin
Would you believe "steps 3 & 4"? -- http://mail.python.org/mailman/listinfo/python-list

Re: using target words from arrays in regex, pythons version of perls 'map'

2006-05-15 Thread John Machin
Think about how well the above solutions scale as len(targets) increases. 1. Make "targets" a set, not a list. 2. Have *ONE* regex which includes a bracketed match for a generic target e.g. ([A-Z\s]+) 3. Do *ONE* regex search, not 1 per target 4. If successful, check if the bracketed gizmoid is in

Re: using target words from arrays in regex, pythons version of perls 'map'

2006-05-15 Thread Paddy
I don't like string interpolation within REs, it pops me out of 'RE mode' as I scan the line. Maybe creating a dict of matchobjects could be used in the larger context?: dict( [(t, re.search(t+regexp_tail, file2) for t in targets] ) (untested). - Pad. -- http://mail.python.org/mailman/listi

using target words from arrays in regex, pythons version of perls 'map'

2006-05-15 Thread Lance Hoffmeyer
Hey all, in perl I was able to use the same regular expression multiple times changing one part of it via a previously defined array and put the results into a new array IN PERL: my @targets = ('OVERALL RATING', 'CLOTHING', ' ITEMS', 'ACCESSORIES',