我在将文件内容转换为词典列表时遇到麻烦,您能否提供建议?python:读取文件并将其分割成词典列表
File content:
host1.example.com#192.168.0.1#web server
host2.example.com#192.168.0.5#dns server
host3.example.com#192.168.0.7#web server
host4.example.com#192.168.0.9#application server
host5.example.com#192.168.0.10#database server
该文件夹中有多个文件格式相同。最后,我想收到以下格式的字典列表:
[ {'dns': 'host1.example.com', 'ip': '192.168.0.1', 'description': 'web_server'},
{'dns': 'host2.example.com', 'ip': '192.168.0.5', 'description': 'dns server'},
{'dns': 'host3.example.com', 'ip': '192.168.0.7', 'description': 'web server'},
{'dns': 'host4.example.com', 'ip': '192.168.0.9', 'description': 'application server'},
{'dns': 'host5.example.com', 'ip': '192.168.0.10', 'description': 'database server'} ]
提前致谢!
+1了详细的解释。 –
其实,你的答案就是我会亲自做的,但不幸的是,列表比赛混淆了大多数人。 +1给你。 –