"Ric Deez" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I have a list: > L1 = [1,1,1,2,2,3] > How can I easily turn this into a list of tuples where the first element > is the list element and the second is the number of times it occurs in > the list (I think that this is referred to as a histogram):
For ease of reading (but not efficiency) I like: hist = [(x,L1.count(x)) for x in set(L1)] See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277600 Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list