312-11 TypeError: 'list' object is not callable

Hello. I am working through the free introductory course of Python for Data Analyst Track.
On Assignment 11 “Alternative Ways to Compute an Average”, I ran into an error that is above the competence of someone taking this course. Is seems that it is a syntax error from the developer side.

Please advise how to fix it.

Thank you,

Hey, Valentina.

Nice job understanding that you didn’t do anything wrong. In fact you did, but it’s perfectly natural that you can’t figure it out, partly because of the way the experience at Dataquest is set up (e.g.: code from previous screens isn’t available on this screen for you to see).

By clicking on the magnifying class on top I was able to query questions containing the sequence of words Object not callable. Here are the results. I suggest you look through the first few.

Let us know if this doesn’t solve your problem.

1 Like

This topic is very useful here :slight_smile:

Hi Bruno,
Thanks for indicating that the problem might be in my previous erroneous code.

I was able to fix the code and move on with the assignment using another solution instead of the one you mentioned( or perhaps is the same). For example, in my previous assignment, 10, instead of using len() function to calculate the average, I used the actual number of lines given in the assignment, 7 197.
By converting the actual number to len () function, I was able to pass assignment 11th.

Did the let() function on assignment 10 changed the variable “apps_data” on assignment 11?

I just can’t see the connection between TypeError : ‘list’ object is not callable with the correction I did on the previous page.
Could you please elaborate on that?

Hi, Valentina. I’m glad that you were able to move on.

I’m having a little trouble understanding what you did.

This shouldn’t make any difference.

I don’t understand what this means. Can you explain in a different way? Or perhaps just share your code for both screens (10 and 11).

As I mentioned above, I’m not sure what you did on the previous screens, but you must have assigned something (for example a number) to list, which made it so that list stopped being a function that converts “things” to lists and started being a number.

This makes it so that when you want to use list as a function, like in your code above, it will fail because it’s now a number. Here’s a simplified reproduction of this problem:

>>> val = "Valentina"
>>> list(val)
['V', 'a', 'l', 'e', 'n', 't', 'i', 'n', 'a']
>>> list = 1337
>>> list(val)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable

Does this help?

Hi Bruno,
Yes, it makes sense. You are right, the change I did should’ve not made any difference, but it did all me to successfully submit the assignment.
Here are the screenshots.


    opened_file = open('AppleStore.csv')
    from csv import reader
    read_file = reader(opened_file)
    apps_data = list(read_file)

    rating_sum = 0
    for each_row in apps_data[1:]:
        rating = float(each_row[7])
        rating_sum  = rating +rating_sum
    avg_rating = rating_sum / 7197

The only explanation I have is that by going back to the previous page (10), I refreshed the page and it just fixed itself.
This came to me as I navigated through the next assignments and have faced the exact same errors. But I was able to fix them by refreshing the previous pages, without doing any other changes to the code.

So I think this might be a future solution to this problem.

Since I am a new user, I can only post one picture at the time.
So here is the correction that I made, which was not necessary to successfully run the code.

    opened_file = open('AppleStore.csv')
    from csv import reader
    read_file = reader(opened_file)
    apps_data = list(read_file)
    all_ratings = []
    for row in apps_data[1:]:
        rating = float(row[7])
    avg_rating = sum(all_ratings) / len(all_ratings)

Hey @valentina.suveico! While Bruno is helping you, it might be helpful to actually just copy/paste the code you’ve taken a screenshot of here so it’s easier for Bruno to copy/paste into his own machine instead of having to type it in!

Here’s a quick gif on how to format your code as well:

1 Like

Hey, Valentina.

Is this your only try at solving this screen? Because if it isn’t, it is likely that the following explains what happened.

I suspect you ran code that overwrote the list function and when you got back to it at a later time, having already fixed the code, it reset the code runner and it ran the now correct code.

If it was your only try, then something really weird happened that I can’t explain.

Hi Bruno,
I ran into the same problem as Valentina.
I used list as a loop variable in one of the assignments and hence the list() was overwritten.
Can you please let me know how to reset the env so that list() works as normal?

Hey, Vvijayalakshmi.

See this post for the details.


Actually this doesn’t teach how to reset the environment, but it does provide a solution to the problem.

I had the same thing happen to me when I named a list list below line #4. That messed up the function list being used to make a list from (read file). Refreshing wouldn’t clear the issue.

You can reset list mishaps by opening the console at the bottom of the screen, typing ‘del list’ and pressing the Enter key.

I had the same issue. It might be beneficial to note to the users not use loops with the word “list” as the iteration variable.

i.e. for list in apps_data[1:]:

Also, for those wondering how to fix this issue, you open the console type in the following

del list
and press enter

Now try running your code.

1 Like

I can see I’m running into the issue that a lot of other people seem to have come up against. I’m new to Python and the community, so not exactly sure what I may be missing. I tried opening the console and using del element (as my subsitute for del list) but I get this error in my code:

TypeError Traceback (most recent call last)
11 rating_sum = rating + rating_sum
—> 13 avg_rating = rating_sum / len(rating_sum)

TypeError: object of type ‘float’ has no len()

I think I see what’s going on, but if anyone has any tips on ways I should handle this differently, I’m all ears.


Hi. This is a separate issue than the one in this post.

Please create a separate, new post for your question and someone can provide a response accordingly.