Create a list with string + range


I need your help:

I want to create a list looking like this ['Unnamed: 16', 'Unnamed: 17', 'Unnamed:18'] for a range (16,60). How can I proceed?

I don’t know if my question is clear but it’s like doing list(range(16, 60) but with a string before each numbers.

Thank you very much for your help!!


You can use f-strings to do so :

my_list = [f"Unnamed: {i}" for i in range(16, 60)]

# Output
['Unnamed: 16', 'Unnamed: 17', 'Unnamed: 18', 'Unnamed: 19', ...]

Answered By – Titouan L

Answer Checked By – Willingham (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.