di.marvellous at gmail.com
Sat Nov 5 00:38:55 CET 2011
Sorry, I didn´t know that I couldn´t ask questions about the homework...
I wanted to do it recursively, like this:
string = string.lower()
check_pair = re.compile("([a-z])[\1-z]")
the only problem is that this regex doesn´t work and this case is not
specified in the Python documentation...
Excuse me for disturbing you.
2011/11/5 Steven D'Aprano <steve at pearwood.info>
> Dinara Vakhitova wrote:
>> Thank you for your answer, Steven.
>> Of course it would have been easier to write this function,
>> but unfortunately my task is to do it with a regular expression :(
> Is this homework? You should have said so.
> I don't understand questions like this. Do carpenters ask their
> apprentices to cut a piece of wood with a hammer? Do apprentice chefs get
> told to dice carrots using only a spoon? Computer programming is the only
> skill I know of where teachers routinely insist that students use
> inappropriate tools to solve a problem, just to prove they can do it.
> In any case, if this is even possible using regular expressions -- and I
> don't think it is -- I have no idea how to do it. Good luck. Maybe somebody
> else might have a clue.
> I don't think it's possible because you don't know how many characters the
> string will have. Even if [\1-z] works (which it doesn't), you still have
> the same problem that you don't know where to stop:
> This is related to the reason you can't parse indefinitely nested
> parentheses using a regular expression.
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor