Created
April 14, 2017 06:56
-
-
Save JaimeEnergy/8d49cde088f6c0d0e2b7a093f33bc352 to your computer and use it in GitHub Desktop.
Generate list of months between interval in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/34898525/generate-list-of-months-between-interval-in-python | |
from datetime import datetime, timedelta | |
from collections import OrderedDict | |
dates = ["2014-10-10", "2016-01-07"] | |
start, end = [datetime.strptime(_, "%Y-%m-%d") for _ in dates] | |
OrderedDict(((start + timedelta(_)).strftime(r"%b-%y"), None) for _ in xrange((end - start).days)).keys() | |
#['Oct-14', 'Nov-14', 'Dec-14', 'Jan-15', 'Feb-15', 'Mar-15', 'Apr-15', | |
# 'May-15', 'Jun-15', 'Jul-15', 'Aug-15', 'Sep-15', 'Oct-15', 'Nov-15', | |
# 'Dec-15', 'Jan-16'] | |
# Iterates over all the days in interval but OrderedDict removes keys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment