/ Published in: Python

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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
URL: http://stackoverflow.com/questions/425604?sort=oldest#sort-top
Comments
