Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly 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 13:51:58 -0600 Lines: 21 Message-ID: References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de njhszb+chH4PK4sIHDqxZgZv4Bh9e0uKWkPfU5MXdPfQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'subject:file': 0.07; 'csv': 0.09; 'subject:CSV': 0.09; 'thread': 0.10; 'subject:python': 0.14; 'subject: \n ': 0.15; '2016': 0.16; 'file.close()': 0.16; 'found"': 0.16; 'helps.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; '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; 'print': 0.30; 'tue,': 0.34; 'file': 0.34; 'except': 0.34; 'membership': 0.34; 'received:google.com': 0.35; 'set.': 0.35; 'but': 0.36; 'list,': 0.36; 'received:209.85': 0.36; 'faster': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'subject:the': 0.39; "didn't": 0.39; 'to:addr:python.org': 0.40; '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 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=Zjdlqbi063CgDktInwPRTIoMz4vRLqeunoy+5Rl1Rm0=; b=O19oV70ArJ5ZiGa8UUx6Czuxh1fturSzr1mMMAvEPOSfYsKhS4pZS9+JDqCnbN7LRe eZjRO+jvUYm0WWoviG02f1trwjRi0pNFBGpegSj4ecEq+DnIixVPtYaJ6CqczouM/tIV sdGITZwJ7PFLAM87SO+jtxjxZc0NiomEbxt1+lNneAwS9HYUNv/L7LaJfxkCIliYvZKd W8eGCr0kEBmhNVo+eGavkxChJSGn5b89hmFUr/J9zCvrdZ3ZY7smu9KuqB46I6gmhAOH 86SEl2GIgwtbjBjBWAeWDZyt6HCcZa+50wHvgXiMqdfMbtqJJh1m/hA0vDD1vpIcyKos ITHg== 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=Zjdlqbi063CgDktInwPRTIoMz4vRLqeunoy+5Rl1Rm0=; b=ilQz/ftFUEbkovNBHOgvgO6x0wMVo7tg1HRQ1DnBKJGqzI9B+oRtgeJnPC6u4Zg4cA U5Em0NP1GezGv3go6tojhNEdXUkfgzpi/VSacuzzBfBWZxybzGLi0UuSQgUbjtgu5e6I f1CT2Son/Vwbiza/khrnJzoNqIm1gPU3tTdu3zTe8XD98TYYz/pvZzOIqnngqZg84d7e esyUrGYwl5ayLB94ACRyjdiTTRX07U8EqbiMU49szJTbiawKF2wZd/onVIQiXwzdqwiq ycDerIAaM0iaATvlvC564zOm4EADe6zPsdb7cm4e8x1yneXxUuM757/OmqGRi8K9RtYk PBEg== X-Gm-Message-State: AOPr4FWacnrJH3D0K12MdXHJE2OCc12GDvnYf0ryl+0RQOuYcqitFvUN+i6C+FjqufAq5RhUsAnbc0CXai6gHA== X-Received: by 10.50.13.73 with SMTP id f9mr5818442igc.68.1461700357732; Tue, 26 Apr 2016 12:52:37 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> Xref: csiph.com comp.lang.python:107685 On Tue, Apr 26, 2016 at 1:05 PM, Joaquin Alzola 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.