Say I have a class Node, with attributes left, right, val. Then suppose we have internal and leaf, where leaf has None for left and right. Then iterating through my_list = [internal, leaf], I only want to add the child nodes to an array only if they exist, so I would do something like
[x.left if x.left is not None for x in my_list]
Is something like this possible? When I try this I get a invalid syntax error