# Python Set issuperset()

Rate this post

Python’s `set.issuperset(set)` returns `True` if all elements of the specified set argument are members of this set. It determines whether the set on which the method is called is the superset of the specified set.

Here’s a minimal example that checks whether set `s` is a superset of `t`:

```>>> s = {'Alice', 'Bob', 'Carl'}
>>> t = {'Alice', 'Bob'}
>>> s.issuperset(t)
True```

Another minimal Harry Potter example:

```>>> hogwarts = {'Ron', 'Harry', 'Hermione', 'Dumbledore', 'Parvati', 'Malfoy'}
>>> gryffindors = {'Ron', 'Harry', 'Hermione'}
>>> hogwarts.issuperset(gryffindors)
True```

## Syntax

Let’s dive into the formal syntax of the `set.issuperset()` method.

`set.issuperset(set)`

## Return Value of set.issuperset()

The return value of `set.issuperset()` is a Boolean whether the set on which it is called is the superset of the set argument.

There are some subtleties you need to understand regarding the set superset method. Let’s dive into them by example!

```>>> {'Alice', 'Bob'}.issuperset({'Alice'})
True```

?Β Can you also pass a list as an argument to the `set.issuperset()` method? The answer is yes—the method takes any iterable.

```>>> {'Alice', 'Bob'}.issuperset(['Alice'])
True```

A set is the superset of itself.

```>>> s = {1, 2, 3}
>>> s.issuperset(s)
True```

This also means that two empty sets are the supersets of each other.

```>>> set().issubset(set())
True```

Can we pass multiple set arguments into the `set.issuperset()` method? No! It only takes one argument.

```>>> {1, 2, 3}.issuperset({1, 2}, {3})
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
{1, 2, 3}.issuperset({1, 2}, {3})
TypeError: issuperset() takes exactly one argument (2 given)```

To fix this `TypeError`, pass only one set argument into the `set.issuperset()` method.

## What is the Time Complexity of set.issuperset() in Python?

The worst-case runtime complexity of the `set.issuperset()` method for a set with n elements and a set argument with m elements is O(m) because you need to check for each set element whether it’s a member of the set on which the method is called.

You can see this in the following simple experiment where we run the set method multiple times for increasing set sizes:

I ran this experiment on my Acer Aspire 5 notebook (I know) with Intel Core i7 (8th Gen) processor and 16GB of memory. Here’s the code of the experiment:

```import matplotlib.pyplot as plt
import time

sizes = [i * 10**5 for i in range(50)]
runtimes = []

for size in sizes:
s = set(range(size))
t = set(range(0, size, 2))

# Start track time ...
t1 = time.time()
s.issuperset(t)
t2 = time.time()
# ... end track time

runtimes.append(t2-t1)

plt.plot(sizes, runtimes)
plt.ylabel('Runtime (s)')
plt.xlabel('Set Size')

plt.show()

```

## Other Python Set Methods

All set methods are called on a given set. For example, if you created a set `s = {1, 2, 3}`, you’d call `s.clear()` to remove all elements of the set. We use the term “this set” to refer to the set on which the method is executed.