Rita Sue and Bob too

Jeffrey Froman Jeffrey at Fro.man
Fri Aug 20 06:28:55 CEST 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