TypeError: unhashable type: 'list', Stuck

Screen Link:

My Code:

def extract(index):
    column = []  
    for row in apps_data[1:]:
        value = row[11]
        column.append(value)    
    return column

genres = extract(11)


def freq_table(column):
    
    frequency_table = {}
    
    for value in apps_data[1:]:
        if value in frequency_table:
            frequency_table[value] += 1
        else:
            frequency_table[value] = 1
    return frequency_table

genres_ft = freq_table(genres)

What I expected to happen: the code to run properly and display the extracted genre list

What actually happened: I got a type error and I see where my code went wrong, but I cannot understand why

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-450e02172c55> in <module>
     26     return frequency_table
     27 
---> 28 genres_ft = freq_table(genres)

<ipython-input-1-450e02172c55> in freq_table(column)
     20 
     21     for value in apps_data[1:]:
---> 22         if value in frequency_table:
     23             frequency_table[value] += 1
     24         else:

TypeError: unhashable type: 'list'

If I can know why “column” is being used to loop through list instead of apps_data ?

Hi @benson.harrison7 and welcome to the community!

The reason we loop over column is because we are looking to build a frequency table for the values that are found in column. If we were to loop over apps_data[1:] then for each iteration, value would actually be a complete row from apps_data[1:] instead of just a single value from a particular column in the dataset. This is also why you’re getting an error for the line if value in frequency_table because value isn’t a single value…it’s an entire row.

Also, I noticed that in this chunk of code

we aren’t using the index parametre anywhere in the body of our function definition. I believe the instructions asked us to build a generic function that would work for any column in the dataset…not just for the column at index 11.

For future posts, please include a link to the lesson so that those who try to help you can have a bit more context for the question.

1 Like