>>> alist = [ '1', '1', '2', '1', '3', '4', '1', '3'] >>> [(a, alist.count(a)) for a in set(alist)] [('1', 4), ('3', 2), ('2', 1), ('4', 1)] >>> sorted(_, key=lambda x: -x[1]) # rank them [('1', 4), ('3', 2), ('2', 1), ('4', 1)]
You need to create an account or log in to post comments to this site.