intersection - Returning indexes of intersected lists with Python -


i have 2 lists:

1. ['a', 'b', 'c', 'd', 'e', 'c', 'd', 'f'] 2. ['c', 'd'] 

and i'd indexes of intersection a, b:

3. [[2, 3], [5, 6]] 

how python?

also these inputs:

1. ['263', '9', '470', '370', '576', '770', '800', '203', '62', '370', '576', '370', '25', '770', '484', '61', '914', '301', '550', '770', '484', '1276', '108'] 2. ['62', '370', '576'] 

should give:

3. [[8, 9, 10]] 

one way be:

>>> l1 = ['a', 'b', 'c', 'd', 'e', 'c', 'd', 'f'] >>> l2 = ['c', 'd'] >>> [range(i,i+len(l2)) in xrange(len(l1)-len(l2)+1) if l2 == l1[i:i+len(l2)]] [[2, 3], [5, 6]] >>>  

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -