Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime, timedelta
- PYBITES_BORN = datetime(year=2016, month=12, day=19)
- def my_gen_special_pybites_dates():
- days = 1
- while True:
- dt = PYBITES_BORN + timedelta(days=days)
- # if days % 100 == 0: # commented to print only 'every year'
- # yield dt
- if dt.month == PYBITES_BORN.month and dt.day == PYBITES_BORN.day:
- yield dt
- days += 1
- def gen_special_pybites_dates():
- days = 0
- while True:
- days += 1
- if days % 365 == 0: # without every 100 days
- yield PYBITES_BORN + timedelta(days=days)
- if __name__ == '__main__':
- # my func to gen pybites dates
- gen = my_gen_special_pybites_dates()
- from itertools import islice
- dates = list(islice(gen, 100))
- for date in dates:
- print(date.strftime('%Y-%m-%d'))
- print('-----------------------------')
- # pybites solution
- gen = gen_special_pybites_dates()
- from itertools import islice
- dates = list(islice(gen, 100))
- for date in dates:
- print(date.strftime('%Y-%m-%d'))
Add Comment
Please, Sign In to add comment