Skip to content

Commit c8413bf

Browse files
authored
Merge pull request wilfredinni#33 from Sonatrix/master
Merge two dictionaries
2 parents ab87bc8 + b1abbd6 commit c8413bf

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

blog_files/pysheet.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,22 @@ Using `setdefault` we could make the same code more shortly:
12251225
'w': 2,
12261226
'y': 1}
12271227
```
1228+
### Merge two dictionaries
1229+
1230+
```python
1231+
# in Python 3.5+:
1232+
>>> x = {'a': 1, 'b': 2}
1233+
>>> y = {'b': 3, 'c': 4}
1234+
>>> z = {**x, **y}
1235+
>>> z
1236+
{'c': 4, 'a': 1, 'b': 3}
1237+
1238+
# in Python 2.7
1239+
>>> z = dict(x, **y)
1240+
>>> z
1241+
{'c': 4, 'a': 1, 'b': 3}
1242+
```
1243+
12281244

12291245
## sets
12301246

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy