Associative array/Merging: Difference between revisions
Content deleted Content added
Created page with "{{draft task}} ;Task: Define two associative arrays, where one represents the following "base" data: {| class="wikitable" |+ | '''Key''' || '''Value''' |- | "name" || "Rocke..." |
added Python solution |
||
Line 55: | Line 55: | ||
{{output}} |
{{output}} |
||
<pre>{"color": "red", "name": "Rocket Skates", "price": 15.25, "year": 1974}</pre> |
<pre>{"color": "red", "name": "Rocket Skates", "price": 15.25, "year": 1974}</pre> |
||
=={header|Python}}== |
|||
As of Python 3.5, this can be solved with the dictionary unpacking operator. |
|||
<lang Python>base = {"name":"Rocket Skates", "price":12.75, "color":"yellow"} |
|||
update = {"price":15.25, "color":"red", "year":1974} |
|||
result = {**base, **update} |
|||
print(result)</lang> |
|||
{{output}} |
|||
<pre>{'name': 'Rocket Skates', 'price': 15.25, 'color': 'red', 'year': 1974}</pre> |