Wednesday, March 28, 2018

How do I print the difference of a tuple in python




I want to output difference two tuple and remove one element on tuple



a = [(1,2),(2,3),(3,3)]
if (1,2) in a:
## how to remove (1,2) on tuple


i need output [(2,3),(3,3)] how to do it?




Thanks,


Answer



Other way, you can use del



>>> a = [(1,2),(2,3),(3,3)]
>>> del a[a.index((1,2))]
>>> a
[(2, 3), (3, 3)]
>>>



or using .pop



>>> a = [(1,2),(2,3),(3,3)]
>>> a.pop(a.index((1,2)))
(1, 2)
>>> a
[(2, 3), (3, 3)]
>>>


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...