Ask Your Question
1

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

asked 10 years ago

this post is marked as community wiki

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

Preview: (hide)

Comments

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

vdelecroix gravatar imagevdelecroix ( 10 years ago )

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

logomath gravatar imagelogomath ( 10 years ago )

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

vdelecroix gravatar imagevdelecroix ( 10 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 10 years ago

slelievre gravatar image

updated 10 years ago

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])
Preview: (hide)
link

Comments

Thank you so much!

logomath gravatar imagelogomath ( 10 years ago )

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!

kcrisman gravatar imagekcrisman ( 10 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 10 years ago

Seen: 6,562 times

Last updated: Nov 22 '14