Set of Sets in Python

If you try to create a set of dictionaries or a set of lists, the code is going to be executed without a problem.

Try to run the following code that represents a set of sets in Python.

The interpreter will return the following error:

TypeError: unhashable type: 'set'

Sets objects are mutable, but they can use mutable objects inside them, such as lists, sets, or dicts.

What you can do in this case, is to create an immutable set object, called frozenset.

This is how it will look in our code:

This is the result we are going to get:

{frozenset({1, 2, 3}), frozenset({2, 3, 4}), frozenset({3, 4, 5})}