Assigning a range to an array in Python
arrays, python, range
Solution
In Python 2.x:
arrayX = range(20080711, 20080714+1)
in Python 3.x:
arrayX = list(range(20080711, 20080714+1))
However, if your ints represent something like a date (YYYYMMDD), it will be trickier:
from datetime import datetime, timedelta
arrayX = []
dt = datetime(2008, 7, 11)
while dt <= datetime(2008, 7, 14):
arrayX.append(int(dt.strftime('%Y%m%d')))
dt += timedelta(days=1)
which works over months and years.
Problem
I know that assigning some values to an array would be as below: ``` arrayX = [20080711, 20080712, 20080713, 20080714] ``` But I couldn't find out how to quickly assign these values as a range to the array.