<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV id=yiv265606387>
<TABLE id=yiv265606387bodyDrftID class=yiv265606387 border=0 cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD style="FONT-FAMILY: arial; FONT-SIZE: 10pt" id=yiv265606387drftMsgContent>
<DIV>Hi JM and All,</DIV>
<DIV>Thank you all very much for your response and help. I managed to work out the problem eventually. But my code is ridiculously long compared to what you have just offered here. I think your code is elegant and should be much faster.  </DIV>
<DIV>Thanks  a lot</DIV>
<DIV>Sammy </DIV>
<DIV> </DIV>
<DIV>Below is my code. </DIV>
<DIV> </DIV>
<DIV> <SPAN>outputfile</SPAN> = codecs.open(csvfile3, 'wb')<BR> inputfile1 =  codecs.open(csvfile1, 'rb')<BR> inputfile2 = codecs.open(csvfile2, 'rb')<BR>             </DIV>
<DIV>                <BR>                 dictreader2 = csv.DictReader(inputfile2)<BR>                 dictreader1 = csv.DictReader(inputfile1)</DIV>
<DIV>                 mergedDict = {}<BR>                 <BR>                 mergedDictb = {}<BR>                 matchedlistA = []<BR>                 matchedlistB = []<BR>                 matchedlist = []<BR>                 cnt = 0<BR>                 cntb =
 0<BR>                 for dictline1 in dictreader1:<BR>                         cnt  += 1<BR>                         print cnt<BR>                         mergedDict = dictline1.copy()<BR>                         mergedDict['UniqID']= 
 cnt<BR>                          matchedlistA.append(mergedDict)<BR>                         <BR>                </DIV>
<DIV>                 for dictline2 in dictreader2:<BR>                          cntb  += 1<BR>                          mergedDictb = dictline2.copy()<BR>                          mergedDictb['UniqID']=  cntb<BR>                         
 matchedlistB.append(mergedDictb)<BR>                         <BR>               </DIV>
<DIV>                 for dictline1 in matchedlistA: <BR>                    for dictline2 in matchedlistB: <BR>                        if dictline1['UniqID'] == dictline2['UniqID']: <BR>                            entry = dictline1.copy() <BR>                           
 entry.update(dictline2)<BR>                            matchedlist.append(entry) </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><BR>--- On <B>Wed, 5/9/12, Jean-Michel Pichavant <I><jeanmichel@sequans.com></I></B> wrote:<BR></DIV>
<BLOCKQUOTE style="BORDER-LEFT: rgb(16,16,255) 2px solid; PADDING-LEFT: 5px; MARGIN-LEFT: 5px"><BR>From: Jean-Michel Pichavant <jeanmichel@sequans.com><BR>Subject: Re: Help with how to combine two csv files<BR>To: "Sammy Danso" <samdansobe@yahoo.com><BR>Cc: python-list@python.org<BR>Date: Wednesday, May 9, 2012, 11:23 AM<BR><BR>
<DIV class=yiv265606387plainMail>Sammy Danso wrote:<BR>> Hello Experts,<BR>> I am new to python and I have been trying to merge two csv files, and upon several hours of unsuccessful attempts, I have decided to seek for help.<BR>>  the format of the file is as follows. file A has  columns a, b, c and values 1,2,3 for several rows. File B also has columns d,e and values 4,5  for same number of rows as A. the files however do not have any unique column between the two.<BR>> I want an output file C to have columns  a,b,c,d,e with values 1,2,3,4,5<BR>>  I would be very grateful for your help with some code.<BR>>  Thanks very much,<BR>> Sammy<BR>> <BR>Post some code so we may point at your problem.<BR><BR>The solution is easy, the code very small.<BR>Something like (pseudo code):<BR><BR>import csv<BR>writer = csv.writer(file3)<BR>for index, row in
 enumerate(csv.reader(file1)):<BR>   writer.writerow(row + csv.reader(file2)[index])<BR><BR>JM<BR></DIV></BLOCKQUOTE></TD></TR></TBODY></TABLE></DIV></td></tr></table>