更改python键的类型

use*_*074 1 python dictionary

有没有一种简单的方法可以在 python 中将键从字符串更改为元组?例如:

dict = {'100,2': 0.3, "2,5" = 0.5}
Run Code Online (Sandbox Code Playgroud)

Raf*_*afG 5

像这样的东西?

>>> d = {'100,2': 0.3, "2,5": 0.5}
>>> d = {tuple(k.split(',')): v for k, v in d.items()}
>>> d
{('100', '2'): 0.3, ('2', '5'): 0.5}
Run Code Online (Sandbox Code Playgroud)