# Determining Position in a List

**URL:** <https://cl.desmos.com/t/determining-position-in-a-list/430>\
**Category:** Questions\
**Created:** [March 30, 2019, 1:48pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430 "2019-03-30T13:48:25Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwinske](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/cwinske/32/3106_2.png) [@cwinske](https://cl.desmos.com/u/cwinske)\
**Post date:** [March 30, 2019, 1:48pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/1 "2019-03-30T13:48:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sergeballif](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sergeballif/32/231_2.png) [@sergeballif](https://cl.desmos.com/u/sergeballif)\
**Post date:** [March 31, 2019, 10:18pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/2 "2019-03-31T22:18:38Z")

</div>

You can make a parallel list and use a conditional statement. The graph [Desmos | Graphing Calculator](https://www.desmos.com/calculator/ttvblil6w9) 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.

---

<div class="post-metadata">

**Author:** ![cwinske](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/cwinske/32/3106_2.png) [@cwinske](https://cl.desmos.com/u/cwinske)\
**Post date:** [April 1, 2019, 3:36pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/3 "2019-04-01T15:36:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SeanMaths4EAL](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/seanmaths4eal/32/289_2.png) [@SeanMaths4EAL](https://cl.desmos.com/u/SeanMaths4EAL)\
**Post date:** [June 9, 2019, 9:49pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/4 "2019-06-09T21:49:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SeanMaths4EAL](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/seanmaths4eal/32/289_2.png) [@SeanMaths4EAL](https://cl.desmos.com/u/SeanMaths4EAL)\
**Post date:** [June 9, 2019, 9:53pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/5 "2019-06-09T21:53:10Z")

</div>

Don’t worry. I’ve got it.

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [October 23, 2019, 6:37pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/6 "2019-10-23T18:37:00Z")

</div>

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})

---

<div class="post-metadata">

**Author:** ![1\_1](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/1_1/32/3768_2.png) [@1\_1](https://cl.desmos.com/u/1_1)\
**Post date:** [September 7, 2022, 5:57pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/7 "2022-09-07T17:57:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [September 8, 2022, 7:19am UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/8 "2022-09-08T07:19:54Z")

</div>

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

> **[Find first instance of a point in a list](https://www.desmos.com/calculator/1xznoc6ajf)**
>
> Find first instance of a point in a list

---

<div class="post-metadata">

**Author:** ![cwinske](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/cwinske/32/3106_2.png) [@cwinske](https://cl.desmos.com/u/cwinske)\
**Post date:** [September 8, 2022, 10:54am UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/9 "2022-09-08T10:54:57Z")

</div>

This is essentially the same as Dan’s with an alternate approach, but [here](https://www.desmos.com/calculator/dwtmwavmbx) 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.

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [September 8, 2022, 5:23pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/10 "2022-09-08T17:23:05Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Matt\_Abbott](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/matt_abbott/32/4781_2.png) [@Matt\_Abbott](https://cl.desmos.com/u/Matt_Abbott)\
**Post date:** [February 9, 2024, 8:06pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/11 "2024-02-09T20:06:51Z")

</div>

you can even replace length(L)+1 with infty which will give you undefined if the given number isn’t in the list, which I think would be better.

---

<div class="post-metadata">

**Author:** ![Haziq](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/haziq/32/5278_2.png) [@Haziq](https://cl.desmos.com/u/Haziq)\
**Post date:** [June 18, 2024, 8:27pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/12 "2024-06-18T20:27:55Z")

</div>

Actually the most efficient way, but retrieving multiple positions of an element and removing the others indices from a list would be by filtering. [1…l\_ist.length][l\_ist=value]  
https://www.desmos.com/calculator/3bv7bxmucw?embed

---

<div class="post-metadata">

**Author:** ![bubu0822](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@bubu0822](https://cl.desmos.com/u/bubu0822)\
**Post date:** [November 3, 2025, 4:51pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/13 "2025-11-03T16:51:45Z")

</div>

This does work on a general level, but if you try to use that in a list, it’ll break and give an error.

[[1…l\_ist.length][l\_ist=value]…1]

Thankfully, adding [1] to the end of it magically makes it function again.

[[1…l\_ist.length][l\_ist=value][1]…1]

---

<div class="post-metadata">

**Author:** ![NTMDev](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/ntmdev/32/7141_2.png) [@NTMDev](https://cl.desmos.com/u/NTMDev)\
**Post date:** [November 4, 2025, 1:01pm UTC](https://cl.desmos.com/t/determining-position-in-a-list/430/14 "2025-11-04T13:01:42Z")

</div>

Yes, the reason it was an error because `[1…l_ist.length][list=value]` could have multiple matches, or just one, which results into a list. And since desmos cannot have lists inside lists, there is an error.
