Last active
August 29, 2015 14:00
-
-
Save mamachanko/11244412 to your computer and use it in GitHub Desktop.
dates and τ
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
from datetime import datetime, timedelta | |
get_random_datetime = lambda: datetime.now() - timedelta(days=random.randrange(1, 365*2), seconds=random.randrange(0, timedelta.max.seconds)) | |
dates = [get_random_datetime() for d in range(10)] | |
half_year_ago = datetime.now() - timedelta(days=365/2) | |
dates_within_last_six_months = filter(lambda date: date >= half_year_ago, dates) | |
deltas = [] | |
for index, date in enumerate(sorted(dates_within_last_six_months)): | |
if index < len(dates_within_last_six_months) - 1: | |
deltas.append(dates_within_last_six_months[index + 1] - dates_within_last_six_months[index]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment