Merging pre-sorted files without reading everything into memory
<p>I have a list of log files, where each line in each file has a timestamp and the lines are pre-sorted ascending within each file. The different files can have overlapping time ranges, and my goal is to blend them together into one large file, sorted by timestamp. There can be ties in the sorting, in which case I want to next line to come from whatever file is listed first in my input list.</p>

<p>I've seen examples of how to do this using <code>fileinput</code> (see <a href="http://stackoverflow.com/questions/6653371/merging-and-sorting-log-files-in-python">here</a>), but this seems to read all the files into memory. Owing to the large size of my files this will be a problem. Because my files are pre-sorted, it seems there should be a way to merge them using a method that only has to consider the most recent unexplored line from each file. </p>
