Created
December 28, 2015 08:22
-
-
Save andreisoriga/a87aed8121ef39530216 to your computer and use it in GitHub Desktop.
30 Minutes Generator
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
import datetime | |
import itertools | |
# it generates dates in 30 minutes intervals | |
date_generator = (datetime.datetime.today() - datetime.timedelta(minutes=i) for i in itertools.count(0, 30)) | |
# it gets 24h of data | |
dates = itertools.islice(date_generator, 24 * 2) | |
# convert generator data in list | |
dates_list = list(dates) | |
# converts time to 11:09 PM | |
hours = [hour.strftime('%I:%M %p') for hour in dates_list] | |
print(hours) | |
''' | |
['11:09 PM', '10:39 PM', '10:09 PM', '09:39 PM', '09:09 PM', '08:39 PM', '08:09 PM', '07:39 PM', '07:09 PM', '06:39 PM', '06:09 PM', '05:39 PM', '05:09 PM', '04:39 PM', '04:09 PM', '03:39 PM', '03:09 PM', '02:39 PM', '02:09 PM', '01:39 PM', '01:09 PM', '12:39 PM', '12:09 PM', '11:39 AM', '11:09 AM', '10:39 AM', '10:09 AM', '09:39 AM', '09:09 AM', '08:39 AM', '08:09 AM', '07:39 AM', '07:09 AM', '06:39 AM', '06:09 AM', '05:39 AM', '05:09 AM', '04:39 AM', '04:09 AM', '03:39 AM', '03:09 AM', '02:39 AM', '02:09 AM', '01:39 AM', '01:09 AM', '12:39 AM', '12:09 AM', '11:39 PM'] | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment