I want to save str that changes only numbers in the same character in the list

Asked 2 years ago, Updated 2 years ago, 49 views

name = ['m1', 'm2', 'm3', 'm4', 'm5']

I want to put a str that is combined with letters and numbers like this

Is there a function in R that functions like paste("m", 1:5, step=""?

python list

2022-09-22 14:37

2 Answers

name = [ "m"+str(i) for i in range(1, 6) ]


2022-09-22 14:37

 [f'{a}]{b}' for a, b in list(zip('abc', [1,2,3]))]

Results: ['a1', 'b2', 'c3']

[f'{a}{b}' for a, b in list(zip('a'*3, [1,2,3]))]

Results: ['a1', 'a2', 'a3']


2022-09-22 14:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.