LeetCode-1807 替换字符串中的括号内容题目链接:1807. 替换字符串中的括号内容 - 力扣(LeetCode) 12345678910111213141516class Solution(object): def evaluate(self, s, knowledge): """ :type s: str :type knowledge: List[List[str]] :rtype: str """ dict_know = {k:v for k,v in knowledge} # 将二维列表转换为字典 new_s = s.replace('(','$').replace(')', '$') # 转换成便于处理的新格式 tokens = new_s.split('$') for i in range(1, len(tokens), 2): key = tokens[i] tokens[i] = dict_know.get(key, "?") return "".join(tokens)