[Tutor] regexp

Sander Sweers sander.sweers at gmail.com
Sat Nov 5 01:29:50 CET 2011

On 5 November 2011 00:38, Dinara Vakhitova <di.marvellous at gmail.com> wrote:
> Sorry, I didn´t know that I couldn´t ask questions about the homework...

This list is meant to help with learning python and not  to do
homework assignments. So if you get stuck with something yes you can
post it but be open about it and show what you have tried (code). I
suspect then people on this list will provide guidance and drop hints
but leave the *writing* of the code to you.

> I wanted to do it recursively, like this:
> def check_abc(string):
>     string = string.lower()
>     check_pair = re.compile("([a-z])[\1-z]")
>     if check_pair.match(string):
>         if check_abc(string[1:]):
>             return True
>         else:
>             return False
>     else:
>         return False

Is using regular expressions a requirement? As Steve already pointed
out this is a hard problem to solve (if it can be solved at all) with
regex. So unless the home work requires regex just drop it.

> the only problem is that this regex doesn´t work and this case is not
> specified in the Python documentation...

There is a separate howto on http://docs.python.org/howto/regex.html
does a decent job.

> Excuse me for disturbing you.

Well, people on this list are volunteers and do not get paid for
answering questions. He actually gave you good and well reasoned
advice and if I was you I'd take it.


More information about the Tutor mailing list