finish 01-homework

This commit is contained in:
SJ2050
2021-10-16 23:35:28 +08:00
parent 1a2d27dc09
commit 001839394c
12 changed files with 369 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
One is always on a strange road, watching strange scenery and listening to strange music. Then one day, you will find that the things you try hard to forget are already gone.
+22
View File
@@ -0,0 +1,22 @@
'''
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}')