You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
490 B
23 lines
490 B
'''
|
|
Author: SJ2050
|
|
Date: 2021-10-10 23:22:04
|
|
LastEditTime: 2021-10-10 23:34:06
|
|
Version: v0.0.1
|
|
Description: Solution for homework 1.
|
|
Copyright © 2021 SJ2050
|
|
'''
|
|
|
|
if __name__ == '__main__':
|
|
with open('essay.txt', 'r') as fp_in:
|
|
content = fp_in.read()
|
|
word_map = {}
|
|
words = content.split()
|
|
for w in words:
|
|
if w in word_map:
|
|
word_map[w] += 1
|
|
else:
|
|
word_map[w] = 1
|
|
|
|
for (k, v) in word_map.items():
|
|
print(f'{k}: {v}')
|