3 ms·
If dicts did subclass sets, then sets would be dicts whose values are all None. In other words, your last example would be defined as: >>> s = {'one', 'two
by kbd 8y ago
If dicts did subclass sets, then sets would be dicts whose values are all None. In other words, your last example would be defined as:
>>> s = {'one', 'two'}
>>> d = {}
>>> d.update(s)
>>> d
{'two': None, 'one': None}
- deleted 8y ago[deleted]
- pdpi 8y agoIf sets are dicts with values of None, then they're dicts, not a superclass of dict.
- eesmith 8y agoWould s["one"] = 1 raise an exception? Or convert the set into a dict? Or change the sentinel value for all the set elements? None seem like a good design since it means either the instance change its class on the fly (which Python does support) or that a dict does not act like its parent set object, breaking the is-a relationship most people expect from an OO design. It seems like the circle/ellipse problem, and the current implementation is the "drop all inheritance relationships" solution to that problem. https://en.wikipedia.org/wiki/Circle-ellipse_problem#Drop_all_inheritance_relationships https://en.wikipedia.org/wiki/Circle-ellipse_problem#Drop_al...
- kbd 8y ago> Would s["one"] = 1 raise an exception? Sets don't support indexing, so it would still raise an exception. Dicts do, which is an example of them supporting more operations than sets, which is an example of why (if there is to be any subclass relation) dicts are subclasses of sets. Edit: I suppose there's some confusion about my language above. "then sets would be dicts whose values are all None" could more helpfully read "sets would be equivalent to dicts whose...".