Python重组字典

Vor*_*Sci 1 python dictionary tuples

我在 Python 中有以下 dict

{1500: 2, 1400: 1, 700: 10}
Run Code Online (Sandbox Code Playgroud)

我很难把它变成以下内容:

[{"x": 1500, "y": 2}, {"x": 1400, "y": 1}, {"x": 700, "y": 10}]
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?是否有一些列表理解?

Stu*_*art 7

就在这里。

[{"x": k, "y": v} for k, v in my_dict.items()]
Run Code Online (Sandbox Code Playgroud)