This is a part of my code:
for d in errors[:]:
if False in d:
Ic.append(current_mA2)
And this is in errors
:
[True, True, True, False, True, True, False, True,True,True, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False,False]
I just want to know if the value False is in the list.
Python all() Function The all() function returns True if all items in an iterable are true, otherwise it returns False.
to directly check if False is in list. list implements the __contains__ magic method so you can just do that. This works for the specific case the OP presents. Be warned, though, if the list errors contains an integer 0 etc, it automatically returns true, eg., False in [0, True] returns True .
We can use the in-built python List method, count(), to check if the passed element exists in the List. If the passed element exists in the List, the count() method will show the number of times it occurs in the entire list. If it is a non-zero positive number, it means an element exists in the List.
No one suggested using all()
(python doc here).
All checks wether all values in a list interpret to True, meaning, if at least one of them is False, it will return False:
> a_list = [True, True, False]
> b_list = [True, True, True]
> all(a_list)
False
> all(b_list)
True
Why not just:
if False in errors:
Ic.append(current_mA2)
to directly check if False
is in list. list
implements the __contains__
magic method so you can just do that.
How about
isFalseIn = False in errors
I think that works.
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