title: How to write csv file row by row in python?
body: <p>I want to write a csv file <code>userperday.csv</code> row by row with a loop. I have a list <code>dates</code> with dates and I want to check if they are in the second list <code>dates2</code>. I tried with the code below</p>
  
  <pre><code>with open('userperday.csv', "w") as f:
      writer = csv.writer(f)
      for j in dates:
          n=0
          if j in dates2:
              n+=1
          rows=zip(j, n)
          for row in rows:
                  writer.writerow(row)
  </code></pre>
  
  <p>My expected output is a csv file with two columns and in the first columns there a the dates from the list <code>dates</code> and in the second column should be a 1 or a 0, so if the particular date is in <code>dates2</code>or not. In addition I wisch to have a header.</p>