Could someone explain me why in for in l5 loop I got 2 True values, but from l5.count(True) I got only 1?? And why l5.count(not 0) returns only 1?
I know about other ways to get what I need: filter + lambda or sum + for + if, but I try understand it :)
Under part from Python console I've asked.
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32 '''
l5 = [0, 0, 0, 1, 2]
l5.count(True)
Out[3]: 1
for x in l5:
print(x, bool(x))
0 False
0 False
0 False
1 True
2 True
l5.count(0)
Out[5]: 3
l5.count(not 0)
Out[6]: 1
l5.count(not False)
Out[7]: 1
'''
count(True)will list only 1 value because there is only "1"(True) in the list. Butbool(x)will return 1 for every non-zero value of x. That is why you have 2 true(s).boolon the items in the list and the result isTrueorFalsedoesn't mean the list actually contains these booleans.