Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'output': 0.04; 'subject:two': 0.07; 'command.': 0.09; 'delimited': 0.09; 'dict': 0.09; 'iterate': 0.09; 'subject:files': 0.09; 'subject:Help': 0.10; 'dec': 0.15; 'subject:joining': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'skip': 0.17; 'appears': 0.18; 'load': 0.19; 'otherwise,': 0.20; 'pipe': 0.22; 'header:In-Reply- To:1': 0.25; 'fit': 0.26; 'am,': 0.27; 'checking': 0.27; 'message- id:@mail.gmail.com': 0.27; 'daniel': 0.30; 'implement': 0.32; 'file': 0.32; 'joined': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'similar': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'subject:" ': 0.36; 'method': 0.36; 'subject:with': 0.36; 'enough': 0.36; 'two': 0.37; 'virtual': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'time,': 0.62; 'charset:windows-1252': 0.65; 'dict.': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=5Zx3A5a78t6rMDpqCde7O53tUY6B5HScHmHzdQjcYn4=; b=0l29k//SCqJC5097KEUR866PKl0VvkHHJ4/UrRCYpTNgiAktKryRXg875P/yppeTOS d9xV+xLr/FEB2dOrC8r+VeRlJMvBODfvQh4OdgUNkZPu1VIJKDOzq08sYTFz+4kYChEW 6Ev4waMADV8puX4ku9W2cvGKXPihzw7MFfq116a1rUnG9GHQUHrwN9MJXa9d0B1EYFU3 jfKJfCJ4Kf8Uzcn8IEBFqZonD4ls7WfFO1GGzbHG/mS8bkY/j/q1nZd63XV6KEouia1M MhU4W+OnVRNYr8xW+LzYNT5yQhhodYuzCa0TQUsPA7CSTbBUtISnIvZpUQUhoNa7QmdB yJgw== MIME-Version: 1.0 In-Reply-To: <08080305078A3F47B751F7412214A051011B096BF3@MBX22.exg5.exghost.com> References: <08080305078A3F47B751F7412214A051011B096BF3@MBX22.exg5.exghost.com> From: Ian Kelly Date: Wed, 5 Dec 2012 11:18:56 -0700 Subject: Re: Help "joining" two files delimited with pipe character ("|") To: Python Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 12 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354731569 news.xs4all.nl 6945 [2001:888:2000:d::a6]:60613 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34307 On Wed, Dec 5, 2012 at 10:57 AM, Daniel Doo w= rote: > I am new to Python. Is there a method to =93join=94 two pipe delimited f= iles > 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.