Re: Composing regex from a list

2011-06-17 Thread TheSaint
Steven D'Aprano wrote: > def compile_alternatives(*args): Thank you all, for these good points. For my eyes seem that explicit or implicit it will take some looping to concatenate the list elements into a string. I will see pypy later. -- goto /dev/null -- http://mail.python.org/mailman/lis

Re: Composing regex from a list

2011-06-16 Thread Vlastimil Brom
2011/6/16 TheSaint : > Hello, > Is it possible to compile a regex by supplying a list? > > lst= ['good', 'brilliant'. 'solid'] > re.compile(r'^'(any_of_lst)) > > without to go into a *for* cicle? > In simple cases, you can just join the list of alternatives on "|" and incorporate it in the pattern

Re: Composing regex from a list

2011-06-16 Thread Steven D'Aprano
On Thu, 16 Jun 2011 20:48:46 +0800, TheSaint wrote: > Hello, > Is it possible to compile a regex by supplying a list? > > lst= ['good', 'brilliant'. 'solid'] > > re.compile(r'^'(any_of_lst)) > > without to go into a *for* cicle? How about this? def compile_alternatives(*args): alternati