"if" gets tricky inside __init__

Hello I have a simple problem but very problematic.

I got a class, and in the attributes i got something like that:

self.List = [ obj_0, obj_1, … ]

the objects inside List are instances that have an attribute called “is_active”, and its value can only be “True” or “False”.

I extract the elements from self.List, to build a new one with only active objects

self.active_objects = [ ele for ele in self.List if ele.is_active == True ]

The result gives 2 elements while there whould be 4

when I make the second list outsine the console, it works well.
Can Someone explain me why is this occuring ? And how can I solve this problem ?

Well your code looks correct (only thing you could change is drop the “== True”):

self.active_objects = [ ele for ele in self.List if ele.is_active ]

The result gives 2 elements while there whould be 4
when I make the second list outsine the console, it works well.

Maybe the context is different?
Can you describe more closely where these objects come from, what marks them as is_active etc.?

Yeah I have figured out that I forgot that there is a modification in the property is_active of some objects in self.List .
first in init, there is just two elements but later on, ther is a method of the instance that adds 2 more elements.
Thanks for your attention. I made another list with tuples that shows [ (obj_0, True), (obj_1,False), …]
Two of them were shown as True.
But in the end, when the instance was created and methods were called, we could get two tuples like (obj, False) have the value of is_active == True.
So finally, “if” cannot get tricky, well, I got this problems fews times with other classes and tough wrongly that the problem was in the “if”.