Hello everyone, I have encountered error in my function get_count(word_l).
It works fine but gives a different answer compared to expected output. When testing the function, it results in error.
What the get_count function does is create a dictionary with the keys as the words in the input list and the value for each word being the count of the number of occurrences of that word in the input list.
The only tricky part of the code is handling the case that you’re seeing a given word for the first time and the dictionary entry doesn’t exist yet.
But there must be something incorrect about your implementation if the tests fail.
Please show us the complete output that you get, not just the failure message. What is the evidence you have that your code “works fine”? Can you show us a case that you claim is correct?
Your logic looks correct to me. I think what that means is that the input word_l is wrong. That was produced by your previous function process_data. Are you sure that passed the tests and produced 6116 unique words?
The way it is wrong must be interesting: you show more unique words, but fewer occurrences of “thee”. Hmmmm. Maybe you forgot to convert everything to lower case?
Notice that you have words that still have trailing commas on them in your output. That requires more logic to strip those. “fire,” is not the same as “fire”.
But you have also turned up some bugs in the test cases. The first one threw an assertion while trying to decode your error.