315-7 Anyone having issues with Functions: Fundamentals 7 of 14? I'm getting a strange error

I am on Functions: Fundamentals - 7 of 14 and just can’t figure out how my code is different than the See Answer code. Do you see something I don’t??? The only difference I can find is my variable and dictionary names…

I am getting a KeyError: 'Social Networking' which is the first row/item in the list genres.

MY CODE:

# CODE FROM THE PREVIOUS SCREEN
opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

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

genres = extract(11)
# SOLUTION CODE
def freq_table(list_name):
    the_frequency_table = {}
    
    for num in list_name:
        
        if num in list_name:
            the_frequency_table[num] += 1
        else:
            the_frequency_table[num] = 1
    
    return the_frequency_table

genres_ft = freq_table(genres)

print(genres_ft) 

DATAQUEST ANSWER:

# CODE FROM THE PREVIOUS SCREEN
opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

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

genres = extract(11)
# SOLUTION CODE
def freq_table(column):
    frequency_table = {}    
    for value in column:
        if value in frequency_table:
            frequency_table[value] += 1
        else:
            frequency_table[value] = 1            
    return frequency_table

genres_ft = freq_table(genres)

You don’t want to check list_name. I’ll let you figure out how to fix this.

Thank you so much Bruno!!! Not sure how I missed that. Probably staring at code for too long. :slight_smile:

1 Like