The reverse of group by key, or how to replace all but last value associated with a x time repeated number

Hi Dynamoers,

My problem:

  • I have a list of number repeated a random number of time
  • with each number comes a text data (Exclus)
  • I want to replace each value but the last associated with each number and get that list of value back to original order.

I got the first part done with a group by key, but to get the correct output I would need to “reverse” that group by key operation. _ or maybe there is another way to approach the problem

How do I do that?

My proof of concept below

allButLastProblem.dyn (44.5 KB)

Sorry I did it using an Imperative block (@kennyb6 would kill me), but this is beacuse List.ReplaceItemAtIndex is not working as expected.

I still think that using Python would be the easiest way, but I thought that it is more visual and comprehensible that way.

allButLastProblem.dyn (25.7 KB)


@mellouze I was trying something as well, with a different approach, so I post it anyway.
List.ReplaceItemAtIndex works for only one index, you need to use the node in the Clockwork package :wink:

ReplaceItems.dyn (18.2 KB)


Yeah, I thought about using the Clockwork package as well, but I wanted to keep it down to OotB nodes :slight_smile: (Nota : the Clockwork node that you used is actually written in Python haha :stuck_out_tongue: ))
Great way of solving this problem btw :smiley:

1 Like

Thank you guy,

You got it nailed in no time. This is part of a much bigger script and that was a bit out of my comfort zone.

Sorry I cannot mark your solution as well @lucamanzoni