ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 25 Nov 2014 14:52:49 -0600What it means "TypeError: 'list' object is not callable"?https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/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?
ThanksSat, 22 Nov 2014 12:22:21 -0600https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/Comment by vdelecroix for <p>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</p>
<p>2) More generally, how can I do sum(d(i) with condition d(i)<10) ?</p>
<p>3) Where can I find a reference document for SAGE and an elementary tutorial?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/?comment=25005#post-id-25005Then, it would be helpful for other people looking for help if you change the title.Tue, 25 Nov 2014 14:52:49 -0600https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/?comment=25005#post-id-25005Comment by logomath for <p>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</p>
<p>2) More generally, how can I do sum(d(i) with condition d(i)<10) ?</p>
<p>3) Where can I find a reference document for SAGE and an elementary tutorial?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/?comment=24971#post-id-24971You 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. SorryMon, 24 Nov 2014 08:39:40 -0600https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/?comment=24971#post-id-24971Comment by vdelecroix for <p>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</p>
<p>2) More generally, how can I do sum(d(i) with condition d(i)<10) ?</p>
<p>3) Where can I find a reference document for SAGE and an elementary tutorial?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/?comment=24953#post-id-24953I do not see the link between the title of the post and the three questions above...Sat, 22 Nov 2014 23:37:57 -0600https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/?comment=24953#post-id-24953Answer by slelievre for <p>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</p>
<p>2) More generally, how can I do sum(d(i) with condition d(i)<10) ?</p>
<p>3) Where can I find a reference document for SAGE and an elementary tutorial?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/?answer=24947#post-id-24947To 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](http://www.sagemath.org/doc/thematic_tutorials/tutorial-comprehensions.html).
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])
Sat, 22 Nov 2014 14:03:10 -0600https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/?answer=24947#post-id-24947Comment by kcrisman for <p>To extract the divisors less than 10, you can do this:</p>
<pre><code>sage: k = 720
sage: sum(d for d in k.divisors() if d < 10)
</code></pre>
<p>See <a href="http://www.sagemath.org/doc/thematic_tutorials/tutorial-comprehensions.html">this tutorial</a>.</p>
<p>The error you got is probably because of the following:</p>
<p>If you defined <code>d</code> as</p>
<pre><code>sage: d = divisors(k)
</code></pre>
<p>Then <code>d</code> is a list. You can extract element number <code>i</code> of <code>d</code> as <code>d[i]</code>, but you cannot do <code>d(i)</code> which would be "calling the function <code>d</code> with argument <code>i</code>". Sage tells you <code>d</code> is not "callable".</p>
<p>If you want to sum the first 10 divisors, do:</p>
<pre><code>sage: sum(d[i] for i in range(10))
</code></pre>
<p>or</p>
<pre><code>sage: sum(d[:10])
</code></pre>
https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/?comment=24950#post-id-24950If 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!Sat, 22 Nov 2014 20:34:22 -0600https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/?comment=24950#post-id-24950Comment by logomath for <p>To extract the divisors less than 10, you can do this:</p>
<pre><code>sage: k = 720
sage: sum(d for d in k.divisors() if d < 10)
</code></pre>
<p>See <a href="http://www.sagemath.org/doc/thematic_tutorials/tutorial-comprehensions.html">this tutorial</a>.</p>
<p>The error you got is probably because of the following:</p>
<p>If you defined <code>d</code> as</p>
<pre><code>sage: d = divisors(k)
</code></pre>
<p>Then <code>d</code> is a list. You can extract element number <code>i</code> of <code>d</code> as <code>d[i]</code>, but you cannot do <code>d(i)</code> which would be "calling the function <code>d</code> with argument <code>i</code>". Sage tells you <code>d</code> is not "callable".</p>
<p>If you want to sum the first 10 divisors, do:</p>
<pre><code>sage: sum(d[i] for i in range(10))
</code></pre>
<p>or</p>
<pre><code>sage: sum(d[:10])
</code></pre>
https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/?comment=24948#post-id-24948Thank you so much!Sat, 22 Nov 2014 15:32:57 -0600https://ask.sagemath.org/question/24945/what-it-means-typeerror-list-object-is-not-callable/?comment=24948#post-id-24948