ValueError: max() arg is an empty sequence
max() and min() have no answer for an empty list, so they raise. Give them a default, or handle the empty case first.
What it means
There is no largest item in nothing. Python 3.12 and later word it "max() iterable argument is empty"; older versions say "max() arg is an empty sequence". Both mean the list, filter or generator you passed had no items.
Common causes
1. No data yet
New users, new products and empty days all produce empty lists.
Breaks
best = max(scores)Works
best = max(scores, default=0)2. A filter that matched nothing
The generator is empty when no item passes the condition.
Breaks
cheapest = min(p for p in prices if p > budget)Works
cheapest = min((p for p in prices if p > budget), default=None)3. max() with a key over an empty dictionary
The same rule applies to dictionaries.
Breaks
top = max(counts, key=counts.get)Works
top = max(counts, key=counts.get) if counts else NoneHow to find it in your own code
Decide what an empty input should mean (0, None, a message) and pass it as default=. Then check why it was empty: no data yet is expected, but an empty list from a wrong filter is the real bug.
Still not sure why yours breaks?
Paste it into the visualizer and watch it run line by line, with every variable at every step. Free, and it runs in your browser.