aa=(1,2,3,42,4,5,4,3,2,56,33,56,56,34,33,43) bb={} for x in aa: try: bb[x] except: bb[x]=0 finally: bb[x]=bb[x] + 1 print bb for key in bb: print key,bb[key]