def extract(index):
column =
for row in apps_data[1:]:
value = row[index]
column.append(value)
return column
genres = extract(11)
My code starts here!!!
def freq_table(x):
table = {}
for row in apps_data[1:]:
value=row
if value in table:
table[value]+=1
else:
table[value]=1
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
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.
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