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

Ian Kelly ian.g.kelly at
Wed Dec 5 19:18:56 CET 2012

On Wed, Dec 5, 2012 at 10:57 AM, Daniel Doo <dd at> 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