擅长:python、mysql、java
<pre><code>lines = """
game_name: Adventure 1
game_goal: Find the magic helmet and bring it to Hans.
game_goalloc: 8
game_goalobj: helmet
game_start: 4
game_xsize: 3
game_ysize: 3
""".strip().splitlines()
game_dict = {}
for line in lines:
line = line.strip()
if "game_" in line:
game = line.split('_')[-1]
k = game.split(':')[0].strip()
v = game.split(':')[-1].strip()
print(k)
print(v)
game_dict[k] = {}
game_dict[k] = v
print(game_dict)
</code></pre>
<p>也许这就是你想要的</p>