import datetime count = 0 a1 = datetime.date(2015,1,1) f = lambda x: sum(map(int, list("{:0>2}".format(x)))) for i in range(1,365): if a1.day < 10: if (a1.month == (0 + a1.day)): count += 1 elif (a1.month == f(a1.day)): count += 1 a1 += datetime.timedelta(days=1) print(count)