希望我在标题中已经解释得足够好,但这是我所拥有的:
输入数据:
Mushroom Kingdom, Mario
Hyrule, Link
Mushroom Kingdom, Bowser
Zebes, Samus
Zebes, Metroid
我想运行这样的东西,
# The next three lines establish that I'll be reading proc as a file
import subprocess
cmd = 'external command that returns the above data'
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
homeworlds = {}
while True:
line = proc.stdout.readline().split(',')
if line:
# If line isn't empty
homeword = line[0]
person = line[1]
homeworlds[homeword] = list.append[person] # Good logic? Bad syntax?
else:
break
目标是我将能够调用:
print homeworlds['Mushroom Kingdom']
并返回列表
Mario, Bowser