我正在尝试编写一些代码来测试一堆输入参数的笛卡尔积。
我看过itertools
,但其product
功能不完全是我想要的。有没有一种简单明显的方法来获取具有任意数量键的字典and每个值中的任意数量的元素,然后生成具有下一个排列的字典?
Input:
options = {"number": [1,2,3], "color": ["orange","blue"] }
print list( my_product(options) )
输出示例:
[ {"number": 1, "color": "orange"},
{"number": 1, "color": "blue"},
{"number": 2, "color": "orange"},
{"number": 2, "color": "blue"},
{"number": 3, "color": "orange"},
{"number": 3, "color": "blue"}
]