dictionary of list from a file

sjdevnull at yahoo.com sjdevnull at yahoo.com
Thu Oct 5 14:14:34 CEST 2006


Peter Otten wrote:
> sjdevnull at yahoo.com wrote:
>
> > for line in (l.rstrip("\n") for l in file("test.txt", "rU") if l[0] !=
> > "\n"):
> > \001\001\001k,\001v\001=\001line.split()
> > \001\001\001d.setdefault(k,\001[]).append(v)
>
> Note that this snippet will produce the same output with or without the
> rstrip() method call.

Wow. That's not at all what I expected.  I would've thought I'd see:
>>> " 1".split()
['', '1']




More information about the Python-list mailing list