First time here? Check out the FAQ!

Ask Your Question
0

generate a list of variables with two indices [closed]

asked 6 years ago

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 ?

Preview: (hide)

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 ( 6 years ago )

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

ortollj gravatar imageortollj ( 6 years ago )

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

ortollj gravatar imageortollj ( 6 years ago )

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

slelievre gravatar imageslelievre ( 4 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 6 years ago

nbruin gravatar image

updated 6 years ago

this:

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

is the right solution

Preview: (hide)
link

Comments

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

slelievre gravatar imageslelievre ( 4 years ago )

Question Tools

1 follower

Stats

Asked: 6 years ago

Seen: 432 times

Last updated: Apr 16 '19