http://paste.pocoo.org/show/234632/
The error's in there and I explain what my thoughts are. Extra information: There is definitely enough RAM. I watched the RAM go down as the program ran (lol), but there was still 2.3GB of RAM before the program crashed, giving the MemoryError.
Here is an example of what the input file is like; it's not exactly like this, and there are occasions where lines beside the first line aren't the length of the "first line being read," but the length check should take care of that.