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


Groups > comp.lang.python > #107688

Re: Howw to prevent the duplication of any value in a column within a CSV file (python)

From MRAB <python@mrabarnett.plus.com>
Newsgroups comp.lang.python
Subject Re: Howw to prevent the duplication of any value in a column within a CSV file (python)
Date 2016-04-26 21:23 +0100
Message-ID <mailman.129.1461702225.32212.python-list@python.org> (permalink)
References (2 earlier) <HE1PR07MB13561533B5D2DEE4B31F9AA9F0630@HE1PR07MB1356.eurprd07.prod.outlook.com> <CALwzidn=KRgvWZq9jc+G5hT6dxDOOjkYZLTbjLR6qNh82m2_LA@mail.gmail.com> <mailman.127.1461700361.32212.python-list@python.org> <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> <e442a9aa-60f2-641f-08fe-487ca1d29799@mrabarnett.plus.com>

Show all headers | View raw


On 2016-04-26 21:07, Adam Davis wrote:
> On Tuesday, 26 April 2016 20:52:54 UTC+1, Ian  wrote:
>> On Tue, Apr 26, 2016 at 1:05 PM, Joaquin Alzola
>> <Joaquin.Alzola@lebara.com> wrote:
>> > Just an example. Didn't use the csv but just hope that it helps.
>> >
>> > name=[]
>> > name_exist="Dop"
>> >
>> > with open("dop.csv") as f:
>> >         for line in f:
>> >                 line_split=line.split(',')
>> >                 name.append(line_strip[0])
>> >         if name_exist in name:
>> >                 print "found name " + name_exist + " Can not append"
>> >         else:
>> >                 file = open("dop.csv",'a')
>> >                 print "No name found"
>> >                 file.write(name_exist)
>> > file.close()
>>
>> Except that as noted elsewhere in the thread a set would be a better
>> choice than a list, since checking membership is much faster on a set.
>
> Thanks for your help Ian. I'm a beginner right now, could you instruct me as to how I would create a set?
>
Create a set:

     the_set = set()

Add an item to a set:

     the_set.add(item)

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


Thread

Howw to prevent the duplication of any value in a column within a CSV file (python) peakgraphicz@gmail.com - 2016-04-26 09:01 -0700
  Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Joel Goldstick <joel.goldstick@gmail.com> - 2016-04-26 12:08 -0400
    Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Adam Davis <peakgraphicz@gmail.com> - 2016-04-26 10:05 -0700
      Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-04-26 20:10 -0400
  Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-26 10:13 -0600
    Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Adam Davis <peakgraphicz@gmail.com> - 2016-04-26 10:00 -0700
      Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-26 13:50 -0600
  Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Adam Davis <peakgraphicz@gmail.com> - 2016-04-26 10:05 -0700
    RE: Howw to prevent the duplication of any value in a column within a CSV file (python) Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-04-26 19:05 +0000
    Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-26 13:51 -0600
      Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Adam Davis <peakgraphicz@gmail.com> - 2016-04-26 13:07 -0700
        Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-26 14:19 -0600
          Re: Private message regarding: Howw to prevent the duplication of any value in a column within a CSV file (python) Ian Kelly <ian.g.kelly@gmail.com> - 2016-05-02 07:47 -0600
        Re: Howw to prevent the duplication of any value in a column within a CSV file (python) MRAB <python@mrabarnett.plus.com> - 2016-04-26 21:23 +0100
          Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Adam Davis <peakgraphicz@gmail.com> - 2016-04-26 23:26 -0700
            Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Chris Angelico <rosuav@gmail.com> - 2016-04-27 16:37 +1000
              Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Adam Davis <peakgraphicz@gmail.com> - 2016-04-27 05:23 -0700
                Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Andrew Ongko <andrew.ongko@gmail.com> - 2016-04-27 19:57 +0700
                Re: Howw to prevent the duplication of any value in a column within a CSV file (python) darnold <darnold992000@yahoo.com> - 2016-04-27 08:49 -0700
  RE: Howw to prevent the duplication of any value in a column within a CSV file (python) Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-04-26 16:07 +0000

csiph-web