【发布时间】:2011-04-21 21:07:23
【问题描述】:
我有以下传入值:
variants = {
"debug" : ["on", "off"],
"locale" : ["de_DE", "en_US", "fr_FR"],
...
}
我想处理它们,所以我得到以下结果:
combinations = [
[{"debug":"on"},{"locale":"de_DE"}],
[{"debug":"on"},{"locale":"en_US"}],
[{"debug":"on"},{"locale":"fr_FR"}],
[{"debug":"off"},{"locale":"de_DE"}],
[{"debug":"off"},{"locale":"en_US"}],
[{"debug":"off"},{"locale":"fr_FR"}]
]
这应该适用于字典中任意长度的键。在 Python 中使用 itertools,但没有找到任何符合这些要求的东西。
【问题讨论】:
-
你确定你不想有一个二元素字典的列表吗?
标签: python algorithm list dictionary combinations