How to count unique number in GH? I think need a help on python

As you see, in the left panel, there are five unique numbers 1, 2, 3, 4, 5, and if you count them, the results are 3, 4, 2, 1, 5, which are in the right panel. I thought of the way to get the right panel in GH but failed. I think there may be a python to resolve it. count unique number.gh (3.5 KB)

Thanks for any help and suggestions!
Capture

Native GH way…
Canvas%20at%2003%3B16%3B31

2 Likes

results are 3, 4, 2, 1, 5

results are actually 34214 (even in your screenshot)

You can do this way additionally if you want to split them out into different branches:


count unique number - MP.gh (9.1 KB)

Wow! That’s great job! Thank you, HS_Kim!!

Thank you, Michael, for your kind help again!

I just tried your code. Now I realize how powerful the “Sets” components are…
Thanks again!

The Python way is set() :slight_smile:

Thank you, Graham, for your suggestion!
Would you please give me more details? Actually I tried python also, but…

Ahh sorry I misread the question
Actually you need a counter:

from collections import Counter

my_counter = Counter(x)

Yeah, that’s what I tried. But it doesn’t work well.

By the way, how do you make the note for each component? That seems so convenient! Now I am always lost in the forest of cells…

1 Like

Got it! Thank you so much, HS_Kim!