Python frozenset()

In this post, we will see about Python frozenset() function.
Python frozenset returns immutable version of set.Unlike set, once frozenset is created, it can not be modified.It is suitable for keys in the dictionary.


Syntax


Return

It returns

  • frozenset initialized with elements of iterable
  • If no argument is passed, it creates empty frozenset

Example

Let’s see a simple example:

frozenset using List

l=[1,2,3,4,3,2,3,2] frozenSet=frozenset(l) print(frozenSet)

Output:

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

frozenset using tuple

t=(1,32,3,21,21,32) frozenSet=frozenset(t) print(frozenSet)

Output:

frozenset({32, 1, 3, 21})

frozenset using dictionary

d={'x':2,'y':1,'z':5} frozenSet=frozenset(d) print(frozenSet)

Output:

frozenset({‘z’, ‘y’, ‘x’})

That’s all about frozenset function in python.

Leave a Reply

Your email address will not be published. Required fields are marked *