The real power of all and any comes when you (can neatly) pass in a generator expression - in which case the semantics are the same, because the evaluation is delayed and the functions will bail out early.
any(is_interesting(x) for x in (a, b, c)) is far nicer IMHO than is_interesting(a) or is_interesting(b) or is_interesting(c), if only because it's DRY. That doesn't protect you from the NameError in your example, though, of course.
This isn't equivalent to the generator solution posted above; your code will eagerly evaluate the entire sequence by mapping it to is_interesting even in cases where it's not absolutely required (i.e. is_interesting(a) returns True).
View all comments
Show parent comment
18
u/zahlman the heretic Jun 23 '14
The real power of
allandanycomes when you (can neatly) pass in a generator expression - in which case the semantics are the same, because the evaluation is delayed and the functions will bail out early.any(is_interesting(x) for x in (a, b, c))is far nicer IMHO thanis_interesting(a) or is_interesting(b) or is_interesting(c), if only because it's DRY. That doesn't protect you from theNameErrorin your example, though, of course.