How can I modify/merge Jinja2 dictionaries?

Sounds like the Jinja2 "do" statement extension may help. Enabling this extension would allow you to rewrite:

{{ x.update({4:5}) }} {{ x }} 

as

{% do x.update({4:5}) %} {{ x }}

Example:

>>> import jinja2
>>> e = jinja2.Environment(extensions=["jinja2.ext.do",])
>>> e.from_string("{% do x.update({4:5}) %} {{ x }}").render({'x':{1:2,2:3}})
u' {1: 2, 2: 3, 4: 5}'
>>> 

I added a filter to merge dictionaries, namely:

>>> def add_to_dict(x,y): return dict(x, **y)
>>> e.filters['add_to_dict'] = add_to_dict
>>> e.from_string("{{ x|add_to_dict({4:5}) }}").render({'x':{1:2,2:3}})
u'{1: 2, 2: 3, 4: 5}'

I found another solution without any extension.

{% set _dummy = x.update({4:5}) %}

It makes x updated. Don't use _dummy.