limodou wrote: > here is my program > > d = {} > for line in file('test.txt'): > line = line.strip() > if line: > k, v = line.strip().split() > d.setdefault(k, []).append(v) > print d
Minor nits: you call strip twice, when you don't need to. just omit the second call. Also, I'm not sure stripping the line is the right thing per the spec; d = {} for line in [l[:-1] for l in file('test.txt', 'rU') if len(l)>1]: k,v = line.split() d.setdefault(k,[]).append(v) -- http://mail.python.org/mailman/listinfo/python-list