If you are using Python-3.6 +, the pythonic way uses f-lines, otherwise - understanding the dictionary:
In [147]: x = 'TEST'
In [148]: d = {
...: 'hello': f'world{x}',
...: 'foo': f'bar{x}'
...: }
In [149]: d
Out[149]: {'foo': 'barTEST', 'hello': 'worldTEST'}
In python <3.6:
d = {
'hello': f'world{var}',
'foo': f'bar{var}'
}
{k: val.format(var=x) for k, val in d.items()}
source
share