Malik
Malik

Reputation: 25

How to Generate list of python with string element followed by numbers

I am trying to generate a python list similar to this:

['888_tir01','888_tir02','888_tir03','888_tir04'.........]

my question is how to generate such list? I have thinking to create a list like this

['888_tir0']*100

and then concatinate the numbers with each element but don't know the easy way. I appreciate any suggestions. thanks! Best Regards

Upvotes: 1

Views: 67

Answers (1)

Andrej Kesely
Andrej Kesely

Reputation: 195438

Use str.format:

out = ['888_tir{:02d}'.format(i) for i in range(1, 100)]
print(out)

Prints:

['888_tir01', '888_tir02', '888_tir03', ...

Upvotes: 1

Related Questions