Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- result_counts_words = {}
- with open("input.txt", "r") as input_file:
- text = input_file.read()
- with open("words.txt", "r") as words_file:
- words = words_file.read().split()
- for word in words:
- count = len(re.findall(fr"\b{word}\b", text, re.IGNORECASE))
- result_counts_words[word] = count
- sorted_words = sorted(result_counts_words.items(), key=lambda kvp: -kvp[1])
- with open("output.txt", "a") as output_file:
- for word, count in sorted_words:
- output_file.write(f"{word} - {count}\n")
Advertisement
Add Comment
Please, Sign In to add comment