title: How to parse of a simple csv file?
body: <p>I have a simple CSV-file like this:</p>
  
  <pre><code>,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
  ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
  Note ,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32
  1,,,,,X,,,,,,,,X,,,,,,,,X,,,,,,,,X,,,
  2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
  3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
  4,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
  5,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
  </code></pre>
  
  <p>I need to parse it into a 2D array containing <strong><code>1</code></strong>-s where X are and <strong><code>0</code></strong> otherwise, ignoring the headers/extra rows.</p>
  
  <p>After reading the docs on the <strong><code>csv</code></strong> module I wrote a simple script like so:</p>
  
  <pre><code>import csv
  
  csvfile = open('input.csv', 'rb')
  reader = csv.reader(csvfile,dialect='excel', delimiter=' ', quotechar='|')
  
  data = []
  
  rowCount = 0
  for row in reader:
      if(rowCount &gt; 2): #skip first 3 rows (2 empty and 1 label)
          dataRow = []
          for i in xrange(1,len(row[0])):#skip 1st label column
              dataRow.append(1 if row[0][i] == 'X' else 0) #append 1s for X, 0s otherwise
          data.append(dataRow)
      rowCount += 1
  
  print data
  </code></pre>
  
  <p>This gives me the expected output:</p>
  
  <pre><code>[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
  </code></pre>
  
  <p>for </p>
  
  <pre><code>,,,,,X,,,,,,,,X,,,,,,,,X,,,,,,,,X,,,
  </code></pre>
  
  <p>The ternary condition could be written as <code>ord(row[0][i])/88</code>, but would it be possible to map the each string row to an integer row of ones and zeros?</p>
  
  <p><strong>Is there's a more 'pythonic' way of writing this ?</strong></p>