T
T
try1002017-03-26 11:35:47
Python
try100, 2017-03-26 11:35:47

How to write multiple lists into one csv in Python?

Greetings friends! I read the documentation, but I confess, I can’t figure out how to combine and write three lists into one csv, so that each list is in a separate column. (I can write down one list)
Yes:
title = list 1
url = list 2
img = list 3

def save():
  with open('D:\spisok.csv', 'w', newline='') as file:
    csv_writer = csv.writer(file)
    for item in title:
     	csv_writer.writerow([item])

This piece of code beautifully writes the first list into a column, but how do you add the other two lists to the file in adjacent columns?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Grinevich, 2017-03-26
@Derfirm

I haven't checked the correctness of the code, but I assume so

RESULTS = [title, url, img]
csv_writer.writerows(RESULTS)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question