title: write key and values in csv file using for loop -- python
body: <p>I am new to python, please help me resolve this.</p>
  
  <p>My code looks like:</p>
  
  <pre><code>if div == 0 or div == 1 or div == 2:
       print (' A ', 'sometext')
  
  elif div == 5 or div == 6:
       print (' B ', 'some')
  
  elif div == 3 or div == 4:
       print (' C ', 'text')
  </code></pre>
  
  <p>I want to insert data into csv instead of printing </p>
  
  <p>like this:</p>
  
  <pre><code>A,B,C
  sometext,some,text
  xhbasj,bjascn,bashc
  bhhashc,bashjc,bcsahbch
  cvashcj,bcashc,bcasc
  </code></pre>
  
  <p>here A,B,C will be like keys.</p>
  
  <p>I have tried many options but none of them working, please help me resolve this</p>
  
  <p>I have tried this</p>
  
  <pre><code>with open('trashData.csv', 'w', newline='') as fp:
      a = csv.writer(fp, delimiter=',')
      if div == 0 or div == 1 or div == 2:
         data = [['A'],['sometext']]
         a.writerows(data)
  </code></pre>