【发布时间】:2018-08-10 04:28:49
【问题描述】:
我有一本像这样的字典:
d = {
'hello': 'world{x}',
'foo': 'bar{x}'
}
在字典中的所有值上运行format 的pythonic 方式是什么?例如x = 'TEST' 的最终结果应该是:
{
'hello': 'worldTEST',
'foo': 'barTEST'
}
注意:我正在从另一个模块加载 d,因此无法使用 f 字符串。
【问题讨论】:
标签: python python-3.x dictionary formatting