I have a question about the following python outcome. Suppose I have a tuple :
a = ( (1,1), (2,2), (3,3) )
I want to remove (2,2)
, and I'm doing this with the following code:
tuple([x for x in a if x != (2,2)])
This works fine, the result is: ( (1,1), (3,3) )
, just as I expect.
But suppose I start from a = ( (1,1), (2,2) )
and use the same tuple() command, the result is ( (1,1), )
while I would expect it to be ((1,1))
In short
>>> a = ( (1,1), (2,2), (3,3) )
>>> tuple([x for x in a if x != (2,2)])
((1, 1), (3, 3))
>>> a = ( (1,1), (2,2) )
>>> tuple([x for x in a if x != (2,2)])
((1, 1),)
Why the comma and empty element in the second case? And how do I get rid of it?
Thanks!