File: day-of-the-week/solution.py

Date: 2026-06-06

Time: 16:09

day-of-the-week/solution.py

Purpose

This file solves LeetCode 1185 — Day of the Week. Given a date as three integers (day, month, year), it returns the English name of that weekday. It's a thin wrapper around Python's datetime.date.weekday().

Key Components

dayofthe_week(day, month, year) -> str — The sole function. Takes integer date components, constructs a datetime.date, and indexes into a lookup table to return the day name.

days list — Maps weekday() return values (0=Monday through 6=Sunday) to their English names. Each string has a trailing space (e.g., "Saturday "), which is a quirk worth noting — this matches the LeetCode problem's expected output format but would be surprising to a caller expecting clean strings.

Patterns

Dependencies

Imports: datetime (stdlib). No project-internal dependencies.

Imported by: day-of-the-week/test_solution.py directly. The "Imported By" list in the prompt is misleading — those hundreds of test files import from their own respective solution.py, not from this one.

Flow

1. Caller passes (day, month, year) integers.

2. datetime.date(year, month, day) constructs a date object — note the argument reordering (year first for datetime.date).

3. .weekday() returns an int 0–6 (Monday–Sunday).

4. That int indexes into days, returning the name string.

Single expression, no branching, O(1).

Invariants

Error Handling

None. Invalid dates (e.g., Feb 30) propagate as ValueError from datetime.date(). There's no try/except — the function assumes valid input per the LeetCode problem constraints.

Topics to Explore

Beliefs