[Tutor] how to join two different files

Rich Lovely roadierich at googlemail.com
Sat Jul 18 08:59:29 CEST 2009

2009/7/18  <amrita at iisermohali.ac.in>:
> Thankyou sir it is working.....but one more thing i want to ask that if my
> file will have entries like:---
> fileA and fileB
> 12         10
> 13         12
> 14
> 15
> means if their no. of entries will not match then how to combine them(both
> input files have more than one column).
> Thanks,
> Amrita
> Amrita Kumari
> Research Fellow
> IISER Mohali
> Chandigarh
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

That depends entirely on what you want to happen when you encounter a
row that doesn't have an entry in one of the files.  The previous
code, using izip(), will stop at the end of the shortest file.  If you
want to pad the short file, (i.e. add values to make it the same
length as the longer file) you can use itertools.izip_longest().  Look
it up in the docs for usage.

Rich "Roadie Rich" Lovely
There are 10 types of people in the world: those who know binary,
those who do not, and those who are off by one.

More information about the Tutor mailing list