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


Groups > comp.lang.python > #44557

Re: how to compare two fields in python

References <59afdc2b-ab76-40b6-8f63-4a562e288029@googlegroups.com>
Date 2013-04-30 13:53 -0400
Subject Re: how to compare two fields in python
From Joel Goldstick <joel.goldstick@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1190.1367344424.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Tue, Apr 30, 2013 at 1:41 PM, upendra kumar Devisetty <
upendrakumar.devisetty@googlemail.com> 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 should study the csv module.

> Thanks in advance..
>
> Upendra
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com

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


Thread

how to compare two fields in python upendra kumar Devisetty <upendrakumar.devisetty@googlemail.com> - 2013-04-30 10:41 -0700
  Re: how to compare two fields in python Joel Goldstick <joel.goldstick@gmail.com> - 2013-04-30 13:53 -0400
  Re: how to compare two fields in python Fábio Santos <fabiosantosart@gmail.com> - 2013-04-30 19:08 +0100
  Re: how to compare two fields in python Tim Chase <python.list@tim.thechases.com> - 2013-04-30 13:19 -0500
    Re: how to compare two fields in python upendra kumar Devisetty <upendrakumar.devisetty@googlemail.com> - 2013-04-30 11:22 -0700
      Re: how to compare two fields in python Fábio Santos <fabiosantosart@gmail.com> - 2013-04-30 19:42 +0100
  Re: how to compare two fields in python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-04-30 19:54 -0400

csiph-web