Python Forum

Full Version: when would a frozenset be needed?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
when would a frozenset be needed over a regular set? or why?
for one frozenset can be used as key in a dict. it's a direct result of frozenset being immutable. if you want to prevent set being changed- e.g. think of tuple vs list.
Same as when you asked about tuples vs. lists - immutability is a good idea.
then why is there no immutable equivalent to dictionary?
there is, although as a third-party package on PyPI:
forzendict

As to why not in the Standard Library, read the rejected PEP 416
OK, yeah, i can see many complications, now, like values have to be unchangeable and immutable.
today I saw there is draft PEP 603 - Adding a frozenmap type to collections
It may be interesting to you in the light of the discussion above
so a FrozenMapCopy does not actually change when modifications are applied, but a frozenmap created from a modified FrozenMapCopy reflects those changes?

i don't understand how can be passed to the frozenmap constructor; creating a frozenmap from a FrozenMapCopy object is an O(1) operation; can be O(1).
(Apr-14-2020, 07:55 PM)Skaperen Wrote: [ -> ]FrozenMapCopy does not actually change when modifications are applied,
I think you misunderstood this part, it's the other way around - the frozenmap does not reflect the changes in FrozenMapCOpy
Quote:[FrozenMappCopy] are mutable, although any mutations on them do not affect the frozenmap instances they were created from;
i'm not saying (the opposite of) that. i'm saying... modifications to FrozenMapCopy ...do not actually change that FrozenMapCopy (but instead record the modifications in a way that allows a new frozenmap created from it to be as if the frozenmap were mutable and copied). i get this from that example code (the big example after frozenmap.mutating()) that did del copy[591221] twice without an error.
Pages: 1 2