In article <mailman.8703.1396133206.18130.python-l...@python.org>, Tim Chase <t...@thechases.com> wrote:
> On 2014-03-29 18:41, Roy Smith wrote: > > On Mar 29, 2014, at 6:36 PM, Tim Chase wrote: > > > > > And for cases where you have more than one or two things to test > > > for None-itude, you could use > > > > > > if all(x is None for x in [a, b, c, d]): > > > do_something_if_theyre_all_None() > > > > I might have written that as: > > > > if set([a, b, c, d]) == set(None) > > > > That's even clearer if you happen to already have the items in an > > iterable: > > > > if set(conditions) == set(None) > > Though am I correct that your iteration tests for equality, while > mine tests for identity? Hmmm, you're almost certainly correct on that, but you would have to have a perversely designed class for that to make a difference. I'll take the increased readability. > Also, my version bails early in the event > quitting early is possible. That's particularly useful in the case > of doing something like > > if all(x() is None for x in [func1, func2, func3, costly_func]): > do_something() Again, you're correct. But, I'll take the increased readability over the premature optimization :-) -- https://mail.python.org/mailman/listinfo/python-list