Python fundamentals, Function - chapter 7 error

Screen Link: < Learn About Functions | Dataquest>

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)

def freq_table(genres):
    
    dictd={}
    for r in genres:
        if r in genres:
            dictd[r]+=1
        else:
            dictd[r]=1
    return dictd

genres_ft = freq_table(genres)
print(genres_ft)
        

What I expected to happen: It was supposed to print the frequency table for the genre of the appstore data.

What actually happened:

Running your code caused an error.
genres_ft isn’t defined in your code, but we expected it to be dict type

Kindly tell me, where i am wrong with the code as the similar code I ran on Visual Studio code and it worked perfectly fine.

1 Like

Hi Ankush,

Welcome to the Community!

The issue is in the definition of the freq_table function: inside the for-loop, you should check if each element is in the dictionary, not in the list (we already know that it’s present in the list since we are iterating through it). So you should make the following adjustement:

if r in dictd:
1 Like