Guest User

Untitled

a guest
Jan 10th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. from datetime import datetime, timedelta
  2.  
  3. PYBITES_BORN = datetime(year=2016, month=12, day=19)
  4.  
  5.  
  6. def my_gen_special_pybites_dates():
  7. days = 1
  8. while True:
  9. dt = PYBITES_BORN + timedelta(days=days)
  10. # if days % 100 == 0: # commented to print only 'every year'
  11. # yield dt
  12. if dt.month == PYBITES_BORN.month and dt.day == PYBITES_BORN.day:
  13. yield dt
  14. days += 1
  15.  
  16.  
  17. def gen_special_pybites_dates():
  18. days = 0
  19. while True:
  20. days += 1
  21. if days % 365 == 0: # without every 100 days
  22. yield PYBITES_BORN + timedelta(days=days)
  23.  
  24.  
  25. if __name__ == '__main__':
  26. # my func to gen pybites dates
  27. gen = my_gen_special_pybites_dates()
  28.  
  29. from itertools import islice
  30. dates = list(islice(gen, 100))
  31. for date in dates:
  32. print(date.strftime('%Y-%m-%d'))
  33.  
  34. print('-----------------------------')
  35.  
  36. # pybites solution
  37. gen = gen_special_pybites_dates()
  38.  
  39. from itertools import islice
  40. dates = list(islice(gen, 100))
  41. for date in dates:
  42. print(date.strftime('%Y-%m-%d'))
Add Comment
Please, Sign In to add comment