Transfer unique words to columns

Hi, I have difficulty in understanding the below code, they are from the solution. i understand the purpose, but don’t really understand the details in list comprehension and for loop.

Screen Link:Learn data science with Python and R projects

My Code:

word_counts_per_sms = {unique_word: [0] * len(training_set['SMS']) for unique_word in vocabulary}

for index, sms in enumerate(training_set['SMS']):
    for word in sms:
        word_counts_per_sms[word][index] += 1

What I expected to happen:

What actually happened:

Replace this line with the output/error
1 Like