-2

I'm pretty new to python and I'm looking to find a relatively simple way to get the top 10 most common items in a list with their occurrences. I saw some solutions however I'm not sure which solution is the best if I'm counting occurrences.

Is there a structure that is best suited for this type of use?

1 Answers1

1

with pandas it could be:

import pandas as pd
pd.Series([1,1,1,2,2,3,3,3,3,3]).value_counts()

This will give:

3    5
1    3
2    2
dtype: int64
languitar
  • 6,554
  • 2
  • 37
  • 62