views:

288

answers:

2
+5  A: 
basket = basket_one.copy()
basket.update(basket_two)

(if the original basket_one does not need to stay intact, you can leave out the copy)

sepp2k
+11  A: 

The "oneliner way", altering neither of the input dicts, is

basket = dict(basket_one, **basket_two)

In case of conflict, the items from basket_two will override the ones from basket_one. As one-liners go, this is pretty readable and transparent, and I have no compunction against using it any time a dict that's a mix of two others comes in handy (any reader who has trouble understanding it will in fact be very well served by the way this prompts him or hear towards learning about dict and the ** form;-). So, for example, uses like:

x = mungesomedict(dict(adict, **anotherdict))

are reasonably frequent occurrences in my code.

Alex Martelli
This is fairly common, a good idiom that everyone should know
gnibbler
Wow, that's a really interesting way of combining 2 dictionaries. It uses basic Python. I'm glad this answer has been sneaked in before the question has closed.
Thierry Lam