Get list of numbers in python without using numpy

Question:

Is there a way to get list of numbers in python without using numpy.
Example,

asd = ['926', '927', '928', '929', '930', '931']

I have a list above which are typed manually.. but can not put a range like (926 to 931) and get the list?

Any help?

Asked By: mapvin vin

||

Answers:

asd = [str(i) for i in range(926, 932)]

square brackets [...] make it return a list

i for i in range(x, y) returns every value between x and y, inclusive of x and y

str(i) converts i to a string so you get the quotes around it

Thus, asd = ['926', '927' ... '931', '932']

Answered By: Talpa

You can do with range + map,

In [1]: list(map(str,range(926, 932)))
Out[1]: ['926', '927', '928', '929', '930', '931']
Answered By: Rahul K P
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.