joining two column

James Mills prologic at shortcircuit.net.au
Fri May 14 13:55:38 EDT 2010


On Sat, May 15, 2010 at 3:22 AM, mannu jha <mannu_0523 at rediffmail.com> wrote:
> Hi,
>
> I have two different file
>
> file1:
>
> a1 a2
> a3 a4
> a5 a6
> a7 a8
>
> file2:
>
> b1 b2
> b3 b4
> b5 b6
> b7 b8
>
> and I want to join them so the output should look like this:
>
> a1 a2 b1 b2
> a3 a4 b3 b4
> a5 a6 b5 b6
> a7 a8 b7 b8
>
> how to do that?

This is completely untested, but this "should" (tm) work:

from itertools import chain

input1 = open("input1.txt", "r").readlines()
input2 = open("input2.txt", "r").readlines()
open("output.txt", "w").write("".join(chain(input1, input2)))

cheers
James



More information about the Python-list mailing list