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


Groups > comp.lang.python > #34307 > unrolled thread

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

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2012-12-05 11:18 -0700
Last post2012-12-05 11:18 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

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

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-12-05 11:18 -0700
SubjectRe: Help "joining" two files delimited with pipe character ("|")
Message-ID<mailman.514.1354731569.29569.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web