>> b = { "c" : 3, "d" : 4 }>>> a {'a': 1, 'b': 2}>...">
Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

Python “extend” for a dictionary

Asked by Rutuja Mishra Apr 9, 2021 1.5K views 1 answer
Share

About this question

Which is the best way to extend a dictionary with another one? For instance:

>>> a = { "a" : 1, "b" : 2 }
>>> b = { "c" : 3, "d" : 4 }
>>> a 
{'a': 1, 'b': 2}
>>> b 
{'c': 3, 'd': 4}
I'm looking for an operation to obtain this avoiding for loop:
{ "a" : 1, "b" : 2, "c" : 3, "d" : 4 }
I wish to do something like:
a.extend(b) # This does not work

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.