Python Forum
when would a frozenset be needed?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
when would a frozenset be needed?
#1
when would a frozenset be needed over a regular set? or why?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Same as when you asked about tuples vs. lists - immutability is a good idea.
Reply
#4
then why is there no immutable equivalent to dictionary?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
there is, although as a third-party package on PyPI:
forzendict

As to why not in the Standard Library, read the rejected PEP 416
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
OK, yeah, i can see many complications, now, like values have to be unchangeable and immutable.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#7
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
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).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#9
(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;
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#10
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  frozenset.copy() docs wrong Skaperen 8 3,566 Apr-08-2020, 12:56 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020