Scott David Daniels wrote: > Felix Collins wrote: >> I have an "outline number" system like >> 1 >> 1.2 >> 1.2.3 >> I want to parse an outline number and return the parent. > > Seems to me regex is not the way to go: > def parent(string): > return string[: string.rindex('.')]
Absolutely, regex is the wrong solution for this problem. I'd suggest using rsplit, though, since that will Do The Right Thing when a top-level outline number is passed: def parent(string): return string.rsplit('.',1)[0] Your solution will throw an exception, which may or may not be the right behaviour. -- http://mail.python.org/mailman/listinfo/python-list