from collections import Counter import re def n_common_words(text,n): words = re.findall('\w+',text) n_common_words= Counter(words).most_common(n) return list(n_common_words)