Home > Net >  Python max arg is empty sequence on non empty list
Python max arg is empty sequence on non empty list

Time:12-25

I get ValueError: max() arg is an empty sequence from this lines of code:

result = {}

ids = [...] # may be empty
objects_from_ids = func_to_fetch_objects(delivery_ids) # returns empty list, if ids are empty, or list of objects, with corresponding ids

if objects_from_ids:
   result["max_dt"] = max(d["dt"] for d in objects_from_ids) # Here comes error

Can anyone explain me, why this might happen? I`ve read answers about default value for cases with empty sequences, but want to understand this case

CodePudding user response:

The objects_from_ids might be a list of empty objects or the error is in the func_to_fetch_objects()

Try printing there values inside the if clause to know what's going inside.

  • Related