KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In Python, you can specify start and end indices when searching for a list element: >>> l = ['a', 'b', 'a'] >>> l.index('a') 0 >>> l.index('a', 1) # begin at index 1 2 >>> l.index('a', 1, 3) # begin at index 1 and stop before index 3 2 >>> l.index('a', 1, 2) # begin at index 1 and stop before index 2 Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: 'a' is not in list Is there an equivalent feature in Ruby? You can use array slices, but that seems as though it would be less efficient, because of its requiring intermediate objects.
Tags (comma-separated)
Save Edits
Cancel