Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- count_dict = {}
- def read_file():
- with open("./pythoWord.txt", "r", encoding="UTF-8") as fin:
- for line in fin:
- line = line.strip()
- words = line.split()
- for word in words:
- if word not in count_dict:
- count_dict[word] = 0
- count_dict[word] += 1
- st = sorted(count_dict.items(),
- key=lambda x: x[1],
- reverse=True)[:5]
- return st
- def writr_file(data):
- with open("./outPythoWord.txt", "w", encoding="UTF-8") as fout:
- for line in data:
- fout.write("".join(line[0]) + "\n")
- data = read_file()
- print(data)
- writr_file(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement