Return to Snippet

Revision: 18604
at October 4, 2009 00:48 by freephys


Initial Code
def seq_in_seq(subseq, seq):
...     while subseq[0] in seq:
...         index = seq.index(subseq[0])
...         if subseq == seq[index:index + len(subseq)]:
...             return index
...         else:
...             seq = seq[index + 1:]
...     else:
...         return -1
... 
>>> seq_in_seq([5,6], [4,'a',3,5,6])
3
>>> seq_in_seq([5,7], [4,'a',3,5,6])
-1

Initial URL
http://stackoverflow.com/questions/425604?sort=oldest#sort-top

Initial Description


Initial Title
Determine if a Sequence is in another sequence in Python

Initial Tags


Initial Language
Python