The following code block raises the aforementioned question:
L1 = [1, True, 0, False]*5
L2 = [True, 1, False, 0]*5
D1 = dict(zip(L1, range(len(L1))))
D2 = dict(zip(L2, range(len(L2))))
print(L1) # [1, True, 0, False, 1, True, 0, False, 1, True, 0, False, 1, True, 0, False, 1, True, 0, False]
print(D1) # {1: 17, 0: 19}
print(L2) # [True, 1, False, 0, True, 1, False, 0, True, 1, False, 0, True, 1, False, 0, True, 1, False, 0]
print(D2) # {True: 17, False: 19}
#print(True in D1)
#print(0 in D2)
#print(True == 1)
#print(False == 0)
I can understand that being a subclass of int
this is the expected behavior of bool
. But does that not affect the structure of list
?
How can I handle their (1 and 0
or True and False
) explicit presence in any case?
i.e. I want something like: {1 : 16, True : 17, 0 : 18, False : 19}
(in case of D1
), in a pure pythonic way.