【发布时间】:2020-07-10 14:56:23
【问题描述】:
我正在尝试编写函数,该函数将为我提供基于预定义字典的给定字符串的所有可能组合。假设示例:
dict = {'a':'á', 'a':'ä', 'y':'ý'}
string = "antony"
word_combination(string, dict) #desired function
预期结果应该是:
["antony", "ántony", "äntony", "ántoný", "äntoný", "antoný"]
即我们根据定义的 dictionary 创建了定义的 string 的所有可能组合进行替换。 请问有什么建议/提示吗?
【问题讨论】:
-
你的字典无效,字典不能有重复的键。
标签: python string dictionary combinations