Question: I've two python class 'tuples' and and i want to compare contents on both of them and get only which is only in 'deactivated' tuple for eg.,

```
deactivated = ((34, 'abcd'), (250, 'def'), (350, 'xyz'))
schedules = ((34, 'abcd'), (250, 'def'))
to_deactivate = ()

```

in here, i want to push `(350, 'xyz')` which is not in schedules to another variable `to_deactivate`.

I've looked into some of the solutions online but most of them are just comparing whether the tuples are same or not. Please help me out on this.

Answer: 
Are you sure you those variables should be tuples?

Because tuples are immutable. In their essence, you are not supposed to add or remove things from them. It looks like those variables are intended to be collections to which you add or remove things. Which is not possible with tuples.

For example, sets, since you don't seem to bother about order, but do seem to be interested about what is or is not in them. That is what `sets` are for. Very quick to check whether something is in it or not (with the same easy `in` operator. But `in` is O(n) for lists or tuples, and is O(log(n)), and in practice even O(1) with sets).

So, that is just a remark, but I feel that those variables should have been sets.
In which case, answer to your question would simply have been

```py
to_deactivate =  deactivated - schedules

```

Even if you insist on keeping them as tuples, one compact answer is still to use sets

```py
to_deactivate=tuple(set(deactivated)-set(schedules))

```

Note that this is faster than the compound tuple solution. (1.38 μs vs 1.59 μs on my computer. And the timing difference grows when the size of the input tuples grows)

Timings
-------

Just to make my point about timing clear, here is how much times it takes to compute is with the "compound tuple" strategy (Andrej's answer)

[![enter image description here](https://i.stack.imgur.com/RpO91.png)](https://i.stack.imgur.com/RpO91.png)

Of course, curve fitting is not a complexity method evaluation, but, well, since instinct says that we can expect either O(n), O(nlog(n)) or O(n²) complexity, we can conclude that we are clearly on the O(n²) side here.

Where as with conversion to sets :
[![enter image description here](https://i.stack.imgur.com/yvCMZ.png)](https://i.stack.imgur.com/yvCMZ.png)

Which looks as a straight line as it can get.
So, clearly, on the O(n) side.

And, of course, put together, we have a match clearly in favor of sets.

[![enter image description here](https://i.stack.imgur.com/zd4hG.png)](https://i.stack.imgur.com/zd4hG.png)

And to reply to SUTerliakov's comment: not just for big values. Even at the very start, sets win. Just a zoom on previous graph.

[![enter image description here](https://i.stack.imgur.com/M8yyk.png)](https://i.stack.imgur.com/M8yyk.png)

And that is comparing set in their most defavorable usage: when we keep every thing in tuples, and then convert to set only for the operation. It would be even faster if variables were sets from the beginning. And in the question, there is really no indication that there is a reason from them not to be sets.
Try:

```py
deactivated = ((34, "abcd"), (250, "def"), (350, "xyz"))
schedules = ((34, "abcd"), (250, "def"))

to_deactivate = tuple(tpl for tpl in deactivated if tpl not in schedules)
print(to_deactivate)

```

Prints:

```
((350, 'xyz'),)

```