Writing dictionary to file

Dan Schmidt dfan at harmonixmusic.com
Fri Sep 8 09:52:30 EDT 2000


Stephen Kloder <stephenk at cc.gatech.edu> writes:

| To write dictionary dict to file f:
| 
| from string import join
| f.write(join(map(lambda x:"%s %s"%x,dict.items()),'\n'))

Or, in Python 2.0,

  f.write(join([("%s %s" % x) for x in dict.items()],'\n'))

Yours for list comprehensions,
Dan

-- 
                 Dan Schmidt | http://www.dfan.org
Honest Bob CD now available! | http://www.dfan.org/honestbob/cd.html



More information about the Python-list mailing list