dez = {(1, 2, 3, 4), 5, 6}

you need to remove any element in the tuple that is in the set: 1, 2, 3, or 4

  • in the example you do not have a list, but a tuple that is immutable, you can create a copy of the tuple without a specific element and remove the original tuple from the set. - Alexander Druz
  • sorry corrected. - Dnpy

1 answer 1

You cannot delete an item from a tuple, because this type is immutable. You can remove a tuple from the set, and instead create a new tuple without some element.

 >>> dez = {(1, 2, 3, 4), 5, 6} >>> dez.remove((1, 2, 3, 4)) >>> dez set([5, 6]) >>> dez.add((1, 2, 3)) >>> dez set([5, 6, (1, 2, 3)]) 
  • You can show how to create a tuple without the specified element: tuple(el for el in tup if el != 4) - jfs