Skip to content

Instantly share code, notes, and snippets.

@mamachanko
Last active August 29, 2015 14:00
Show Gist options
  • Save mamachanko/11244412 to your computer and use it in GitHub Desktop.
Save mamachanko/11244412 to your computer and use it in GitHub Desktop.
dates and τ
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