title: Python list comprehension, can it be used for reading multiple files?
body: <p>Here is my script so far: </p>
  
  <pre><code>#!/usr/bin/env python
  import fileinput
  from optparse import OptionParser
  
  op = OptionParser()
  (options, files) = op.parse_args()
  print options
  print files
  content = []
  for line in fileinput.input(files):
      # print "reading from " + fileinput.filename()
      if (fileinput.isfirstline()):
          content.append([])
          # print "is reading from the first line"
      content[-1].append(line.rstrip())
  </code></pre>
  
  <p>As you can see I am reading all lines in all files and constructing a structure like this</p>
  
  <pre><code>[["contents", "file 1"], ["file 2; is one line"], ["file 3", "has", "3 lines in it"]]
  </code></pre>
  
  <p>As far as I can tell the <code>fileinput</code> does not let me split up based on lines and so I have resorted to calling <code>isfirstline()</code> on each line to see if I have progressed to the next file. </p>
  
  <p>Is it the case that I cannot use list comprehensions to do this work elegantly? Since I seem to be limited to a single loop over all lines. Is there something smart I can do to get it to give me the files separated? </p>