python - Write csv with each list as column -


i have dictionary holds 2 level nested list each key looks following:

ordereddict([(0,[['a','b','c','d'],['e','f','g','h']]), (1,[['i','j','k','l'],['m','n','o','p']])]) 

i write each nested list csv column:

a,b,c,d      e,f,g,h i,j,k,l      m,n,o,p 

the output getting current code is:

['a','b','c','d']      ['e','f','g','h'] ['i','j','k','l']      ['m','n','o','p'] 

the columns correct remove brackets [ ] , quotes ' '

a,b,c,d      e,f,g,h i,j,k,l      m,n,o,p 

code:

with open('test.csv', 'w', newline='') csv_file:     writer = csv.writer(csv_file, quotechar='"', quoting=csv.quote_all)     record in my_dict.values():         writer.writerow(record) 

any appreciated!

this should work:

with open('test.csv', 'w', newline='') csv_file:     writer = csv.writer(csv_file, quotechar='"', quoting=csv.quote_all)     record in my_dict.values():         final = [",".join(index) index in record]         writer.writerow(final) 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -