News for hackers. Stuff that matters.
Re:ChatGPT: How many weekdays were there in June 2023? Answe... by gabrielsroka on Wednesday August 02, 2023 @03:15PM (#36975682)
I would have changed the following two lines, that way, you don't have to know what the last day of the month is.

   end_date = datetime(2023, 7, 1)
   # ...
   while current_date < end_date:
This is a lot shorter though maybe harder to read:

  >>> import calendar
  >>> c = calendar.Calendar()
  >>> sum(1 for d, w in c.itermonthdays2(2023, 6) if d > 0 and calendar.MONDAY <= w <= calendar.FRIDAY)
  22

There are no comments on this comment yet.