# Replace specific indexes in a list with a corresponding list of value

**URL:** <https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767>\
**Category:** Questions\
**Created:** [June 28, 2026, 7:00pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767 "2026-06-28T19:00:03Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![levi\_robertson42](https://avatars.discourse-cdn.com/v4/letter/l/bc79bd/32.png) [@levi\_robertson42](https://cl.desmos.com/u/levi_robertson42)\
**Post date:** [June 28, 2026, 7:00pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/1 "2026-06-28T19:00:03Z")

</div>

Hello! I’m working on a graph that is supposed to emulate a pixel screen (here: [Computer? | Desmos](https://www.desmos.com/calculator/ma7vbnvskn) ) I found a way to flatten a list and convert from x,y positions to screen positions, but I am having trouble replacing values. I know you can use R\_{eplace}\left(L,i,v\right)=\left[\left\{\operatorname{total}\left(\left\{j=i:1,0\right\}\right)\>0:v,L\left[j\right]\right\}\operatorname{for}j=\left[1...\operatorname{length}\left(L\right)\right]\right] to replace a value in a list, and I was able to modify it to take multiple indexes, but not multiple values. (I kept getting the ‘list in list’ error) Line 20 in the graph is where I have my most recent attempt at solving it, and I want to be able to do something like this:C\_{hange}\left(\left(X,Y,C\right)\right) where X and Y are lists of the screen coordinates and C is a list of the colors to change them to. I have to thank all of you for being so much help!

---

<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:** [June 29, 2026, 12:44pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/2 "2026-06-29T12:44:50Z")

</div>

For `R_{esetScreen}`, are you just trying to change `P_{ixelList}` to the list `(i,j,1)`? If so, I think you can do it more explicitly instead of using your function.

```auto
R_{esetScreen}=P_{ixelList}\to\left[\left(i,j,1\right)\operatorname{for}i=\left[1...S_{creenWidth}S_{creenResolution0}-1\right],j=\left[0...S_{creenHeight}S_{creenResolution0}\right]\right]
```

---

<div class="post-metadata">

**Author:** ![levi\_robertson42](https://avatars.discourse-cdn.com/v4/letter/l/bc79bd/32.png) [@levi\_robertson42](https://cl.desmos.com/u/levi_robertson42)\
**Post date:** [June 29, 2026, 1:04pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/3 "2026-06-29T13:04:31Z")

</div>

I’m actually trying to make the entire list just 1s, and yes, I could do something on the line of repeat(1, length(S\_{creen}), but I wanted to use my fancy function. I think I forgot to mention it in the original post, but where I want to use it is in line 109, (the P\_{layer}\left(d\_t\right) function) where I use it to input the player’s position and have it show a pixel on screen.

---

<div class="post-metadata">

**Author:** ![levi\_robertson42](https://avatars.discourse-cdn.com/v4/letter/l/bc79bd/32.png) [@levi\_robertson42](https://cl.desmos.com/u/levi_robertson42)\
**Post date:** [June 29, 2026, 1:09pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/4 "2026-06-29T13:09:31Z")

</div>

I can make it change only 1 pixel at a time (Here’s what it looks like: [Computer? | Desmos](https://www.desmos.com/calculator/9td8ahbyv3) ) but anything more and it doesn’t like 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:** [June 29, 2026, 7:08pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/5 "2026-06-29T19:08:18Z")

</div>

I’m having a little trouble wrapping my head around it, but your note that it is doing the full list instead of length(PosColor) is because your R\_eplace function is dependent on the length of your list argument, which is P\_ixelList, not PosColor. I think _maybe_ updating C\_hange with this added to the end, if I’m understanding correctly.

```auto
[1...length(P_{osColor})].join(P_{ixelList})[length(P_{osColor})+1...length(P_{ixelList})])

```

---

<div class="post-metadata">

**Author:** ![levi\_robertson42](https://avatars.discourse-cdn.com/v4/letter/l/bc79bd/32.png) [@levi\_robertson42](https://cl.desmos.com/u/levi_robertson42)\
**Post date:** [June 29, 2026, 7:48pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/6 "2026-06-29T19:48:36Z")

</div>

I’m basically trying to do this: [Replacing multiple elements in a list at once](https://cl.desmos.com/t/replacing-multiple-elements-in-a-list-at-once/7754) , but be able to make the points different colors based on what I input. Line 8 in here is pretty close to what I have [Replace items in list. | Desmos](https://www.desmos.com/calculator/6y3obthlk4) .

---

<div class="post-metadata">

**Author:** ![Guzman\_Tierno](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/guzman_tierno/32/6149_2.png) [@Guzman\_Tierno](https://cl.desmos.com/u/Guzman_Tierno)\
**Post date:** [June 30, 2026, 6:59pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/7 "2026-06-30T18:59:17Z")

</div>

I think this is what you are looking for:  
[https://www.desmos.com/calculator/fhyjtppaag](https://www.desmos.com/calculator/fhyjtppaag)

---

<div class="post-metadata">

**Author:** ![Guzman\_Tierno](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/guzman_tierno/32/6149_2.png) [@Guzman\_Tierno](https://cl.desmos.com/u/Guzman_Tierno)\
**Post date:** [June 30, 2026, 7:21pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/8 "2026-06-30T19:21:44Z")

</div>

What is making you crazy is the function

```auto
indexOf(v,L)= [1...length(L)] [L=v]

```

because you have to be careful that it does return a list (even if it only contains one element) …  
if you only want the first index you need to use

```auto
indexOf(v,L)= [1...length(L)] [L=v][1]

```

---

<div class="post-metadata">

**Author:** ![levi\_robertson42](https://avatars.discourse-cdn.com/v4/letter/l/bc79bd/32.png) [@levi\_robertson42](https://cl.desmos.com/u/levi_robertson42)\
**Post date:** [June 30, 2026, 7:22pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/9 "2026-06-30T19:22:44Z")

</div>

I see… You’re using the P\_{pos} function to replace the values of j with undefined, except for the values of I, and using that to get the right indexes. Very clean. Thank you! This helps a lot.

---

<div class="post-metadata">

**Author:** ![Guzman\_Tierno](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/guzman_tierno/32/6149_2.png) [@Guzman\_Tierno](https://cl.desmos.com/u/Guzman_Tierno)\
**Post date:** [June 30, 2026, 7:31pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/10 "2026-06-30T19:31:25Z")

</div>

It now works:

[https://www.desmos.com/calculator/ffkxcpfv9u](https://www.desmos.com/calculator/ffkxcpfv9u)

---

<div class="post-metadata">

**Author:** ![levi\_robertson42](https://avatars.discourse-cdn.com/v4/letter/l/bc79bd/32.png) [@levi\_robertson42](https://cl.desmos.com/u/levi_robertson42)\
**Post date:** [June 30, 2026, 7:42pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/11 "2026-06-30T19:42:20Z")

</div>

Yep, thank you again! (I forgot that you had to click the solution button for a minute there 🙂 )

---

<div class="post-metadata">

**Author:** ![Guzman\_Tierno](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/guzman_tierno/32/6149_2.png) [@Guzman\_Tierno](https://cl.desmos.com/u/Guzman_Tierno)\
**Post date:** [June 30, 2026, 7:45pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/12 "2026-06-30T19:45:08Z")

</div>

no problem, glad to help, and nice job with your idea …

---

<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:** [July 1, 2026, 1:18pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/13 "2026-07-01T13:18:45Z")

</div>

I had the same issue debugging something yesterday! “Why is this saying it’s a list when I’m seeing a single point as ouput in this line?”

---

<div class="post-metadata">

**Author:** ![Guzman\_Tierno](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/guzman_tierno/32/6149_2.png) [@Guzman\_Tierno](https://cl.desmos.com/u/Guzman_Tierno)\
**Post date:** [July 1, 2026, 3:36pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/14 "2026-07-01T15:36:02Z")

</div>

Yes, the output should be sometyhing like [1] instead of simply 1 … to show that it is a list … but it seems to me that under certain circumstances the square brakets are not there or one is not able to see them.

---

<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:** [July 2, 2026, 1:30pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/15 "2026-07-02T13:30:51Z")

</div>

I realize that’s an issue. I think I’ll pass that to the team. It feels pretty useful to be aware of if you’re trying to debug things.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/f/f5bd144684474e9a2f333002cde9840e52c5dbd3.png) [@system](https://cl.desmos.com/u/system)\
**Post date:** [July 4, 2026, 1:31pm UTC](https://cl.desmos.com/t/replace-specific-indexes-in-a-list-with-a-corresponding-list-of-value/8767/16 "2026-07-04T13:31:05Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
