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

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

On Wed, Dec 5, 2012 at 11:18 AM, Ian Kelly <ian.g.kelly at> wrote:
> 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.

Note that this assumes that the join fields are unique.  If they're
not, then you would need to store lists of lines rather than single
lines in the dict.

More information about the Python-list mailing list