In printing, quite often we need to rearrange data so it comes out in a different order than it arrives. Once it's been printed its set up on cutters and needs to come out in a stream order (it called north south splitting). I need to write a 4-way north south which is to divide the file into (4) sections, determine any leftovers (in this case, 3 records: 19/4=4.5, round down to 4. 4x4=16 R3); example below.
The data comes in in this order; 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
It needs to be rearranged so that when the records are printed and cut into 4 "ribbons" they are presented in this way:
1 6 11 16 Print direction
2 7 12 17 |
3 8 13 18 |
4 9 14 19 |
5 10 15 V
So, the natural order of the file needs to be rebuilt as as an output file in this order; 1,6,11,16,2,7,12,17,3,8,13,18.........
Does python have a reasonably efficient way of doing this outside of seeking to file points inside loops and counters? These files are quite large with record lengths in the hundreds, and record counts in the millions.