sim*_*sim 4 python dictionary list web-scraping
我有一个字符串列表.我想转换成字典.我在抓取数据后得到了输出.
['Name:Dr. Mak', 'Location: India, Delhi']
['Name:Dr. Hus MD', 'Location:US, NY']
Run Code Online (Sandbox Code Playgroud)
我想要输出如下
{'Name':'Dr. Mak', 'Location': 'India, Delhi'}
{'Name':'Dr. Hus MD', 'Location':'US, NY'}
Run Code Online (Sandbox Code Playgroud)
FHT*_*ell 10
dict(s.split(':') for s in list_of_strings)
Run Code Online (Sandbox Code Playgroud)
编辑:删除空格
dict(map(str.strip, s.split(':')) for s in list_of_strings)
Run Code Online (Sandbox Code Playgroud)