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

Ian Kelly ian.g.kelly at gmail.com
Tue Apr 26 15:50:20 EDT 2016


On Tue, Apr 26, 2016 at 11:00 AM, Adam Davis <peakgraphicz at gmail.com> wrote:
> On Tuesday, 26 April 2016 17:14:36 UTC+1, Ian  wrote:
>> On Tue, Apr 26, 2016 at 10:01 AM,  <peakgraphicz at gmail.com> wrote:
>> > I am wondering how to make my code function so it does not allow any of the same values to be entered into a column in my CSV file created through python. So I need to read into the CSV file and check if any names have already been entered. If they have, the user must not be allowed to enter this value.
>>
>> Assuming the file is reasonably small enough to fit into memory,
>> create a set and populate it with the values in the column. When the
>> user enters a new value, check whether it's already in the set.
>
> That's exactly what I want to do, however, I'm unsure how to check whether it's in the set?

if value in the_set:
    # Forbid the value.
else:
    # Allow the value.



More information about the Python-list mailing list