A
Alan Rodricks
Guest
Hi
Is there a command that will give me the index of an element in a
list
Regards
Alan Rodricks
Is there a command that will give me the index of an element in a
list
Regards
Alan Rodricks
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
easier would be to use nth(0 a) however i think the question was about the opposite.a = list( 1 2 3)
listToVector(a)[0]
One of the possible solutions would be to convert that to an array and
then get the element with the given index
something like this,
a = list( 1 2 3)
listToVector(a)[0]
Partha
Alan Rodricks wrote:
Hi
Is there a command that will give me the index of an element in a
list
Regards
Alan Rodricks
I don't think there is a command to do this directly, so I always do this:
;; define procedure
procedure(getElemIndex(elem list)
let((foundList)
when(foundList = member(elem list)
length(list)-length(foundList)
)
)
) ; ** when foundList **
;; test and examine usage
a = list(1 2 3 4 5 6 7 8 9 1 2 3 4 5)
getElemIndex(1 a) => 0
getElemIndex(9 a) => 8
getElemIndex(10 a) => nil
Obviously, it only reports the index of the first match.
HTH,
Trevor
tattvamasi@gmail.com wrote:
One of the possible solutions would be to convert that to an array and
then get the element with the given index
something like this,
a = list( 1 2 3)
listToVector(a)[0]
Partha
Alan Rodricks wrote:
Hi
Is there a command that will give me the index of an element in a
list
Regards
Alan Rodricks