Re: creating an (inefficent) alternating regular expression from a list of options

2008-09-18 Thread metaperl.com
On Sep 9, 12:42 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > > you may also want to do re.escape on all the words, to avoid surprises > when the choices contain special characters. yes, thank you very much: import re def oneOf(s): alts = sorted(s.split(), reverse=True) alts = [re.esca

Re: creating an (inefficent) alternating regular expression from a list of options

2008-09-18 Thread metaperl.com
On Sep 9, 9:23 am, [EMAIL PROTECTED] wrote: >     >> I really dont care if theexpressionis optimal. So the goal is >     >> something like: > >     >> vowel_regexp = oneOf("a aa i ii u uu".split())  # yielding r'(aa|a|uu| >     >> u|ii|i)' > >     >> Is there a public module available for this purp

creating an (inefficent) alternating regular expression from a list of options

2008-09-09 Thread metaperl.com
Pyparsing has a really nice feature that I want in PLY. I want to specify a list of strings and have them converted to a regular expression. A Perl module which does an aggressively optimizing job of this is Regexp::List - http://search.cpan.org/~dankogai/Regexp-Optimizer-0.15/lib/Regexp/List.pm

Please explain collections.defaultdict(lambda: 1)

2007-11-06 Thread metaperl.com
I'm reading http://norvig.com/spell-correct.html and do not understand the expression listed in the subject which is part of this function: def train(features): model = collections.defaultdict(lambda: 1) for f in features: model[f] += 1 return model Per http://docs.python.org/