Ask Your Question
0

generate a list of variables with two indices [closed]

asked 2019-04-16 09:25:03 +0200

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 09: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 09:29:29 +0200 )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 08:44:08 +0200 )edit

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

ortollj gravatar imageortollj ( 2019-04-18 08:52:39 +0200 )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 10:34:23 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-04-17 04:24:14 +0200

nbruin gravatar image

updated 2019-04-17 04:24:32 +0200

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 10:35:57 +0200 )edit

Question Tools

1 follower

Stats

Asked: 2019-04-16 09:25:03 +0200

Seen: 110 times

Last updated: Apr 16 '19