我正在尝试将字符串转换为字典。示例:
Milk, Cheese, Bottle
程序会将其转换为字典。
{"Milk":"NULL", "Cheese":"NULL", "Bottle":"NULL"}
我该怎么做?
请您参考如下方法:
>>> string = 'Milk, Cheese, Bottle'
>>> dict((key, None) for key in string.split(', '))
{'Cheese': None, 'Milk': None, 'Bottle': None}
