How about
seq[seq.index(first):].index(second)
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
Here more final version from the idea I threw without testing possibility:
>>> seq
[1, 2, 3, 4, 5, 2]
>>> def dis(seq, first,second):
return seq[seq.index(first):].index(second)-1
>>> dis(seq,2,2)
-1
>>> def dis(seq, first,second):
return seq[seq.index(first)+1:].index(second)
>>> dis(seq,2,2)
3
>>>
So the better form is:
def dis(seq, first,second):
return seq[seq.index(first)+1:].index(second
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852