I was wondering if we could assert all elements in a list is not None, therefore while a = None will raise an error.
The sample list is [a, b, c]
I have tried assert [a, b, c] is not None, it will return True if any one of the elements is not None but not verifying all. Could you help figure it out? Thanks!!
Unless you have a weird element that claims it equals None:
assert None not in [a, b, c]
Do you mean by all:
>>> assert all(i is not None for i in ['a', 'b', 'c'])
>>>
Or just simply:
assert None not in ['a', 'b', 'c']
P.S just noticed that @don'ttalkjustcode added the above.
Or with min:
>>> assert min(a, key=lambda x: x is not None, default=False)
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With