Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Walrus :) solution in Creative category for Lightbulb End Watching by suic
from datetime import datetime
from itertools import zip_longest
from typing import List, Optional
def sum_light(
els: List[datetime],
start_watching: Optional[datetime] = None,
end_watching: Optional[datetime] = None,
) -> int:
return sum(
d
for d1, d2 in zip_longest(*[iter(els)] * 2, fillvalue=end_watching)
if (
d := (
min(d2, end_watching or d2) - max(d1, start_watching or d1)
).total_seconds()
)
> 0
)
Nov. 12, 2020
Comments: