# What it means "TypeError: 'list' object is not callable"?

This post is a wiki. Anyone with karma >750 is welcome to improve it.

1) For example, how can I extract the divisors < 10 from the list divisors(n) ? I try to create a def with S=sum(d(i)) , d(i) verifying d(i)<10, but I get that TypeError

2) More generally, how can I do sum(d(i) with condition d(i)<10) ?

3) Where can I find a reference document for SAGE and an elementary tutorial?

Thanks

edit retag close merge delete

I do not see the link between the title of the post and the three questions above...

( 2014-11-23 06:37:57 +0200 )edit

You are right, I forgot to make clear that I had that error text because I was looking for a conditioned sum. Anyway the given answer guessed what I was meaning. Sorry

( 2014-11-24 15:39:40 +0200 )edit

Then, it would be helpful for other people looking for help if you change the title.

( 2014-11-25 21:52:49 +0200 )edit

Sort by » oldest newest most voted

To extract the divisors less than 10, you can do this:

sage: k = 720
sage: sum(d for d in k.divisors() if d < 10)


See this tutorial.

The error you got is probably because of the following:

If you defined d as

sage: d = divisors(k)


Then d is a list. You can extract element number i of d as d[i], but you cannot do d(i) which would be "calling the function d with argument i". Sage tells you d is not "callable".

If you want to sum the first 10 divisors, do:

sage: sum(d[i] for i in range(10))


or

sage: sum(d[:10])

more

Thank you so much!

( 2014-11-22 22:32:57 +0200 )edit

If this answered your question, don't forget to accept it so that someone else coming to this forum sees quickly that it has an accepted, correct answer. And have fun learning more Python and Sage - it's fun to see how elegantly many such problems can be solved!

( 2014-11-23 03:34:22 +0200 )edit