Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import groupby
- num_list = [1, 5, 4, 3, 45, 45, 47, 1, 2, 2]
- counts = [(v, len(list(c))) for v,c in groupby(sorted(num_list))] # Create value-count pairs as list of tuples
- for pair in counts:
- print('number',str(pair[0]),'appeared', str(pair[1]), 'time(s)')
Advertisement
Add Comment
Please, Sign In to add comment