4 ms·
I would write that as for item in report(): if any(event in events_we_care_about for event in item['events']): act_upon(
by Asooka 8y ago
I would write that as
for item in report():
if any(event in events_we_care_about
for event in item['events']):
act_upon(item)
But obviously the features that enable this form didn't exist when for...else was added to the language.
- jacob019 8y agoClearly it was a poor example, I wouldn't structure simple code this way either but in more complex situations it can be the simplest solution.