find sublist inside list

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon May 4 09:20:34 EDT 2009


John O'Hagan:
> li=['a', 'c', 'a', 'c', 'c', 'g', 'a', 'c']
> for i  in range(len(li)):
>     if li[i:i + 2] == ['a', 'c']:
>         li[i:i + 2] = ['6']

Oh well, I have done a mistake, it seems.
Another solution then:

>>> 'acaccgac'.replace("ac", chr(6))
'\x06\x06cg\x06'

Bye,
bearophile



More information about the Python-list mailing list