TypeError: 'list' object is not callable

*I am in the following section: *
Lists and For Loops
4. Retrieving Multiple List Elements

This is my code.

row_1 = ['Facebook', 0.0, 'USD', 2974676, 3.5]
row_2 = ['Instagram', 0.0, 'USD', 2161558, 4.5]
row_3 = ['Clash of Clans', 0.0, 'USD', 2130805, 4.5]
row_4 = ['Temple Run', 0.0, 'USD', 1724546, 4.5]
row_5 = ['Pandora - Music & Radio', 0.0, 'USD', 1126879, 4.0]

fb_rating_data = [row_1[0], row_1[3], row_1[4]]
insta_rating_data = [row_2(0), row_2(3), row_2(4)]
pandora_rating_data = [row_5(0), row_5(3), row_5(4)]
total = [fb_rating_data(2) + insta_rating_data(2) + pandora_rating_data(2)]
avg_rating = total/3

After running this code i get the following error.

TypeErrorTraceback (most recent call last)
<ipython-input-1-dc48ef9bea5f> in <module>()
      6 
      7 fb_rating_data = [row_1[0], row_1[3], row_1[4]]
----> 8 insta_rating_data = [row_2(0), row_2(3), row_2(4)]
      9 pandora_rating_data = [row_5(0), row_5(3), row_5(4)]
     10 total = [fb_rating_data(2) + insta_rating_data(2) + pandora_rating_data(2)]

TypeError: 'list' object is not callable

Could you please explain this error

Hi @sfsabiha, welcome to the community.

It appears you’re trying to use curved brackets, (), as opposed to square brackets, [ ], for indexing.

1 Like

Hi @sfsabiha

Welcome to our Dataquest Community.

TypeError: ‘list’ object is not callable

It means you are trying to call any list object, calling means executing something. list objects are not a function (if you don’t know then you will learn later).

So, square brackets are used for indexing and small brackets are used for calling any function or for using any method (you will learn later).

In your code, row_1 up to row_5 are all list object. You can index it not call it.

insta_rating_data = [row_2(0), row_2(3), row_2(4)]
pandora_rating_data = [row_5(0), row_5(3), row_5(4)]
total = [fb_rating_data(2) + insta_rating_data(2) + pandora_rating_data(2)]

Also, you are using your list objects to make other list object i.e. fb_rating_data, insta_rating_data and pandora_rating_data.

I think you will understand, what changes you have to do in your code.

Correct code:

row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5]
row_2 = [‘Instagram’, 0.0, ‘USD’, 2161558, 4.5]
row_3 = [‘Clash of Clans’, 0.0, ‘USD’, 2130805, 4.5]
row_4 = [‘Temple Run’, 0.0, ‘USD’, 1724546, 4.5]
row_5 = [‘Pandora - Music & Radio’, 0.0, ‘USD’, 1126879, 4.0]

fb_rating_data = [row_1[0], row_1[3], row_1[4]]
insta_rating_data = [row_2[0], row_2[3], row_2[4]]
pandora_rating_data = [row_5[0], row_5[3], row_5[4]]
total = (fb_rating_data[2] + insta_rating_data[2] + pandora_rating_data[2])
avg_rating = total/3
1 Like

Hi @Prem
I like your answer, but I think you have to replace

total = [fb_rating_data[2] + insta_rating_data[2] + pandora_rating_data[2]]
by
total = (fb_rating_data[2] + insta_rating_data[2] + pandora_rating_data[2])

you can not devide list by int
than to correct code will be:

row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5]
row_2 = [‘Instagram’, 0.0, ‘USD’, 2161558, 4.5]
row_3 = [‘Clash of Clans’, 0.0, ‘USD’, 2130805, 4.5]
row_4 = [‘Temple Run’, 0.0, ‘USD’, 1724546, 4.5]
row_5 = [‘Pandora - Music & Radio’, 0.0, ‘USD’, 1126879, 4.0]

fb_rating_data = [row_1[0], row_1[3], row_1[4]]
insta_rating_data = [row_2[0], row_2[3], row_2[4]]
pandora_rating_data = [row_5[0], row_5[3], row_5[4]]
total = (fb_rating_data[2] + insta_rating_data[2] + pandora_rating_data[2])
avg_rating = total/3
1 Like

Yes @bahmed21, you are right. I didn’t see that bracket :slightly_smiling_face: . After editing it will be correct.

Thanks @blueberrypudding85 !!! I did the same mistake :rofl: