I am running in a loop and and parsing a string. That string ultimately contains 2 items a host and application running on a host. As expected a host runs multiple applications. I'd like to store it all in one data structure where host is used as a key.
Below is my failed attempt. Please help me understand why only the last element is being saved in the host = app format.
What i expect to see
host = app1, app2 etc
What i see
Host = app2 (always last)
data = dict()
def add(line):
l = line.split("/")
host = l[0].strip()
app = l[-1].strip()
data[host].append(app)
for entry in env:
if "/" not in entry: continue
add(entry)
print data