[Tutor] merging 2 files.

nitin chandra nitinchandra1 at gmail.com
Thu Feb 24 17:43:16 CET 2011


On Thu, Feb 24, 2011 at 9:18 PM, nitin chandra <nitinchandra1 at gmail.com> wrote:
> Hi Martin,
>
> Thanks a lot. It did work, but I am trying to break it down and  understand
>
>>  import csv
>>
>>  # -- build the lookup table
>>  #
>>  lookup = dict()
>>  file0 = csv.reader(open('jhun.csv','r'))
>>  for row in file0:
>>      lookup[ row[0] ] = row
>>
>>  # -- now, read through the
>>  #
>>  file1 = csv.reader(open('test.csv','r'))
>>  for row in file1:
>
> modified it to
>
> for row1 in file1:
>
>>      exists = lookup.get( row[0], None )
>
>     exists = lookup.get(row1[0], None)
>
>>      if exists:
>>          print row, exists  # -- print out only what you want
>>      else:
>>          pass  # -- do you need to do something if no lookup entry?
>>
>
> but some how It is reading "test.csv" from row 8000+ onwards not from
> 1st row. Dunno if it doing the same thing with jhun.csv. screen
> scrolls by.
>
>>
>>  : I am in need of the solution as client breathing down my neck.
>>
>> They always do.  Wear a scarf.
>>
>> -Martin
>>
> I shall try a fire proof scarf ... thanks :)
>
> Nitin
>


More information about the Tutor mailing list