Consider these dictionaries:
{% set dict1 = { 'a':'b', 'c':'d' } %}
{% set dict2 = { 'e':'f' } %}
How to merge them into one dictionary?
Tried these with no positive results:
{{dict1 + dict2}}
{{dict1 ~ dict2}}
Consider these dictionaries:
{% set dict1 = { 'a':'b', 'c':'d' } %}
{% set dict2 = { 'e':'f' } %}
How to merge them into one dictionary?
Tried these with no positive results:
{{dict1 + dict2}}
{{dict1 ~ dict2}}
{{ dict(dict1, **dict2) }}
Obviously
I can sort of imagine the dict(dict1, dict2) but not the **… which genius(?uh) came up with this next to all other methods to add things
Probably this is TOO genius for understanding)))
Thanks a lot!
It’s a Python thing. dict()
takes a dictionary and keyword arguments to add, like this:
{{ dict(dict1, e='f') }}
The **
effectively expands the second dictionary into keywords.
Kind of a constructor which creates a new object using data from other objects…
… no further comment but: thanks!