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!!

>Solution :

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', ...]

Leave a Reply