diff --git "a/homework_01_python/1. \345\255\227\347\254\246\344\270\262" "b/homework_01_python/1. \345\255\227\347\254\246\344\270\262" new file mode 100644 index 0000000000000000000000000000000000000000..d3e64f43dfc1b26eaf5ae32a564a7432235d84bc --- /dev/null +++ "b/homework_01_python/1. \345\255\227\347\254\246\344\270\262" @@ -0,0 +1,10 @@ +# 1. 字符串:给定一个文章,找出每个单词的出现次数。 + +str1 = "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. " + +str1 = str1.replace(',', '').replace('.', '') +str1 = str1.split() +word = set(str1) +for i in word: + count = str1.count(i) + print(i, ':', count, '次') \ No newline at end of file