"Kent Johnson" <[email protected]> wrote in message news:[email protected]... On Tue, Jun 23, 2009 at 1:08 AM, Mark Tolonen<[email protected]> wrote:

import csv

dyc = {
'a50' : ['textfield', 50, 40],
'k77' : ['othertext', 60, 10]
}

myfile = open('csv-test.csv', 'w')
mywriter = csv.writer(myfile, dialect='excel')

for k,[a,b,c] in dyc.items():
mywriter.writerow([k,a,b,c])

I think I would write this as
for k, v in dyc.items(): # or iteritems()
 mywriter.writerow([k] + v)

That way it doesn't depend on the actual size of the value list.

I knew there was a more straightforward way, it just wouldn't come to me at 1am. ;^)

-Mark


_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to