I am attempting to write a single line of Python code for the following:
is_valid = False
for single_object in object_list:
if single_object.test == test:
is_valid = True
if not is_valid:
return 'Bad data!'
I know that there has to be a way to accomplish this in less code. I mean, it’s Python!
The
any(iterable)function returnsTrueif any of the values initerableareTrue, andFalseif none of them are. I’m using a “generator expression” to go through the values inobject_listand evaluate the condition.