0

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,

Ramin Farajpour Cami
  • 1,605
  • 3
  • 11
  • 21

2 Answers2

6

You can simply use .remove method for lists when you know the element that is to be removed.

>>> a = [(1,2),(2,3),(3,3)]
>>> a.remove((1,2))
>>> a
[(2, 3), (3, 3)]
shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
1

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)]
>>> 
SuperNova
  • 25,512
  • 7
  • 93
  • 64