小编Seb*_*ner的帖子

使用Python从字典中组合列表值的组合

我有以下传入价值:

variants = {
  "debug" : ["on", "off"],
  "locale" : ["de_DE", "en_US", "fr_FR"],
  ...
}
Run Code Online (Sandbox Code Playgroud)

我想处理它们,所以我得到以下结果:

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"}]
]
Run Code Online (Sandbox Code Playgroud)

这应该适用于字典中任意长度的键.在Python中使用itertools,但没有找到符合这些要求的任何内容.

python algorithm combinations dictionary list

24
推荐指数
2
解决办法
5276
查看次数

标签 统计

algorithm ×1

combinations ×1

dictionary ×1

list ×1

python ×1