How to merge 2 dictionaries in Python

I have been disappearing for quite awhile due to work and other stuff. Recently, I have been looking heavily into Google App Engine (GAE) and Python. Hopefully, I will discover something interesting and is able to share them here.

Today I was creating a global template system in GAE and I found myself needing to merge 2 dictionaries together.

I thought it was gonna be something like merge or append functions but Stackoverflow points me to this interesting syntax.

a = { ‘one’ : ‘one’, ‘two’ : ‘two’}

b = {‘three’ : ‘three’}

c = dict(a, ** b) # merge a and b

I questioned myself about the syntax for awhile but I agreed to try it and it works perfectly.

Advertisements

One Response to How to merge 2 dictionaries in Python

  1. Deep says:

    thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: