[Tutor] week 10 synthesizing assignment

Ben Finney ben+python at benfinney.id.au
Sat Apr 2 04:06:45 EDT 2016


Daniella Sapozhnikova <daniellasapo at gmail.com> writes:

> 1) If I wanted to combine two dictionaries into one, how would I go
> about doing so?

How to do it depends on what policy you want to adopt for duplicate
keys:

* Existing item stays?

* New item overrides existing item?

* Something else happens?

> (the .update method?)

The ‘dict.update’ method is good, yes. It requires that you be explicit
about which items you are updating in the existing dictionary.


> 2) How can I make that combined dictionary have inner dictionaries
> with the inner values from the previous separate dictionaries?

That will be easier to talk about if you give some sample inputs and the
expected output from the operation.

-- 
 \      “I find the whole business of religion profoundly interesting. |
  `\     But it does mystify me that otherwise intelligent people take |
_o__)                                    it seriously.” —Douglas Adams |
Ben Finney



More information about the Tutor mailing list