Hopefully I’ve explained it well enough in the title but here is what I have:
Input data:
Mushroom Kingdom, Mario
Hyrule, Link
Mushroom Kingdom, Bowser
Zebes, Samus
Zebes, Metroid
And I want to run something like this,
# 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
The goal is that I’ll be able to call:
print homeworlds['Mushroom Kingdom']
and return the list
Mario, Bowser
1 Answer