s=['Closure Type: Button', 'Fit: Regular', 'Neckline: Collar Neck',
'Sleeve Length: Long Sleeve', 'Sleeve Style: Cuffed Sleeve']
您好,我正在尝试将以上列表转换为一本词典
键对于我需要更改的所有字符串不是恒定的。
我试过了
data={{k:v} for i in s for k,v in i.split(': ')}
json.loads(s)
但我明白了
ValueError:太多值无法解包(预期2)
我的预期输出是:
data={'Closure Type':'Button','Fit':'Regular','Neckline':'Collar Neck',
'Sleeve Length':'Long Sleeve','Sleeve Style':'Cuffed Sleeve'}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句