-1

Given a 4 digit year, return the number of the day on which January 1st falls. 0 is Sunday, …, 6 is Saturday

vaultah
  • 44,105
  • 12
  • 114
  • 143

1 Answers1

0

You can use the datetime library

import datetime

d = datetime.date(year, 1, 1)
weekday = d.isoweekday() % 7

The datetime library starts all weeks on Monday, so you need to do a bit of a conversion to get Sunday to be 0

Brendan Abel
  • 35,343
  • 14
  • 88
  • 118
  • @chrisz Yes, for `weekday()`, it's Mon-Sun (0-6), `isoweekday()` is still Mon-Sun, but it runs `1-7`, I'm just converting `7` to `0` – Brendan Abel Apr 11 '18 at 18:48