Given:
$ cat file1
This is a source first line
This is a source second line
This is a source third line
$ cat file2
This is a transformed line 1
This is a transformed line 2
This is a transformed line 3
You can do:
from itertools import izip_longest
with open(fn1) as f1, open(fn2) as f2:
print '\n'.join(['{}: {}\t{}'.format(i,l1.strip(),l2.strip()) for i,(l1,l2) in enumerate(izip_longest(f1,f2),1)])
Prints:
1: This is a source first line This is a transformed line 1
2: This is a source second line This is a transformed line 2
3: This is a source third line This is a transformed line 3
Now suppose you have:
$ cat file1
This is a source first line
This is a source second line
This is a source third line
$ cat file2
This is a transformed line 1
This is a transformed line 2
This is a transformed line 3
This is line 4
You need to make the output true columns (by using {:40} to set a 40 character column value) and use a fillvalue for izip_longest:
with open(fn1) as f1, open(fn2) as f2:
print '\n'.join(['{}: {:40}{:40}'.format(i,l1.strip(),l2.strip()) for i,(l1,l2) in enumerate(izip_longest(f1,f2,fillvalue=""),1)])
Prints:
1: This is a source first line This is a transformed line 1
2: This is a source second line This is a transformed line 2
3: This is a source third line This is a transformed line 3
4: This is line 4
zip_longestis your friend