import re
import io
text = '''
test login_id: userid
authority: root folder: root123
login password: 1234***
'''.lstrip()
data = []
for l in io.StringIO(text):
data += [{k: v} for k, v in re.findall(r'\s*(.+?):\s+([^\s]+)', l)]
print(data)
# [{'test login_id': 'userid'}, {'authority': 'root'}, {'folder': 'root123'}, {'login password': '1234***'}]
metropolis
- 6,705
- 2
- 6
- 16