Replace indexes in list

Hi, I’m looking for a node that will replace a given set of indexes in a list with a new value. I tried my hand at a python definition but no luck… help! What i’m looking for is the indexes of the watch node listed in the red box to be remapped to the input string “wood”

Thanks!

orewao

las

I’m not certain of what you want, but here is my guess:

 

in python you can iterate through a list like this:

 

# this is an example of our index list

list = [0,3,6,12]

this is our input list to modify

list2 = IN[2]

we make a copy of it like this

list3 = list(list2)

for remapIndex in list:

-----list3[remapIndex] = “wood”

OUT = list3


 

 

Have you tried the “GetItemAtIndex” node? I think it will do what you’re looking for:

2014-10-03_123117

Thanks Michael,

The python base you sent really helped. I modified it slightly and its exactly what I was looking for. In the screenshot below IN[2] is a hard coded variable… a single string. would this syntax be the same if one wanted to pass a different value into the remapIndex for each index?

say you had a list of 20.

you need to replace 3 items at 3 different points. you pass in the main list of 20 at IN[0], the indexes to replace are IN[1] (3 values). If one feeds 3 values into IN[2] will remapindex understand that?

Thanks again!

fa

Hey Michael -

no python’s for loop won’t automatically figure out that you want to replace the 3 different indices with the 3 variables, but it’s easy to be explicit about it. This is the kind of problem that dynamo’s replication attempts to solve, we should add a replace at index node.

 

so you’re going to use a slightly different for loop syntax here, since you want to know the INDEX of the item in the list… you’ll do:

 

for index in range(len(list):

remapindex = list[index]

list2[remapindex] = replacementValues[index]

Thanks Michael, Michael, and Dimitar. I’ve submitted the issue to the development backlog (MAGN-4884).