-1

I would like to generate a list of numbers such as this:

['1','2','3','4','5','6']

but all I can seem to get is:

[1, 2, 3, 4, 5, 6]

using this code:

values = list(range(1,7))

Is there some easy way to generate a list of consecutive numbers, that are within apostrophes, since I want the code to treat them like a string.

I have tried:

values = str(list(range(1,7)))

but that just gave me the same result as above.

0

3 Answers 3

3
>>> [str(i) for i in range(1,7)]
['1', '2', '3', '4', '5', '6']
Sign up to request clarification or add additional context in comments.

Comments

1

The comprehension proposed by @CoryKramer has you covered, but given your attempts, you might be looking for:

>>> list(map(str, range(1, 7)))
['1', '2', '3', '4', '5', '6']

Comments

1

Try the following:

list(map(str, range(1,7)))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.