[New-bugs-announce] [issue42356] Dict inline manipulations

Tomek H report at bugs.python.org
Sat Nov 14 06:36:46 EST 2020


New submission from Tomek H <tomek.hlawiczka at googlemail.com>:

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!

----------
components: Interpreter Core
messages: 380972
nosy: tomek.hlawiczka
priority: normal
severity: normal
status: open
title: Dict inline manipulations
type: enhancement
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42356>
_______________________________________


More information about the New-bugs-announce mailing list