On Feb 8, 5:06 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > I need to search list a for the sequence of list b > > def list_contains(a, b): > return any(a[i:i+len(b)] == b for i in range(len(a) - len(b) + 1)) > > list_contains(range(1, 7), [2, 3, 4]) > > -- > Paul Hankin
This is more careful but not necessarilly faster in python: def issubseq(s, l): indices = [0] try: for x in l: indices = [i+1 for i in indices if s[i] == x] indices.append(0) return indices[0] == len(s) except IndexError: return True issubseq('m&e', 'spam&eggs) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list