Advertisement
Guest User

Untitled

a guest
Sep 26th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. from collections import Counter
  2. import json
  3.  
  4.  
  5. def get_txt(fn):
  6.     try:
  7.         with open(fn, encoding="utf-8") as f:
  8.             return json.load(f)
  9.     except FileNotFoundError:
  10.         print("Файл не найден")
  11.  
  12.  
  13. def sort(fn):
  14.     txt = get_txt(fn)
  15.     word_list = []
  16.     symbols = "!@#$%^&*()\"_<>?,.[]{}`~'"
  17.  
  18.     for word in txt.split():
  19.         clear_word = ""
  20.         for letter in word:
  21.             if letter.isalpha():
  22.                 clear_word += letter.lower()
  23.         if clear_word not in symbols:
  24.             word_list.append(clear_word)
  25.  
  26.     return word_list
  27.  
  28.  
  29. filename = 'user.json'
  30. clear_list = sort(filename)
  31. print(Counter(clear_list))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement