I have a list of words:
words = [\'all\', \'awesome\', \'all\', \'yeah\', \'bye\', \'all\', \'yeah\']
And I want to get a list of tuples:
The defaultdict collection is what you are looking for:
from collections import defaultdict
D = defaultdict(int)
for word in words:
D[word] += 1
That gives you a dict where keys are words and values are frequencies. To get to your (frequency, word) tuples:
tuples = [(freq, word) for word,freq in D.iteritems()]
If using Python 2.7+/3.1+, you can do the first step with a builtin Counter class:
from collections import Counter
D = Counter(words)