Вопрос по list, python – Python, транспонирование списка и запись в файл CSV

13

Error: User Rate Limit Exceeded

 lol = [[1,2,3],[4,5,6]]

Error: User Rate Limit Exceeded

1 4
2 5
3 6

Error: User Rate Limit Exceeded

file = open("test.csv", "wb")
fileWriter = csv.writer(file , delimiter='\n',quotechar='|', quoting=csv.QUOTE_MINIMAL)
spamWriter.writerow([1,2,3])
spamWriter = csv.writer(file , delimiter=',',quotechar='|', quoting=csv.QUOTE_MINIMAL)
spamWriter.writerow([4,5,6])
file.close()

Error: User Rate Limit Exceeded

 1
 2
 3
 4 5 6

Error: User Rate Limit Exceeded

 1 4 
 2 5
 3 6

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Ваш Ответ

3   ответа
8

Error: User Rate Limit Exceededzip()

>>> zip(*lol)
[(1, 4), (2, 5), (3, 6)]

Error: User Rate Limit Exceededcsw.writerError: User Rate Limit Exceeded

with open("test.csv", "wb") as f:
    fileWriter = csv.writer(f, delimiter=',',quotechar='|', quoting=csv.QUOTE_MINIMAL)
    for row in zip(*lol):
        fileWriter.writerow(row)

Error: User Rate Limit Exceeded

$ cat test.csv 
1,4
2,5
3,6
пишет с символом [и]
13

Error: User Rate Limit Exceeded

import csv

lol = [[1,2,3],[4,5,6],[7,8,9]]
item_length = len(lol[0])

with open('test.csv', 'wb') as test_file:
  file_writer = csv.writer(test_file)
  for i in range(item_length):
    file_writer.writerow([x[i] for x in lol])

Error: User Rate Limit Exceeded

1,4,7
2,5,8
3,6,9
2

csvwriterows

data=[("test", "value1", "value2"), ("test2", "value3", "value4")]
with open('my.csv','wt') as out:
   csv_out=csv.writer(out)
   csv_out.writerows(data)

lol = [[1,2,3],[4,5,6]]
data = zip(lol[0],lol[1])

Похожие вопросы