use set notation for repr of dict_keys?

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


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 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).

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 with respect to iterating over the original dictionary to obtain the keys]


More information about the Python-list mailing list