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

John Machin sjmachin at lexicon.net
Tue May 16 02:18:55 EDT 2006


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 the set of
targets.

It's not 100% apparent whether it is possible that there can be more
than one target in the inappropriately named file2 (it is a string,
isn't it?). If so, then  write your own findall-like loop wrapped
around steps 2 & 3 above. Compile the regex in advance.

HTH,
John




More information about the Python-list mailing list