def snap_to_beginning_of_week ( day , weekday_start = "Sunday" ) : delta_days = ( ( day . weekday ( ) + 1 ) % 7 ) if weekday_start is "Sunday" else day . weekday ( ) return day - timedelta ( days = delta_days )
custom week start day for python weekday
Get the first day of the current week .
def snap_to_beginning_of_week(day, weekday_start="Sunday"):
    """ Get the first day of the current week.

    :param day: The input date to snap.
    :param weekday_start: Either "Monday" or "Sunday", indicating the first day of the week.
    :returns: A date representing the first day of the current week.
    """
    delta_days = ((day.weekday() + 1) % 7) if weekday_start is "Sunday" else day.weekday()
    return day - timedelta(days=delta_days)