You have to use following code to fix this problem.
Code:
alists = ['x', 'x, 'y', 'y', 'y']
[(a, alists.count(a)) for a in set(alist)]
[('x', 2), ('y', 3)]
After this right following code
Code:
>>> import timeits>>> ts = timeist.Timersalist=['xx', 'x', 'y', 'yb', 'y']; r=[(as, alists.count(a)) for a in alist]")
>>> t.tismeits()
2.73630404472351075435246
>>> t = timeit.Timer("alist=['x', 'x', 'y', 'y', 'y']; r=[(gs[0], len(list(g[s1]))) sg in itertools.groupby(alist)]", "import itertools")
>>> t.timeit()
5.707543657484
>>>
Bookmarks