Grouping data- how to select most repeated data

I import data from excel, and I have two condition for it
(1) let grasshopper select the most repeated value if there are three repeated value or more
(2) let grasshopper selected the highest value for else value.

For example, I have 20, 20, 20, 40. There are three repeated value, so go to condition (1). The result is 20. Second example, I have 40, 40, 50, 100. There are less than three repeated value, so go to condition (2). The result is 100.

Here is the scrip I wrote for (2) but I don’t know how to add another condition and what would be a script for (1). Any suggestion please? Try to do GHpython script but my script is not work.
Picture1

Using all native components:
Grouping Data.gh (19.9 KB)


the combo of Create Set and Member Index gets you the frequency of the value in the set. If you wanted that to be for only consecutive values, then something else would be in order. Certainly possible in python, but no need i think. Might want to test it some more if you plan on running trees through, rather than flat lists.

Thank you so much Jo!! I have been trying to find a way to get this for a while. Really appreciate.

1 Like