diff --git a/Basics/Exercise/13_read_write_files/exercise_1_poem.py b/Basics/Exercise/13_read_write_files/exercise_1_poem.py index b4470301..12bf2196 100644 --- a/Basics/Exercise/13_read_write_files/exercise_1_poem.py +++ b/Basics/Exercise/13_read_write_files/exercise_1_poem.py @@ -2,8 +2,9 @@ with open("poem.txt","r") as f: for line in f: - words=line.split(' ') + words=line.lower()split(' ') #convert all words to lowercase. for word in words: + word=word.strip(',.!?;:') #remove punctuation. if word in word_stats: word_stats[word]+=1 else: @@ -18,4 +19,4 @@ print("Words with max occurances are: ") for word, count in word_stats.items(): if count==max_count: - print(word) \ No newline at end of file + print(word)