Convert list of strings to dictionary

前端 未结 7 932
深忆病人
深忆病人 2020-12-01 22:08

I have a list

[\'Tests run: 1\', \' Failures: 0\', \' Errors: 0\']

I would like to convert it to a dictionary as

{\'Tests r         


        
7条回答
  •  感动是毒
    2020-12-01 22:34

    >>> s = ['Tests run: 1', ' Failures: 0', ' Errors: 0']
    >>> {i.split(":")[0].strip():int(i.split(":")[1].strip()) for i in s}
    {' Failures': 0, 'Tests run': 1, ' Errors': 0}
    

提交回复
热议问题