Pattern Matching Over Python Lists

Chris chrisspen at gmail.com
Mon Jun 23 04:55:58 CEST 2008


On Jun 19, 9:03 pm, John Machin <sjmac... at lexicon.net> wrote:
> On Jun 20, 10:45 am, Chris <chriss... at gmail.com> wrote:
>
> > On Jun 17, 1:09 pm, bearophileH... at lycos.com wrote:
>
> > > Kirk Strauser:
>
> > > > Hint: recursion.  Your general algorithm will be something like:
>
> > > Another solution is to use a better (different) language, that has
> > > built-in pattern matching, or allows to create one.
>
> > > Bye,
> > > bearophile
>
> > Btw, Python's stdlib includes a regular expression library. I'm not
> > sure if you're trolling or simply unaware of it, but I've found it
> > quite adequate for most tasks.
>
> Kindly consider a third possibility: bearophile is an experienced
> Python user, has not to my knowledge exhibited any troll-like
> behaviour in the past, and given that you seem to be happy using the
> re module not on strings but on lists of integers, may have been
> wondering whether *you* were trolling or just plain confused but just
> too polite to wonder out loud :-)

Fair enough. To help you understand the method I used, I'll give you
this hint. It's true that regex on works on strings. However, is there
any way to convert arbitrarily complex data structures to string
representations? You don't need to be an experienced Python user to
answer to this ;)



More information about the Python-list mailing list