use set notation for repr of dict_keys?

Random832 random832 at fastmail.com
Wed Feb 24 09:00:21 EST 2021


On Wed, Feb 24, 2021, at 02:59, Marco Sulla wrote:
> On Wed, 24 Feb 2021 at 06:29, Random832 <random832 at fastmail.com> wrote:
> > I was surprised, though, to find that you can't remove items directly from the key set, or in general update it in place with &= or -= (these operators work, but give a new set object).
> 
> This is because they are a view. Changing the key object means you
> will change the underlying dict. Probably not that you want or expect.

Why wouldn't it be what I want or expect? Java allows exactly this [and it's the only way provided to, for example, remove all keys matching a predicate in a single pass... an operation that Python sets don't support either]

> You can just "cast" them into a "real" set object.
> 
> There was a discussion to implement the whole Set interface for dicts.
> Currently, only `|` is supported.


More information about the Python-list mailing list