I have a list of words:
words = [\'all\', \'awesome\', \'all\', \'yeah\', \'bye\', \'all\', \'yeah\']
And I want to get a list of tuples:
You can use the counter for this.
import collections
words = ['all', 'awesome', 'all', 'yeah', 'bye', 'all', 'yeah']
counter = collections.Counter(words)
print(counter.most_common())
>>> [('all', 3), ('yeah', 2), ('bye', 1), ('awesome', 1)]
It gives the tuple with reversed columns.
From the comments: collections.counter is >=2.7,3.1. You can use the counter recipe for lower versions.