![]() |
when would a frozenset be needed? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: when would a frozenset be needed? (/thread-25377.html) Pages:
1
2
|
when would a frozenset be needed? - Skaperen - Mar-28-2020 when would a frozenset be needed over a regular set? or why? RE: when would a frozenset be needed? - buran - Mar-28-2020 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. RE: when would a frozenset be needed? - ndc85430 - Mar-28-2020 Same as when you asked about tuples vs. lists - immutability is a good idea. RE: when would a frozenset be needed? - Skaperen - Mar-29-2020 then why is there no immutable equivalent to dictionary? RE: when would a frozenset be needed? - buran - Mar-29-2020 there is, although as a third-party package on PyPI: forzendict As to why not in the Standard Library, read the rejected PEP 416 RE: when would a frozenset be needed? - Skaperen - Apr-01-2020 OK, yeah, i can see many complications, now, like values have to be unchangeable and immutable. RE: when would a frozenset be needed? - buran - Apr-14-2020 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 RE: when would a frozenset be needed? - Skaperen - Apr-14-2020 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). RE: when would a frozenset be needed? - buran - Apr-14-2020 (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; RE: when would a frozenset be needed? - Skaperen - Apr-14-2020 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.
|