Home › Forums › Batch of Feb 26, 2024 › frozenset
-
frozenset
Posted by Debarpan on February 29, 2024 at 6:40 amwhat is the use case of frozenset as it is immutable once created.So we cant modify it.
Deleted User replied 1 year ago 4 Members · 5 Replies -
5 Replies
-
Deleted User
MemberFebruary 29, 2024 at 7:33 amIn python frozenset is similar to set but unlike set, elements cannot be added or removed from a frozenset since they are frozen. Frozenset can be used as Dictionary keys(since keys in a Dictionary are immutable) and also as elements in another set.
-
example :
fruits = {‘apple’, ‘banana’, ‘cherry’}
x = frozenset(fruits) #
x[1] = “strawberry” #Attempting to modify a frozenset will result in a TypeError# If you need to modify the set, we need to use a regular set instead
fruits.add(“strawberry”)
print(fruits)
-
Yes I know about frozensets, I am just asking what is the usecase of it like for what purpose we can utilize it?
-
Deleted User
MemberFebruary 29, 2024 at 6:08 pmHi Debarpan. You can refer to my reply where I have mentioned two possible use cases of frozenset.
-
-
-
Log in to reply.