Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34308

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

References <08080305078A3F47B751F7412214A051011B096BF3@MBX22.exg5.exghost.com> <CALwzid=+vUEM1xRXAi2Oxus9D5v2B+5XAf6pMhyqCmJejm0oVw@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-12-05 11:22 -0700
Subject Re: Help "joining" two files delimited with pipe character ("|")
Newsgroups comp.lang.python
Message-ID <mailman.515.1354731774.29569.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Dec 5, 2012 at 11:18 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Wed, Dec 5, 2012 at 10:57 AM, Daniel Doo <dd@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.

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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Help "joining" two files delimited with pipe character ("|") Ian Kelly <ian.g.kelly@gmail.com> - 2012-12-05 11:22 -0700

csiph-web