Determining Position in a List

Let’s say I have a list [2, 6, 1, 9]. Is it possible to get the position of the number in the list? For example if 6 is the input, the output would be 2 because it"s the second number in the list.

You can make a parallel list and use a conditional statement. The graph Desmos | Graphing Calculator shows an example of how to get the first occurence of a 6 in a list, though it doesn’t quite know what to do if no 6 shows up.

1 Like

That’s exactly what I needed and I was able to replicate it for my needs. Thank you!

I can’t quite get my head around how that works. Could you explain what is happening?

Don’t worry. I’ve got it.

1 Like

You can make fewer expressions by nesting list N and editing position to this:

p_{osition}=min({L=6:[1…length(L)],length(L)+1})

Can you make a version of this that works for points?

It’s a little ugly, but I think this works:

This is essentially the same as Dan’s with an alternate approach, but here are two functions: one that returns the first index and one that returns all the indices. Depending on your needs, you could also adjust the tolerance needed to match points.

1 Like

Oh, using distance is smart, I didn’t think of that at all. Now I also see how you are using a list of indices and limiting that list to conditions that are met, instead of creating a list of valid indices and then finding the smallest. That’s a new technique for me that really simplifies things… I’ll have to remember that!