如何使用 ramdasequence
遍历字典?
给定以下字典
cars = {color: ['yellow', 'red'], year: [2017], model: ['coup', 'sedan']}
我想产生遍历的结果
all_cars = [
{color: 'yellow', year: 2017, model: 'coup'},
{color: 'yellow', year: 2017, model: 'sedan'},
{color: 'red', year: 2017, model: 'coup'},
{color: 'red', year: 2017, model: 'sedan'}
]
R.sequence
在空列表的列表中使用结果
R.sequence(R.of, cars)
[[]]
如果我遍历列表而不是字典,它会产生正确的笛卡尔积,但结果(当然)是列表而不是字典。
R.sequence(R.of, [['yellow', 'red'], [2017], ['coup', 'sedan']])
[["yellow", 2017, "coup"], ["yellow", 2017, "sedan"], ["red", 2017, "coup"], ["red", 2017, "sedan"]]