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

Andrew Ongko andrew.ongko at gmail.com
Wed Apr 27 08:57:58 EDT 2016


On Apr 27, 2016 7:25 PM, "Adam Davis" <peakgraphicz at gmail.com> wrote:
>
> On Wednesday, 27 April 2016 07:37:42 UTC+1, Chris Angelico  wrote:
> > On Wed, Apr 27, 2016 at 4:26 PM, Adam Davis <peakgraphicz at gmail.com>
wrote:
> > > I understand what you're saying! But where you say: " the_set =
set()", what would go within the set brackets?
> >
> > Nothing. The empty parentheses mean "call this with no arguments", and
> > when you call the set constructor like that, you get back an empty
> > set.
> >
> > ChrisA
>
> Thanks Chris. Where Ian says 'the_set.add(item)', what would be put
within item in terms of my codes function/aim?

item is name in your case. Since it's the one you care about existing or
not.

It would be like:
Read from csv,
For each row, the_set.add(name)

Now that you have the_set in memory, whenever you want to check whether a
particular name has taken the quiz, just do:

if name in the_set:
    # forbid
else:
    # allow

Regards,
Andrew



More information about the Python-list mailing list