ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 16 Nov 2012 21:57:03 +0100Question about ordered pairs and dictionaries.https://ask.sagemath.org/question/9538/question-about-ordered-pairs-and-dictionaries/Hello, what I am trying to do is use (math) functions within functions that are defined by ordered pairs. The code I have looks like this:
<code>
f = {-3:4, -2:2, -1:0, 0:1, 1:3, 2:4, 3:-1}
g = {-3:-2, -2:0, -1:-4, 0:0, 1:-3, 2:1, 3:2}
show(g[f[g[0]]])
</code>
So, the way I intend for this to work is g[0] should return 0, which will become f[0] which returns 1, which becomes g[1] which should return -3. When I try to run this in sage 5.4, nothing appears to happen. Any help would be really great, thanks!Fri, 16 Nov 2012 15:25:48 +0100https://ask.sagemath.org/question/9538/question-about-ordered-pairs-and-dictionaries/Answer by fidbc for <p>Hello, what I am trying to do is use (math) functions within functions that are defined by ordered pairs. The code I have looks like this:</p>
<p><code></code></p><code>
<p>f = {-3:4, -2:2, -1:0, 0:1, 1:3, 2:4, 3:-1}
g = {-3:-2, -2:0, -1:-4, 0:0, 1:-3, 2:1, 3:2}</p>
<p>show(g[f[g[0]]])</p>
</code><p><code></code></p>
<p>So, the way I intend for this to work is g[0] should return 0, which will become f[0] which returns 1, which becomes g[1] which should return -3. When I try to run this in sage 5.4, nothing appears to happen. Any help would be really great, thanks!</p>
https://ask.sagemath.org/question/9538/question-about-ordered-pairs-and-dictionaries/?answer=14274#post-id-14274Hi, the code above seems fine, the output of the `show` function was a pdf file containing -3. Maybe just
f = {-3:4, -2:2, -1:0, 0:1, 1:3, 2:4, 3:-1}
g = {-3:-2, -2:0, -1:-4, 0:0, 1:-3, 2:1, 3:2}
g[f[g[0]]]
If you want the result printed then
f = {-3:4, -2:2, -1:0, 0:1, 1:3, 2:4, 3:-1}
g = {-3:-2, -2:0, -1:-4, 0:0, 1:-3, 2:1, 3:2}
print g[f[g[0]]]Fri, 16 Nov 2012 21:15:47 +0100https://ask.sagemath.org/question/9538/question-about-ordered-pairs-and-dictionaries/?answer=14274#post-id-14274Comment by fidbc for <p>Hi, the code above seems fine, the output of the <code>show</code> function was a pdf file containing -3. Maybe just</p>
<pre><code>f = {-3:4, -2:2, -1:0, 0:1, 1:3, 2:4, 3:-1}
g = {-3:-2, -2:0, -1:-4, 0:0, 1:-3, 2:1, 3:2}
g[f[g[0]]]
</code></pre>
<p>If you want the result printed then</p>
<pre><code>f = {-3:4, -2:2, -1:0, 0:1, 1:3, 2:4, 3:-1}
g = {-3:-2, -2:0, -1:-4, 0:0, 1:-3, 2:1, 3:2}
print g[f[g[0]]]
</code></pre>
https://ask.sagemath.org/question/9538/question-about-ordered-pairs-and-dictionaries/?comment=18697#post-id-18697The code in your question contains a syntax error and I can't edit it. I'll update the answer above to include it.Fri, 16 Nov 2012 21:57:03 +0100https://ask.sagemath.org/question/9538/question-about-ordered-pairs-and-dictionaries/?comment=18697#post-id-18697Comment by Siramok for <p>Hi, the code above seems fine, the output of the <code>show</code> function was a pdf file containing -3. Maybe just</p>
<pre><code>f = {-3:4, -2:2, -1:0, 0:1, 1:3, 2:4, 3:-1}
g = {-3:-2, -2:0, -1:-4, 0:0, 1:-3, 2:1, 3:2}
g[f[g[0]]]
</code></pre>
<p>If you want the result printed then</p>
<pre><code>f = {-3:4, -2:2, -1:0, 0:1, 1:3, 2:4, 3:-1}
g = {-3:-2, -2:0, -1:-4, 0:0, 1:-3, 2:1, 3:2}
print g[f[g[0]]]
</code></pre>
https://ask.sagemath.org/question/9538/question-about-ordered-pairs-and-dictionaries/?comment=18698#post-id-18698I really appreciate you checking it, but strangely enough, now when I try evaluating the above code I get an error: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_3.py", line 8, in <module>
_interact_.SAGE_CELL_ID=1
NameError: name '_interact_' is not defined Fri, 16 Nov 2012 21:42:14 +0100https://ask.sagemath.org/question/9538/question-about-ordered-pairs-and-dictionaries/?comment=18698#post-id-18698