Re: use set notation for repr of dict_keys?

2021-02-24 Thread Marco Sulla
On Wed, 24 Feb 2021 at 15:02, Random832 wrote: > On Wed, Feb 24, 2021, at 02:59, Marco Sulla wrote: > > On Wed, 24 Feb 2021 at 06:29, Random832 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 -

Re: use set notation for repr of dict_keys?

2021-02-24 Thread Random832
On Wed, Feb 24, 2021, at 02:59, Marco Sulla wrote: > On Wed, 24 Feb 2021 at 06:29, Random832 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)

Re: use set notation for repr of dict_keys?

2021-02-24 Thread Marco Sulla
On Wed, 24 Feb 2021 at 06:29, Random832 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

Re: use set notation for repr of dict_keys?

2021-02-23 Thread Chris Angelico
On Wed, Feb 24, 2021 at 4:29 PM Random832 wrote: > > AIUI the keys, values, and items collections have always had the ordering > guarantee that iterating over them while not modifying the underlying > dictionary will give the same order each time [with respect to each other, > and possibly also

Re: use set notation for repr of dict_keys?

2021-02-23 Thread Random832
On Sat, Feb 20, 2021, at 15:00, dn via Python-list wrote: > So, the output is not a set (as you say) but nor (as > apparently-indicated by the square-brackets) is it actually a list! To be clear, it is an instance of collections.abc.Set, and supports most binary operators that sets support. I wa

Re: use set notation for repr of dict_keys?

2021-02-20 Thread dn via Python-list
On 20/02/2021 20.25, Wolfgang Stöcher wrote: > Having a dict like >   d = {'one': 1, 'two': 2} > the representation of its keys >   repr(d.keys()) > gives >   "dict_keys(['one', 'two'])" > > But since the keys are unique, wouldn't a representation using the set > notation > be more intuitive, i.e.

Re: use set notation for repr of dict_keys?

2021-02-20 Thread Terry Reedy
On 2/20/2021 2:25 AM, Wolfgang Stöcher wrote: Having a dict like   d = {'one': 1, 'two': 2} the representation of its keys   repr(d.keys()) gives   "dict_keys(['one', 'two'])" But since the keys are unique, wouldn't a representation using the set notation be more intuitive, i.e. what about c

use set notation for repr of dict_keys?

2021-02-20 Thread Wolfgang Stöcher
Having a dict like d = {'one': 1, 'two': 2} the representation of its keys repr(d.keys()) gives "dict_keys(['one', 'two'])" But since the keys are unique, wouldn't a representation using the set notation be more intuitive, i.e. what about changing the output of dict_keys.__repr__ to