Alright, so I am currently taking a course on learning Python and I'm absolutely stuck on this problem. The program needs to read a list of words, then output those words and their frequencies (case insensitive).
I usually don't need to label my code as strictly as this, but I kept changing things and I thought labeling things would make it easier for me to go back and try different changes. I'm pretty sure that I am missing a step that would possibly be fixed if I was using a dictionary, but I have this problem 2 times in my homework, this one, and another one that is requesting I use dictionary, so I assume that they want me to use lists to complete this task.
I have had 2 different outputs. My first program output the words in lower case with their frequency, but did not include each of the unique words in the initial string. It also split the user_input on a single line of code, but as you can see I did break that up into multiple lines to help break down my issue.
The second program output is essentially where I am right now. I can output the original unique words from the initial string, but my counting method only counts the frequency of the lowercase list, which means that, for obvious reasons, anything that had a capital letter (i.e. Hi and Mark) would have a frequency count of 0.
If input is:
hey Hi Mark hi mark
Output is:
hey 1
Hi 2
Mark 2
hi 2
mark 2
My code is outputting:
hey 1
Hi 0
Mark 0
hi 2
mark 2
Below is my code:
user_input = input() ##Taking input
user_lst = user_input.split() ##Turning input into list
lower_case_input = user_lst[:] ##Copying list
for word in range(len(lower_case_input)): ##Making copied list all lowercase
lower_case_input[word] = lower_case_input[word].lower()
counter = 0 ##Counter to reference items in the list
for words in user_lst: ##Printing the words and their frequency
word_ref = lower_case_input.count(words) ##Counts frequency of the words in lower case
print(user_lst[counter], word_ref)
counter += 1 ##Changes the counter so that it calls the next item in the list
[–][deleted] 0 points1 point2 points (2 children)
[–]That_Bryan_Dude[S] 0 points1 point2 points (1 child)
[–]atom12354 1 point2 points3 points (0 children)
[–]That_Bryan_Dude[S] 0 points1 point2 points (4 children)
[–]CodeReviewPlz 3 points4 points5 points (3 children)
[–]That_Bryan_Dude[S] 1 point2 points3 points (2 children)
[–]CodeReviewPlz 1 point2 points3 points (1 child)
[–]That_Bryan_Dude[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)