Can anybody help me understand the error...section:lists and for loops

CODE:

opened_file = open(‘AppleStore.csv’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
rating_sum = 0
for row in apps_data[1:]:
rating = float(row[7])
rating_sum += rating

avg_rating = rating_sum / len(apps_data[1:])

ERROR:

TypeErrorTraceback (most recent call last)
in ()
2 from csv import reader
3 read_file = reader(opened_file)
----> 4 apps_data = list(read_file)
5 rating_sum = 0
6 for row in apps_data[1:]:

TypeError: ‘list’ object is not callable

Also showing(dataquest console):

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

Your code is correct and should work. It sounds like you might have used the keyword list as a variable name somewhere else in a previous screen in the same mission. You can read this post by @joshdq for more details.

i think you missed indentation in the body of for loop

That would not explain why he got a TypeError.

1 Like

yeah…you’re right…I was using list as an iterable in a previous screen…thanks…

1 Like

@Mary Maybe the Variables And Data Types Mission in the Python Fundamentals course could be updated to include the info that Python keywords should not be used as variable names? Several users seem to have found this out the hard way. :stuck_out_tongue:

1 Like

I’ll pass this along to our content team, @Slavina!

cc: @rose

2 Likes