TypeError: 'list' object is not callable while trying to access a list

此生再无相见时 提交于 2019-11-26 16:14:48
orlp

For accessing the elements of a list you need to use the square brackets ([]) and not the parenthesis (()).

Instead of:

print  wordlists(len(words))

you need to use:

print worldlists[len(words)]

And instead of:

(wordlists(len(words))).append(words)

you need to use:

worldlists[len(words)].append(words)

wordlists is not a function, it is a list. You need the bracket subscript

print  wordlists[len(words)]
Ikke

To get elements of a list you have to use list[i] instead of list(i).

I also got the error when I called a function that had the same name as another variable that was classified as a list.

Once I sorted out the naming the error was resolved.

You are attempting to call wordlists here:

print  wordlists(len(words)) <--- Error here.

Try:

print wordlists[len(words)]

Try wordlists[len(words)]. () is a function call. When you do wordlists(..), python thinks that you are calling a function called wordlists which turns out to be a list. Hence the error.

Check your file name in which you have saved your program. If the file name is wordlists then you will get an error. Your filename should not be same as any of methods{functions} that you use in your program.

Even I got the same error, but I solved it, I had used many list in my work so I just restarted my kernel (meaning if you are using a notebook such as Jupyter or Google Colab you can just restart and again run all the cells, by doing this your problem will be solved and the error vanishes.

Thank you.

Raveena
del list

above command worked for me

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!