Adding to George's reply, if you want slightly more performance, you can avoid the exception with something like def hist(seq): h = {} for i in seq: h[i] = h.get(i,0)+1 return h.items() Jeethu Rao