Anonymous user
Associative array/Merging: Difference between revisions
→{{header|Python}}: added alternative
m (→{{header|REXX}}: changed wording in the REXX section header.) |
(→{{header|Python}}: added alternative) |
||
Line 271:
=={{header|Python}}==
As of Python 3.5, this can be solved with the dictionary unpacking operator.
{{works with|Python|3.5+}}
<lang Python>base = {"name":"Rocket Skates", "price":12.75, "color":"yellow"}
update = {"price":15.25, "color":"red", "year":1974}
Line 277 ⟶ 278:
print(result)</lang>
{{output}}
<pre>{'name': 'Rocket Skates', 'price': 15.25, 'color': 'red', 'year': 1974}</pre>
Alternative:
<lang Python>base = {"name":"Rocket Skates", "price":12.75, "color":"yellow"}
update = {"price":15.25, "color":"red", "year":1974}
base.update(update)
print(base)</lang>
{{output}}
<pre>{'name': 'Rocket Skates', 'price': 15.25, 'color': 'red', 'year': 1974}</pre>
|