[Tutor] A Demolished Function

Kirby Urner urnerk@qwest.net
Fri, 16 Nov 2001 22:45:02 -0800


>
>After writing this function, though, I still feel tense and apprehensive.
>Does anyone see any improvements one could make to make the function
>easier to read?  Any criticism or dissension would be great.  Thanks!

Some inconsequential coding changes -- not necessarily easier
to read:

def conservativeSplit(regex, stuff):
     """Split 'stuff' along 'regex' seams."""
     fragments = []
     while 1:
         match = regex.search(stuff)
         if not match: break
         begin, end = match.span()
         if not begin == 0:
             fragments.append(stuff[0 : begin])
         fragments.append(stuff[begin : end])
         stuff = stuff[end :]
     if stuff: fragments.append(stuff)
     return fragments

Kirby