Replace consecutive similar numbers in a list

is there any way to replace one of the consecutive similar numbers in a list with Null or 0 and not delete them?
for example: (1, 2, 2, 3) to (1, Null, 2, 3)

Might the value 2 occur again later on in the list?

yeah. but not consecutive. it might be like: 1, 2, 2, 3, 2, 4, 5, 5… and i need: 1, null, 2, 3, 2, 4, null, 5

I ask because this seems to work, but it won’t if the numbers happen again: NullifyDuplicates.gh (23.3 KB)

that is the problem. the numbers might show up again

This seems to work.


ReplaceConsecutiveDuplicates.gh (9.8 KB)

1 Like

Perfect!! Thanks a lot! I should have asked earlier:)

Actually, Michael’s solution does not work (see items 2 & 14, and 6 & 13, they are the same). No offense!
I found a solution that works with random lists, although it’s probably not the simplest way. It would also need some adjusments if you want it to work on more than one list at a time.


Cull duplicates.gh (13.5 KB)

Actually, Michael’s solution does not work (see items 2 & 14, and 6 & 10

It does work, They are not consecutive. Read the question, the goal is to replace consecutive duplicates, not duplicates in general.

Oops, sorry! You’re right, my bad…

No Worries, yours is good for another situation.

@ala_hzd and if you want it to read like your post describes where the nulls come first then the one remaining of the conseccutive duplicates you can just reverse the start list, then reverse it back at the end.


ReplaceConsecutiveDuplicatesRev.gh (12.7 KB)