Help "joining" two files delimited with pipe character ("|")

Ian Kelly ian.g.kelly at gmail.com
Wed Dec 5 13:18:56 EST 2012


On Wed, Dec 5, 2012 at 10:57 AM, Daniel Doo <dd at topekacapitalmarkets.com> wrote:
> I am new to Python.  Is there a method to “join” two pipe delimited files
> using a unique key that appears in both files?  I would like to implement
> something similar to the Unix join command.

If the files are small enough to fit in virtual memory, load one of
the files into a dict where the key is the join field and the value is
the full line.  Then iterate over the other file one line at a time,
checking to see if the join field is in the dict.  If it is, output
the joined line.  Otherwise, skip it.



More information about the Python-list mailing list