Skip to content

Instantly share code, notes, and snippets.

@NekoTashi
Created January 3, 2018 15:10
Show Gist options
  • Save NekoTashi/93d4fe62b846fabff3ec2f00daf98c66 to your computer and use it in GitHub Desktop.
Save NekoTashi/93d4fe62b846fabff3ec2f00daf98c66 to your computer and use it in GitHub Desktop.
365 does not include leap year.
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'))
# % python3 test_gen.py
# 2017-12-19
# 2018-12-19
# 2019-12-19
# 2020-12-19
# 2021-12-19
# 2022-12-19
# 2023-12-19
# 2024-12-19
# 2025-12-19
# 2026-12-19
# 2027-12-19
# 2028-12-19
# 2029-12-19
# 2030-12-19
# 2031-12-19
# 2032-12-19
# 2033-12-19
# 2034-12-19
# 2035-12-19
# 2036-12-19
# 2037-12-19
# 2038-12-19
# 2039-12-19
# 2040-12-19
# 2041-12-19
# 2042-12-19
# 2043-12-19
# 2044-12-19
# 2045-12-19
# 2046-12-19
# 2047-12-19
# 2048-12-19
# 2049-12-19
# 2050-12-19
# 2051-12-19
# 2052-12-19
# 2053-12-19
# 2054-12-19
# 2055-12-19
# 2056-12-19
# 2057-12-19
# 2058-12-19
# 2059-12-19
# 2060-12-19
# 2061-12-19
# 2062-12-19
# 2063-12-19
# 2064-12-19
# 2065-12-19
# 2066-12-19
# 2067-12-19
# 2068-12-19
# 2069-12-19
# 2070-12-19
# 2071-12-19
# 2072-12-19
# 2073-12-19
# 2074-12-19
# 2075-12-19
# 2076-12-19
# 2077-12-19
# 2078-12-19
# 2079-12-19
# 2080-12-19
# 2081-12-19
# 2082-12-19
# 2083-12-19
# 2084-12-19
# 2085-12-19
# 2086-12-19
# 2087-12-19
# 2088-12-19
# 2089-12-19
# 2090-12-19
# 2091-12-19
# 2092-12-19
# 2093-12-19
# 2094-12-19
# 2095-12-19
# 2096-12-19
# 2097-12-19
# 2098-12-19
# 2099-12-19
# 2100-12-19
# 2101-12-19
# 2102-12-19
# 2103-12-19
# 2104-12-19
# 2105-12-19
# 2106-12-19
# 2107-12-19
# 2108-12-19
# 2109-12-19
# 2110-12-19
# 2111-12-19
# 2112-12-19
# 2113-12-19
# 2114-12-19
# 2115-12-19
# 2116-12-19
# -----------------------------
# 2017-12-19
# 2018-12-19
# 2019-12-19
# 2020-12-18
# 2021-12-18
# 2022-12-18
# 2023-12-18
# 2024-12-17
# 2025-12-17
# 2026-12-17
# 2027-12-17
# 2028-12-16
# 2029-12-16
# 2030-12-16
# 2031-12-16
# 2032-12-15
# 2033-12-15
# 2034-12-15
# 2035-12-15
# 2036-12-14
# 2037-12-14
# 2038-12-14
# 2039-12-14
# 2040-12-13
# 2041-12-13
# 2042-12-13
# 2043-12-13
# 2044-12-12
# 2045-12-12
# 2046-12-12
# 2047-12-12
# 2048-12-11
# 2049-12-11
# 2050-12-11
# 2051-12-11
# 2052-12-10
# 2053-12-10
# 2054-12-10
# 2055-12-10
# 2056-12-09
# 2057-12-09
# 2058-12-09
# 2059-12-09
# 2060-12-08
# 2061-12-08
# 2062-12-08
# 2063-12-08
# 2064-12-07
# 2065-12-07
# 2066-12-07
# 2067-12-07
# 2068-12-06
# 2069-12-06
# 2070-12-06
# 2071-12-06
# 2072-12-05
# 2073-12-05
# 2074-12-05
# 2075-12-05
# 2076-12-04
# 2077-12-04
# 2078-12-04
# 2079-12-04
# 2080-12-03
# 2081-12-03
# 2082-12-03
# 2083-12-03
# 2084-12-02
# 2085-12-02
# 2086-12-02
# 2087-12-02
# 2088-12-01
# 2089-12-01
# 2090-12-01
# 2091-12-01
# 2092-11-30
# 2093-11-30
# 2094-11-30
# 2095-11-30
# 2096-11-29
# 2097-11-29
# 2098-11-29
# 2099-11-29
# 2100-11-29
# 2101-11-29
# 2102-11-29
# 2103-11-29
# 2104-11-28
# 2105-11-28
# 2106-11-28
# 2107-11-28
# 2108-11-27
# 2109-11-27
# 2110-11-27
# 2111-11-27
# 2112-11-26
# 2113-11-26
# 2114-11-26
# 2115-11-26
# 2116-11-25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment