fork download
  1. from collections import defaultdict
  2.  
  3. data = [2,1,2,4,5,5,6,4]
  4. map = defaultdict(list)
  5. for index, number in enumerate(data):
  6. map[number].append(index)
  7.  
  8. for number, positions in map.items():
  9. print(number, positions)
Success #stdin #stdout 0.03s 10192KB
stdin
Standard input is empty
stdout
1 [1]
2 [0, 2]
4 [3, 7]
5 [4, 5]
6 [6]