I am looking for a possible equivalent of the following loop in python list comprehension.
for foo in foos:
if foo.text == expected_text
return foo
return []
Something like this.
found_foo = [foo for foo in foos if foo.text == expected_text]
If this possible using list comprehension?
fooor an empty list? This is not usually a good designfound_foois actually a list with length == 1 and when the match is not found[]with length is returned