【发布时间】:2017-07-20 17:47:06
【问题描述】:
我有一个字符串列表如下:
e = ['Website: Alabama Office of the Attorney General',
'Toll Free: 1-800-392-5658',
'Website: State Banking Department',
'Toll Free: 1-866-465-2279',
'Website: Department of Insurance',
'Phone Number: 334-241-4141',
'Website: Securities Commission',
'Phone Number: 334-242-2984',
'Website: Public Service Commission',
'Toll Free: 1-800-392-8050']
我想通过在“:”处拆分字符串来形成字典,并形成列表中每两个元素的字典,例如:
e = [{'Website': 'Alabama Office of the Attorney General',
'Toll Free': '1-800-392-5658'},
{'Website': 'State Banking Department',
'Toll Free': '1-866-465-2279'},
{'Website': 'Department of Insurance',
'Phone Number': '334-241-4141'},
{'Website': 'Securities Commission',
'Phone Number': 334-242-2984'},
{'Website': 'Public Service Commission',
'Toll Free': '1-800-392-8050'}]
感谢您一如既往的帮助。
【问题讨论】:
-
为什么要它在列表中?
-
请向我们展示您迄今为止为解决问题所做的尝试。你在哪里卡住了?
-
Stack Overflow 不是代码编写服务,请查看How to Ask 并向我们展示您的尝试。
-
您能否详细说明列表的格式是如何工作的?
-
对不起,@TemporalWolf 和大家,下次我会更加小心。我就是想不出办法。
标签: python list dictionary