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?
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']
You can do with range
+ map
,
In [1]: list(map(str,range(926, 932)))
Out[1]: ['926', '927', '928', '929', '930', '931']
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?
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']
You can do with range
+ map
,
In [1]: list(map(str,range(926, 932)))
Out[1]: ['926', '927', '928', '929', '930', '931']