Stedents Question

Jeff Shannon jeff at ccvcorp.com
Mon Mar 4 16:43:18 EST 2002


Geert-Jan Van den Bogaerde wrote:

> On Sat, 2002-03-02 at 00:45, Tony K wrote:
> > The question below is a tutorial question that stumps me.  Any suggestions
> > would be appreciated.
> > Tony
> >
> > Write a Python function findABBC which takes a single string as parameter
> > and returns all substrings thereof which match the regexp pattern ab+c. You
> > are NOT allowed to use the re module.
> >
>
> Haven't used regexps in a while, but I believe that just means:
>
> def findABBC(str):
>     return str == "a" + "b" * len(str[1:-1]) + "c"

Except that the spec was to return all matching substrings.  You're simply
testing to see if the entire string matches that pattern, and returning a boolean
true/false.  (This could theoretically be used as a helper function in a
solution, though I suspect that there's a better way to go about it.)

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list