Replace every other occurence in list

Hello fellow Dynamo users!!

I’m stuck on this little list manipulation. I have a list of 0’s, 1’s, and 2’s (green list below). What I need done is whenever the number 1 appears a 2nd, 4th, 6th, etc. time in the list I’d like it to change to the number 3 (pink list below). The lists could get really long and the 1’s can appear at any index.

After the list has the 3’s in it I’ll be able to use IF commands for all the 1’s, 2’s, and 3’s to trim curves by TrimByEndParameter(1’s), TrimByParameter(2’s), and TrimByStartParameter(3’s).

You could do this really quickly with python. Just have a boolean check on whether you’re on a first or second 1.

It’s should also be doable with OotB nodes, but will take a bit of list management. I would start with getting all indices of 1 and then converting every other index to 3 to place back in the original list.

1 Like

A couple of ways with nodes …

replace.dyn (45.1 KB)

2 Likes

Thank you for the help. I completely forgot about list.transpose. There are so many nodes that I’m bound to for get another simple one.

1 Like