from datetime import date, timedelta d1 = date(2015,1,1) d2 = date(2015,12,31) c=0 for i in range((d2 - d1).days + 1): date = d1 + timedelta(i) m=date.month d=date.day if m==d//10+d%10: c+=1 print(c)