我正在尝试完成这样的事情:
models = {k1: v, k2:v}
grid = {k1: w, k2:w, k3:w}
grid_of_params = {grid.items() if grid.keys() in models for k,v in grid.items()}
print(grid_of_params)
Output: {k1: w, k2:w}
换句话说,grid如果 dict 中存在键,则 dict 理解返回 dict 的项目models。
如何更正此语法?
PIPIONE
相关分类