Wednesday 28 March 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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...