You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python does not support + and += on dict, but uses | and |= instead (since 3.9), updating values like with your option 1.
That being said, I would definitively not add a new kind of operator just for that. Therefore, I think using + and += is a viable option. Another option would be to use a method instead, like update (but with a verb that makes it clear it returns a copy and do not modify values in-place).
A third solution for collision would be to perform a recursive merge (lhs values are updated from rhs, but if both values are dict themselves, they are merged, and if both values are array, values from rhs are appended to lhs)
Like for arrays, I'd imagine that if you wrote something like:
that this would be equivalent to:
The only question that remains is what to do with key collisions. There are two possibilities that seem acceptable to me:
Equivalent python
The text was updated successfully, but these errors were encountered: