Rita Sue and Bob too

Jeffrey Froman Jeffrey at Fro.man
Fri Aug 20 00:28:55 EDT 2004


M. Clift wrote:

> But, how to I find a sequence in a list of unknown size? i.e. this
> sequence in list of other names and replace it with three others?

How about a generator?

def slice(apple, worm, new_worm):
    while apple:
        if worm == apple[:len(worm)]:
            apple = apple[len(worm):]
            yield new_worm
        else:
            yield [apple.pop(0)]

Jeffrey



More information about the Python-list mailing list