L=[0,8,5,6,4,5,6,14,8]
I want to be able to return the index of [4,5,6] (returning 4 in this example).
L=[0,8,5,6,4,5,6,14,8]
I want to be able to return the index of [4,5,6] (returning 4 in this example).
Here's one way to implement it:
def find_in_list(l, x):
for i in range(len(l) - len(x) + 1):
if l[i:i+len(x)] == x:
return i
Use this instead:
' '.join(map(str,L)).index(' '.join(map(str,x)))/2
EDIT: Thanks to isbadawi for noticing the silly mistake, and solilo for pointing out the huge mistake haha
In [193]: min(i for i in range(len(L)) if L[i:i+len(key)] == key)
Out[193]: 4
In [194]: L=[0,8,5,6,4,5,6,14,8]
In [195]: key=[4,5,6]
In [196]: min(i for i in range(len(L)) if L[i:i+len(key)] == key)
Out[196]: 4