Ask Your Question
0

generate a list of variables with two indices [closed]

asked 2019-04-16 02:25:03 -0600

ortollj gravatar image

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 ?

edit retag flag offensive reopen merge delete

Closed for the following reason not a real question by ortollj
close date 2019-04-16 02:30:13.161587

Comments

Oops 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])
ortollj gravatar imageortollj ( 2019-04-16 02:29:29 -0600 )edit

thank you nbruin, finally it was a true question !, i'm gonna reopen it and mark your comment as answer.

ortollj gravatar imageortollj ( 2019-04-18 01:44:08 -0600 )edit

but it is not possible for me to transform your comment in good answer !

ortollj gravatar imageortollj ( 2019-04-18 01:52:39 -0600 )edit

I turned @nbruin's comment into an answer so you can accept it and mark the question as solved.

slelievre gravatar imageslelievre ( 2020-12-31 03:34:23 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-04-16 21:24:14 -0600

nbruin gravatar image

updated 2019-04-16 21:24:32 -0600

this:

["rr_%d%d"%(i,i-1) for i in [1..n]]

is the right solution

edit flag offensive delete link more

Comments

I would add an extra underscore to better separate the two indices in case they have several digits.

slelievre gravatar imageslelievre ( 2020-12-31 03:35:57 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-04-16 02:25:03 -0600

Seen: 90 times

Last updated: Apr 16 '19