<分区>
我对正则表达式的理解很糟糕,我需要帮助进行一些替换。我搜索过类似的问题,但它们与我的问题有一点不同。
基本上我有一个可用参数的字典,如下所示:
available_params = {'item1': 'dog', 'item2': 'cat', 'item3': 'horse'}
我收到这样的字符串:
str = 'The {item3} and the {item2} kicked the {item1}.'
我只想用相应的字典值替换花括号值来得到这个:
The horse and the cat kicked the dog.
看起来这应该很容易,但我不确定最好的方法是什么。
如有任何帮助,我们将不胜感激。