checking if two things do not equal None

Roy Smith roy at panix.com
Sat Mar 29 18:41:03 EDT 2014


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)


--
Roy Smith
roy at panix.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140329/e858779c/attachment.html>


More information about the Python-list mailing list