Just do:
Counter(example).items()
Which is not a list, but if want a list:
list(Counter(example).items())
Because Counter
is basically a dict, has equivalent functions to a dict, so Counter has items
,
Only thing is that Counter
has a elements
and most_common
(most_common
actually can solve this), elements
converts Counter
to itertools.chain
object then make to list will be the original list but ordered by occurrence.
most_common
example:
Counter(example).most_common()
No need converting for list, it's already a list, but it orders by number of occurrence (meaning maximum --- to --- minimum).
Both Output:
[('apple', 2), ('pear', 1)]