Stedents Question
Andrae Muys
amuys at shortech.com.au
Sun Mar 3 20:56:49 EST 2002
Michael Janssen <Janssen at rz.uni-frankfurt.de> wrote in message news:<3c811073 at nntp.server.uni-frankfurt.de>...
> 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.
>
> def findABBC(str):
> a=0
> b=0
> while str:
> for n in str:
> if n=="a":
> a=1
> break
> if a==1 and n=="b":
> b=b+1
> break
> if a==1 and n=="c":
> print "a"+"b"*b+"c"
> a, b = 0, 0
> break
> if n!=[a-c]:
> a, b = 0, 0
> break
> str=str[1:]
>
> produces every ab+c-string in str. But there must be something easier.
> Something smaller ;-)
>
Probably, but given that this is someones homework we probably
shouldn't discuss this until next week (presumably after the
tutorial's due).
Andrae
More information about the Python-list
mailing list