title: Avoiding off-by-one errors when removing columns based on indices in a python list
body: <p>I have a target file called <code>TARGFILE</code> of the form:</p>
  
  <pre><code>10001000020002002001100100200000111
  10201001020000120210101100110010011
  02010010200000011100012021001012021
  00102000012001202100101202100111010
  </code></pre>
  
  <p>My idea here was to leave this as a string, and use slicing in python to remove the indices.</p>
  
  <p>The removal will occur based on a list of integers called <code>INDICES</code> like so:</p>
  
  <pre><code>[1, 115654, 115655, 115656, 2, 4, 134765, 134766, 18, 20, 21, 23, 24, 17659, 92573, 30, 32, 88932, 33, 35, 37, 110463, 38, 18282, 46, 18458, 48, 51, 54]
  </code></pre>
  
  <p>I want to remove every position of <em>every</em> line in <code>TARGFILE</code> that matches with <code>INDICES</code>. For instance, the first digit in <code>INDICES</code> is 1, so the first column of <code>TARGFILE</code> containing 1,1,0,0 would be removed. However, I am weary of doing this incorrectly due to off-by-one errors and changing index positions if everything is not removed at the same time.</p>
  
  <p>Thus, a solution that removed every column from each row at the same time would likely be both much faster and safer than using a nested loop, but I am unsure of how to code this.</p>
  
  <p>My code so far is here: </p>
  
  <pre><code>#!/usr/bin/env python
  import fileinput
  SRC_FILES=open('YCP.txt', 'r')
  
  for line in SRC_FILES:
      EUR_YRI_ADM=line.strip('\n')
      EUR,YRI,ADM=EUR_YRI_ADM.split(' ')
      ADMFO=open(ADM, 'r')
      lines=ADMFO.readlines()
      INDICES=[int(val) for val in lines[0].split()]
      TARGFILE=open(EUR, 'r')
  </code></pre>
  
  <p>It seems to me that a solution using <code>enumerate</code> might be possible, but I have not found it, and that might be suboptimal in the first place...</p>
  
  <p>EDIT: in response to concerns about memory: the longest lines are ~180,000 items, but I should be able to get this into memory without a problem, I have access to a cluster.</p>