0

Like, I have a array [2, 3, 'a', 'wow', 3], is there some function from it I can get a dict which key is the item of list and value is the nubmer of time which appear? like {2: 1, 3: 2, 'a': 1, 'wow': 1}.

speedcell4
  • 666
  • 8
  • 23

1 Answers1

2

You can use a counter:

>>> import collections
>>> print(collections.Counter([2, 3, 'a', 'wow', 3]))
Counter({3: 2, 'wow': 1, 2: 1, 'a': 1})