The paragraph is meant to have spaces and random punctuation, I removed them in my for loop, by doing .replace. Then I made paragraph into a list by .split() to get ['the', 'title', 'etc']. Then I made two functions count words to count each word but I didn't want it to count every word, so I made another function to create a unique list. However, I need to create a for loop to print out each word and how many times it been said with the output being something like this
The word The appears 2 times in the paragraph.
The word titled appears 1 times in the paragraph.
The word track appears 1 times in the paragraph.
I also have a hard time understanding what a for loop essentially does. I read that we should just be using for loops for counting, and while loops for any other things but a while loop can also be used for counting.
paragraph = """ The titled track “Heart Attack” does not interpret the
feelings of being in love in a serious way,
but with Chuu’s own adorable emoticon like ways. The music video has
references to historical and fictional
figures such as the artist Rene Magritte!!.... """
for r in ((",", ""), ("!", ""), (".", ""), (" ", "")):
paragraph = paragraph.replace(*r)
paragraph_list = paragraph.split()
def count_words(word, word_list):
word_count = 0
for i in range(len(word_list)):
if word_list[i] == word:
word_count += 1
return word_count
def unique(word):
result = []
for f in word:
if f not in result:
result.append(f)
return result
unique_list = unique(paragraph_list)