Reputation: 41
I want to retrieve the position of a nested list given an element of the nested list. Is this possible without traversing through all the nested lists?
For example, given a list of lists, [[1.1 a b][1.2 c d][1.3 e f]] I'd like to get the position 1 given element 1.2 .
Upvotes: 2
Views: 832
Reputation: 14972
This is similar to what was asked in this question: NetLogo : How to do multiple operations on lists (find, get , replace, remove , search elements within lists , ....)
In your particular case, you can use a combination of map
to extract the sublist element you're looking for and position
to get its index:
observer> show position 1.2 map first [[1.1 "a" "b"][1.2 "c" "d"][1.3 "e" "f"]]
observer: 1
Upvotes: 2