classification
Title: Dict inline manipulations
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, terry.reedy, tomek.hlawiczka
Priority: normal Keywords:

Created on 2020-11-14 11:36 by tomek.hlawiczka, last changed 2020-11-21 01:46 by terry.reedy.

Messages (3)
msg380972 - (view) Author: Tomek H (tomek.hlawiczka) Date: 2020-11-14 11:36
With Python3.9 there is a great feature for merging `dict`s:
{1: 'a'} | {2: 'b'} => {1: 'a', 2: 'b'}


It would be very handy to filter out a dict with a similar fashion (for example & operator with a list/tuple/frozenset of keys you want to get back):
{1: 'a', 2: 'b', 3: 'c'} & [1, 3, 4] == {1: 'a', 3: 'c'}
{1: 'a', 2: 'b', 3: 'c'} & {1, 3, 4} == {1: 'a', 3: 'c'}


Also, omitting specified keys (for example - operator with a list/tuple/frozenset of keys you want to suppress):
{1: 'a', 2: 'b', 3: 'c'} - [3, 4] == {1: 'a', 2: 'b'}
{1: 'a', 2: 'b', 3: 'c'} - {3, 4} == {1: 'a', 2: 'b'}


Regards!
msg380980 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-11-14 15:18
I think you should bring this up on the python-ideas mailing list if you'd like to see it discussed. It will likely also require a PEP, similar to PEP 584.
msg381517 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-11-21 01:46
I agree with Eric suggestion.
History
Date User Action Args
2020-11-21 01:46:01terry.reedysetnosy: + terry.reedy
messages: + msg381517
2020-11-14 15:18:59eric.smithsetnosy: + eric.smith
messages: + msg380980
2020-11-14 11:36:46tomek.hlawiczkacreate