Use Python list operations to get rid of a lot of FORTRANish for loops.