from datetime import datetime, timedelta year = 2015 start_date = datetime(year, 1, 1) end_date = datetime(year, 12, 31) delta = timedelta(days=1) curr_date = start_date cnt = [] while curr_date <= end_date: if curr_date.month == (curr_date.day//10 + curr_date.day%10): cnt.append(1) curr_date += delta print(sum(cnt))