Convert sets to frozensets as values of a dictionary

Posted by Space_C0wb0y on Stack Overflow See other posts from Stack Overflow or by Space_C0wb0y
Published on 2010-06-14T13:19:35Z Indexed on 2010/06/14 13:22 UTC
Read the original article Hit count: 156

Filed under:
|
|

I have dictionary that is built as part of the initialization of my object. I know that it will not change during the lifetime of the object. The dictionary maps keys to sets. I want to convert all the values from sets to frozensets, to make sure they do not get changed. Currently I do that like this:

for key in self.my_dict.iterkeys():
    self.my_dict[key] = frozenset(self.my_dict[key])

Is there a simpler way to achieve this? I cannot build frozenset right away, because I do not how much items will be in each set until i have built the complete dictionary.

© Stack Overflow or respective owner

Related posts about python

Related posts about dictionary