Sorry, I didn´t know that I couldn´t ask questions about the homework... 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 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 <st...@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: > > [a-z][\1-z][\2-z][\3-z][\4-z].**..[\99-z] > > This is related to the reason you can't parse indefinitely nested > parentheses using a regular expression. > > > > > -- > Steven > > ______________________________**_________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor> > -- *Yours faithfully, Dinara Vakhitova*
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor