| from collections import Counter | |
| def word_frequency(file_path): | |
| with open(file_path, 'r') as f: | |
| words = f.read().split() | |
| return Counter(words) | |
| print(word_frequency('sample.txt')) |
| from collections import Counter | |
| def word_frequency(file_path): | |
| with open(file_path, 'r') as f: | |
| words = f.read().split() | |
| return Counter(words) | |
| print(word_frequency('sample.txt')) |