Why operations between dict views return a set and not a frozenset?

Antoon Pardon antoon.pardon at vub.be
Wed Jan 5 09:06:32 EST 2022



Op 4/01/2022 om 19:27 schreef Marco Sulla:
> $ python
> Python 3.10.0 (heads/3.10-dirty:f6e8b80d20, Nov 18 2021, 19:16:18)
> [GCC 10.1.1 20200718] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> a = {1:2}
>>>> c = {1:2, 3:4}
>>>> c.keys() - a.keys()
> {3}
>
> Why not frozenset({3})?

My 2 cents worths: Because dictviews mutate with the directory. That makes
them more like set than like frozenset. So operations on them produce a set.

-- 
Antoon Pardon.


More information about the Python-list mailing list