Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107687
| Path | csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Howw to prevent the duplication of any value in a column within a CSV file (python) |
| Date | Tue, 26 Apr 2016 14:19:20 -0600 |
| Lines | 40 |
| Message-ID | <mailman.128.1461702002.32212.python-list@python.org> (permalink) |
| References | <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> <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> <CALwzidnC3dsQjDyYUM+tiSZUNxi2+-QdzLCUrAHNipAK_3vHtg@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de Px+rotsRSaHo+Gb06HcFnQugRvq4c+t+3nXlwRR69FJg== |
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'received:209.85.223': 0.03; 'subject:file': 0.07; 'csv': 0.09; 'subject:CSV': 0.09; 'thread': 0.10; 'python': 0.10; 'subject:python': 0.14; 'subject: \n ': 0.15; '2016': 0.16; 'adam': 0.16; 'file.close()': 0.16; 'found"': 0.16; 'helps.': 0.16; 'ian.': 0.16; 'membership:': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'set()': 0.16; 'set:': 0.16; 'wrote:': 0.16; 'beginner': 0.18; 'example.': 0.18; 'noted': 0.22; 'header :In-Reply-To:1': 0.24; 'checking': 0.27; 'message- id:@mail.gmail.com': 0.27; '"no': 0.29; 'tutorial': 0.29; "i'm": 0.30; 'print': 0.30; 'url:python': 0.33; 'tue,': 0.34; 'file': 0.34; 'except': 0.34; 'membership': 0.34; 'add': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'set.': 0.35; 'but': 0.36; 'list,': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'faster': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:209': 0.38; 'subject:the': 0.39; "didn't": 0.39; 'to:addr:python.org': 0.40; 'url:3': 0.60; 'your': 0.60; 'hope': 0.61; 'skip:n 10': 0.62; 'elsewhere': 0.66; '26,': 0.72; 'subject:any': 0.84; 'subject:value': 0.84; 'to:name:python': 0.84; 'url:tutorial': 0.91 |
| 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; bh=AavGBMQTdpp37NdCKonb6KvdJo5pyPlyM8JZFb9smKU=; b=t5rvvzpDPT59irKKksB6bqSTS2BVOdkxP7c/TNIHOaSFyXo0BqhZ2ZG7X4yWJmuBFe lv2pWTbfNIjsrzKbmjR/K6aX4PBEfPS1/PK0OEeWwS2tSrRvjY0R9viSV2E/PDsrgd8q DGum4ua/NsUYL1tb2q7ivSA8tlEFt6mxf1L8lnNAdGQLZHJz3kXQNBc9cBNHSciq3wsF NzMd6xlmhLAbZAvYDPgnXG1asJZT3gwWs1U5f9gL/TdWw/XtuaK5dQKKGNqUjBOGLffM guOdxENXgwHK2pJXl7pKOz4gelvElPhmj+xVMcJjYpY1wVIe5X8oI2huoHg95+LgYCfU DbXg== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=AavGBMQTdpp37NdCKonb6KvdJo5pyPlyM8JZFb9smKU=; b=K+4TwCnsgczJIXHFPuHp7xxwZ1n4zrWlOnUxWZi2nnHnwWJvPiCrKu5+b7499QFV2S iSz6tyXCAkIRfCwY8Ns+FQ30hAkzxAgeZL2Nu43w1OHsiGxVNMO38adO2k3GGAZJ/ByQ DQanIIBgbktz/tTxaMnB02sa17Eyj9xCCK0rZCjhjviq2iaKmVAocDgCbJUrLCvmzsiK sjDRzkN3ExRRVmmdivGkANZGgGf5EEWhuMEPIbrEa0z2yUyt2f4GHNw6BMTEnO6QKiJt /U4e/YHOETSVq/+j0qaq14axMQy98Z7ZEyEpvbksGoolnQ1nfSKKAN92rWE99fqVU59q 1krw== |
| X-Gm-Message-State | AOPr4FWZ7TbRklwsEr8G1+7KK2ks51JqVIeIaSVcW6iywKHamM2a6qrrOxNalTA5qWyZGsT9otEqjiuuxp4W9w== |
| X-Received | by 10.107.171.198 with SMTP id u189mr5977629ioe.111.1461701999386; Tue, 26 Apr 2016 13:19:59 -0700 (PDT) |
| In-Reply-To | <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <CALwzidnC3dsQjDyYUM+tiSZUNxi2+-QdzLCUrAHNipAK_3vHtg@mail.gmail.com> |
| X-Mailman-Original-References | <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> <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> |
| Xref | csiph.com comp.lang.python:107687 |
Show key headers only | View raw
On Tue, Apr 26, 2016 at 2:07 PM, Adam Davis <peakgraphicz@gmail.com> 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 new set:
my_set = set()
Add a value to the set:
my_set.add(value)
Check for membership:
value in my_set
See also the Python tutorial at
https://docs.python.org/3/tutorial/datastructures.html#sets
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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