[PYTHON] I read PEP 584 (Add Union Operators To dict)

The other day, PEP 584 (Add Union Operators To dict) became Final Commit / python / peps / pull / 1440) I saw it. So, this time I will read PEP 584.

Overview

approach

Combine the two dictionaries with d1 | d2. If you have the same key, it will be overwritten with the contents of the dictionary on the right, so it is not commutative (the order of the keys in the new dictionary will also change).

>>> d = {'spam': 1, 'eggs': 2, 'cheese': 3}
>>> e = {'cheese': 'cheddar', 'aardvark': 'Ethel'}
>>> d | e
{'spam': 1, 'eggs': 2, 'cheese': 'cheddar', 'aardvark': 'Ethel'}
>>> e | d
{'aardvark': 'Ethel', 'spam': 1, 'eggs': 2, 'cheese': 3}

It also supports the | = operator.

>>> d |= e
>>> d
{'spam': 1, 'eggs': 2, 'cheese': 'cheddar', 'aardvark': 'Ethel'}

Impressions

Recommended Posts

I read PEP 584 (Add Union Operators To dict)
I read PEP 618 (Add Optional Length-Checking To zip)
I read PEP 604 (Complementary syntax for Union []).
I read PEP 613 (Explicit Type Aliases)
I read PEP 612 (Parameter Specification Variables)
I read PEP-362 (Function Signature Object) Memo
What I always add to my ~ / .bashrc
I read PEP 614 (Relaxing Grammar Restrictions On Decorators)
I read "How to make a hacking lab"
I read PEP-593 (Flexible function and variable annotations)
I tried to read and save automatically with VOICEROID2 2
I read PEP-544 (Protocols: Structural subtyping (static duck typing)).
I read PEP 585 (Type Hinting Generics In Standard Collections)
I tried to automatically read and save with VOICEROID2
I read the Chainer reference (updated from time to time)