Advertisement
Guest User

Counting all words in a text and sorting(unicode)-Python 3

a guest
Jun 18th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import unidecode
  2. import string
  3. import re
  4. from collections import Counter
  5.  
  6.  
  7. def word_counter(text):
  8.     standardize = unidecode.unidecode(text.lower())
  9.     punctuations = '[{}]'.format(re.escape(string.punctuation))
  10.     removing_punctuations = re.sub(punctuations, " ", standardize).split()
  11.     counting_words = Counter(removing_punctuations).most_common()
  12.     for word, count in counting_words:
  13.         print("{} = {}".format(word, count))
  14.  
  15.  
  16. if __name__ == "__main__":
  17.     word_counter('''text here''')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement