I'm currently using SciPy's mode function to find the most occurring item in different iterable objects. I like the mode function because it works on every object type I've thrown at it (strings, float
s, int
s).
While this function seems reliable, it is very slow on bigger lists:
from scipy.stats import mode
li = range(50000)
li[1] = 0
%timeit mode(li)
1 loops, best of 3: 7.55 s per loop
Is there a better way to get the mode for a list? If so, would the implementation be different depending on the item type?