Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'subject:two': 0.07; 'kumar': 0.09; 'subject:fields': 0.09; 'cc:addr:python-list': 0.11; '-tkc': 0.16; '203': 0.16; '509': 0.16; 'csv': 0.16; 'duplicates': 0.16; 'finds': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'ignored?': 0.16; 'subject:compare': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'python?': 0.22; 'cc:addr:python.org': 0.22; 'example.': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'compare': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'file': 0.32; 'basic': 0.35; 'problem.': 0.35; 'done': 0.36; 'next': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'previous': 0.38; 'how': 0.40; 'numbers': 0.61; 'first': 0.61; 'field': 0.63; 'different': 0.65; 'finally': 0.65; 'here': 0.66; 'of:': 0.68; 'noise': 0.84; 'received:50.22': 0.84; 'significance': 0.84 Date: Tue, 30 Apr 2013 13:19:56 -0500 From: Tim Chase To: upendra kumar Devisetty Subject: Re: how to compare two fields in python In-Reply-To: <59afdc2b-ab76-40b6-8f63-4a562e288029@googlegroups.com> References: <59afdc2b-ab76-40b6-8f63-4a562e288029@googlegroups.com> X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com Cc: python-list@python.org 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367345875 news.xs4all.nl 15962 [2001:888:2000:d::a6]:50928 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44562 On 2013-04-30 10:41, upendra kumar Devisetty wrote: > I have a very basic question in python. I want to go through each > line of the a csv file and compare to see if the first field of > line 1 is same as first field of next line and so on. If it finds a > match then i would like to put that field in an object1 else put > that field in a different object2. Finally i would like to count > how many of the fields in object1 vs object2. Can this be done in > python? Here is a small example. > > BRM_1 679 1929 > BRM_1 203 567 > BRM_2 367 1308 > BRM_3 435 509 > As you can see field1 of line1 is same as field2 of line2 and so > that field BRM_1 should be place in object1 and BRM_2 and BRM_3 > should be placed in object2. So the final numbers of object1 is 1 > and object2 is 2. You underdefine the problem. What happens in the case of: BRM_1 ... BRM_1 ... BRM_2 ... BRM_1 ... <-- duplicates a (not-immediately) previous line BRM_3 ... Also, do the values that follow have any significance for this, or are they just noise to be ignored? -tkc