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.Thu, 31 Dec 2020 10:35:57 +0100generate a list of variables with two indiceshttps://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/Hi
I would like to make a list of variables with two consecutive indices, example rr_10, rr_21 .. etc
I tried :
n=3
rrL=list(var('rr_%d%d' %i %(i-1)) for i in [1..n])
without success:**not enough arguments for format string**
what is the missing arguments here ? Tue, 16 Apr 2019 09:25:03 +0200https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/Comment by ortollj for <p>Hi</p>
<p>I would like to make a list of variables with two consecutive indices, example rr_10, rr_21 .. etc
I tried :</p>
<pre><code>n=3
rrL=list(var('rr_%d%d' %i %(i-1)) for i in [1..n])
</code></pre>
<p>without success:<strong>not enough arguments for format string</strong>
what is the missing arguments here ? </p>
https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/?comment=46215#post-id-46215Oops ok , I find a way Sorry, Im gonna close the subject !
n=3
rrL=list(var('rr_%d' %i +'%d' %(i-1)) for i in [1..n])Tue, 16 Apr 2019 09:29:29 +0200https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/?comment=46215#post-id-46215Comment by ortollj for <p>Hi</p>
<p>I would like to make a list of variables with two consecutive indices, example rr_10, rr_21 .. etc
I tried :</p>
<pre><code>n=3
rrL=list(var('rr_%d%d' %i %(i-1)) for i in [1..n])
</code></pre>
<p>without success:<strong>not enough arguments for format string</strong>
what is the missing arguments here ? </p>
https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/?comment=46254#post-id-46254thank you nbruin, finally it was a true question !, i'm gonna reopen it and mark your comment as answer.Thu, 18 Apr 2019 08:44:08 +0200https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/?comment=46254#post-id-46254Comment by ortollj for <p>Hi</p>
<p>I would like to make a list of variables with two consecutive indices, example rr_10, rr_21 .. etc
I tried :</p>
<pre><code>n=3
rrL=list(var('rr_%d%d' %i %(i-1)) for i in [1..n])
</code></pre>
<p>without success:<strong>not enough arguments for format string</strong>
what is the missing arguments here ? </p>
https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/?comment=46255#post-id-46255but it is not possible for me to transform your comment in good answer !Thu, 18 Apr 2019 08:52:39 +0200https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/?comment=46255#post-id-46255Comment by slelievre for <p>Hi</p>
<p>I would like to make a list of variables with two consecutive indices, example rr_10, rr_21 .. etc
I tried :</p>
<pre><code>n=3
rrL=list(var('rr_%d%d' %i %(i-1)) for i in [1..n])
</code></pre>
<p>without success:<strong>not enough arguments for format string</strong>
what is the missing arguments here ? </p>
https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/?comment=55022#post-id-55022I turned @nbruin's comment into an answer so you can accept it and mark the question as solved.Thu, 31 Dec 2020 10:34:23 +0100https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/?comment=55022#post-id-55022Answer by nbruin for <p>Hi</p>
<p>I would like to make a list of variables with two consecutive indices, example rr_10, rr_21 .. etc
I tried :</p>
<pre><code>n=3
rrL=list(var('rr_%d%d' %i %(i-1)) for i in [1..n])
</code></pre>
<p>without success:<strong>not enough arguments for format string</strong>
what is the missing arguments here ? </p>
https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/?answer=46236#post-id-46236this:
["rr_%d%d"%(i,i-1) for i in [1..n]]
is the right solutionWed, 17 Apr 2019 04:24:14 +0200https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/?answer=46236#post-id-46236Comment by slelievre for <p>this:</p>
<pre><code>["rr_%d%d"%(i,i-1) for i in [1..n]]
</code></pre>
<p>is the right solution</p>
https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/?comment=55023#post-id-55023I would add an extra underscore to better separate the two indices in case they have several digits.Thu, 31 Dec 2020 10:35:57 +0100https://ask.sagemath.org/question/46214/generate-a-list-of-variables-with-two-indices/?comment=55023#post-id-55023