Associative array/Merging: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Used more explicit base.copy() instead of dict(base))
m (indented tables to be more centered.)
Line 4: Line 4:
Define two associative arrays, where one represents the following "base" data:
Define two associative arrays, where one represents the following "base" data:


{| class="wikitable"
::::: {| class="wikitable"
|+
|+
| '''Key''' || '''Value'''
| '''Key''' || '''Value'''
Line 17: Line 17:
And the other represents "update" data:
And the other represents "update" data:


{| class="wikitable"
::::: {| class="wikitable"
|+
|+
| '''Key''' || '''Value'''
| '''Key''' || '''Value'''
Line 30: Line 30:
Merge these into a new associative array that contains every key found in either of the source ones. Each key should map to the value in the second (update) table if that exists, or else to the value in the first (base) table. If possible, do this in a way that does not mutate the original two associative arrays. Obviously this should be done in a way that would work for any data, not just the specific data given here, but in this example the result should be:
Merge these into a new associative array that contains every key found in either of the source ones. Each key should map to the value in the second (update) table if that exists, or else to the value in the first (base) table. If possible, do this in a way that does not mutate the original two associative arrays. Obviously this should be done in a way that would work for any data, not just the specific data given here, but in this example the result should be:


{| class="wikitable"
::::: {| class="wikitable"
|+
|+
| '''Key''' || '''Value'''
| '''Key''' || '''Value'''
Line 42: Line 42:
| "year" || 1974
| "year" || 1974
|}
|}
<br><br>


=={{header|Factor}}==
=={{header|Factor}}==