IT45200

Untitled

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