How to return the index of an element in SArray?

User 5317 | 6/23/2016, 12:28:40 AM

For example, for a = SArray([6,7,8,9,10,11,12,13]), I want a index method like a.index(6) returning 0.

I believe it is a common functionality but I failed to find any related method in the api doc.

Comments

User 1774 | 6/23/2016, 10:36:33 AM

Indeed, this is not implemented. Here's a workaround, though: python def index(sa, value): return (sa == value).argmax() And then: `python

index(SArray([6,7,8,9,10,11,12,13]), 6) # your input 0 index(SArray([6,7,8,9,10,11,12,13, 6]), 6) # your input + [6] 0 `