Creating frequency tables 7/14

Hello everybody! Can you please take a look at my code. It seems to be working and platform accepts my solution, but there is one issue.


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]
return column

genres = extract(11)

My code starts here!!!

def freq_table(x):
table = {}
for row in apps_data[1:]:
if value in table:
return table

genres_ft = freq_table(11)

The problem is with the last line of my code (bold). When i put index of table it accepts.
But normally in the instruction they want me to do this way:
genres_ft = freq_table(genres)

And this is not working. I opened the solution of the task. Although it looks different plus when I just copy it to console it shows mistake in code.
Can someone explain why when I do genres_ft = freq_table(genres) it rejects code and solution despite it required to be done this way

Hi @klausuts. It looks like you’re working on this mission:

The difference between whether to use freq_table(11) versus freq_table(genres) is in how we’re using the input when we write the function. I don’t see it in the code snippet you copied, but I’m guessing that you’re using the input x as the row index in your loop: value = row[x]. If this is the case, then what your code does is cycle through every row and extract the value at the index before creating the dictionary. If you try to use freq_table(genres), then your code doesn’t know what to do with the genres variable since genres is a list generated from the extract() function. Your code is expecting an integer value for the row index.

In contrast, the instructions wanted you to be able to take the information from genres and use that for the freq_table() function. This way, the extract() function does the job of getting the values from row[11] of each row, and then the freq_table() function uses those values to create the table.

I hope that helps!

1 Like

Yes, you’re right.
Thank you again. For a second time you helped me.
I just saw my mistake and now it helps me to see the process more clearly and move further even though I’m a complete fool in mathematical science

Happy to help! It’s a bit of a learning curve to learn to think in code, and making mistakes and getting guidance is all part of the process. :grin:

1 Like