Given the array a = [1,1,12,3,5,8,13,21]
I can slice off the first 3 elements like a[:3]
giving [1,1,2]
. What I want is to slice off up to the element of vlaue i
(e.g. if i=8
I want [1,1,12,3,5,8]
or [1,1,12,3,5]
(I can work with either)).
This works:
return a[:a.index(i)]
but only if I give it a value that's in the array.
Is there a clean built in way to do this that does something sane on the missing value case?