How can I merge two Python dictionaries in a single expression?

Answer

Say you have two dicts and you want to merge them into a new dict without altering the original dicts:

x ={'a':1,'b':2}
y ={'b':3,'c':4}

y will come second and its values will replace x's values, thus 'b' will point to 3 in our final result.

All python Questions

Ask your interview questions on python

Write Your comment or Questions if you want the answers on python from python Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---