DEV Community

Discussion on: Updating a dict in python

Collapse
 
rhymes profile image
rhymes • Edited

The only drawback of this is that update does not return anything so you can't use it in an expression.

There's an alternative in Python 3.5+:

c = {**a, **b}

this way you can merge dictionary a with b (or an in-line dict). c is the result, a and b remain unchanged.

Collapse
 
mxl profile image
Maria Boldyreva

Thanks Rhymes!