|
|
Subscribe / Log in / New account

Python sets, frozensets, and literals

Python sets, frozensets, and literals

Posted Jan 20, 2022 18:48 UTC (Thu) by JoeBuck (subscriber, #2330)
In reply to: Python sets, frozensets, and literals by quietbritishjim
Parent article: Python sets, frozensets, and literals

You'd solve it by adding coercions as needed: uses of set that require hashable objects would be handled by converting to frozenset.

But it probably isn't a good idea, because it could be unexpectedly expensive: people expect hashes to be fast, and if we're always doing copy-and-insert, copy-and-hash it would be costly.


to post comments

Python sets, frozensets, and literals

Posted Jan 20, 2022 23:08 UTC (Thu) by quietbritishjim (subscriber, #114117) [Link]

Sounds like you were thinking of the first of the two possibilities I mentioned in my comment:

> If you copy the set into a frozenset then changes to X won't be reflected in the new location - very confusing.

I think the fact that changes to the original set won't be reflected in the frozenset made from it earlier is even more serious than the cost of the copy.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds