Most common occurrence of a value from a list?

Say I have a list of numbers or strings, how can I find out the most common occurrence of any value from the list?

Couple different ways but one OOTB would be to get the unique items of the list, use an all indices of node to see how many times each unique item is in the list, a count on the all indices, and then find the max of those counts. Alternatively, you could do a group by key with the list being both inputs and counting the sublists.

What have you tried so far?

1 Like

Yes that was it, I forgot about List.AllIndicesOf node. Below is how i went about it, just wondering if I could clean it up a bit?

List.GroupByKey where the key and list inputs are both your list. Then use a List.Count node on the groups with longest lacing, and a List.SortByKey node where the list is the groups from the List.GroupByKey node and the key input is the results of the List.Count node. Lastly use a List.Reverse node on the groups output and you will have the sub lists sorted by items with the largest number or occurrences to items with the least number of occurrences.

If you just want the value not the list, use the UniqueKeys output from the List.GroupByKeys node as the list input for the List.SortByKeys.