Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107662 > unrolled thread
| Started by | peakgraphicz@gmail.com |
|---|---|
| First post | 2016-04-26 09:01 -0700 |
| Last post | 2016-04-26 16:07 +0000 |
| Articles | 20 — 10 participants |
Back to article view | Back to comp.lang.python
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
| From | peakgraphicz@gmail.com |
|---|---|
| Date | 2016-04-26 09:01 -0700 |
| Subject | Howw to prevent the duplication of any value in a column within a CSV file (python) |
| Message-ID | <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> |
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. Thanks in advance!
[toc] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2016-04-26 12:08 -0400 |
| Message-ID | <mailman.112.1461686936.32212.python-list@python.org> |
| In reply to | #107662 |
On Tue, Apr 26, 2016 at 12:01 PM, <peakgraphicz@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. > > Thanks in advance! > -- > https://mail.python.org/mailman/listinfo/python-list Show your code and a few lines of your file with useful data. Show the result you want -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays
[toc] | [prev] | [next] | [standalone]
| From | Adam Davis <peakgraphicz@gmail.com> |
|---|---|
| Date | 2016-04-26 10:05 -0700 |
| Message-ID | <25b35d39-4163-414c-9495-f2ed4a2a90a8@googlegroups.com> |
| In reply to | #107663 |
On Tuesday, 26 April 2016 17:09:10 UTC+1, Joel Goldstick wrote:
> On Tue, Apr 26, 2016 at 12:01 PM, <peakgraphicz@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.
> >
> > Thanks in advance!
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
> Show your code and a few lines of your file with useful data. Show
> the result you want
>
> --
> Joel Goldstick
> http://joelgoldstick.com/blog
> http://cc-baseballstats.info/stats/birthdays
Here's my section of code:
with open(class_code+".csv", 'a') as csvfile:
fieldnames = ["Name", "Score 1", "Score 2", "Score 3", "Average"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
#writer.writeheader()
writer.writerow({"Name": name, "Score 1": score1, "Score 2": score2, "Score 3": score3})
It prints when requested as:
Adam,1,0,0,0.3333333333333333
Jake,9,10,6,8.333333333333334
Tom,5,3,3,3.6666666666666665
So basically, if anyone called Adam, Jake or Tom tries the quiz again, it will not let them.
Thanks
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2016-04-26 20:10 -0400 |
| Message-ID | <mailman.133.1461715819.32212.python-list@python.org> |
| In reply to | #107674 |
On Tue, 26 Apr 2016 10:05:00 -0700 (PDT), Adam Davis
<peakgraphicz@gmail.com> declaimed the following:
>Here's my section of code:
>
>with open(class_code+".csv", 'a') as csvfile:
> fieldnames = ["Name", "Score 1", "Score 2", "Score 3", "Average"]
> writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
> #writer.writeheader()
> writer.writerow({"Name": name, "Score 1": score1, "Score 2": score2, "Score 3": score3})
>
>It prints when requested as:
>
>Adam,1,0,0,0.3333333333333333
>Jake,9,10,6,8.333333333333334
>Tom,5,3,3,3.6666666666666665
>
>So basically, if anyone called Adam, Jake or Tom tries the quiz again, it will not let them.
>Thanks
Probably not what you want, but...
I'd drop the CSV file -- create an SQLite3 database with two tables:
TestTaker(*ID*, Name)
and
Scores(*ID*, _testTakerID_, TestID, Score)
where *ID* is the primary key -- autoincrement integer; _testTakeID_ is a
foreign key (the ID of the TestTaker); no need to store the average, you'll
compute that when retrieving data.
If you set up (_testTakerID_, TestID) as a composite unique key, the
database system will object when you try to add a duplicate of those two
fields.
This design is not limited to only three scores (since TestID
identifies which score you can easily add more tests).
You'd get the average by something like (this is off the cuff, I'd have
to test to get the syntax fully correct):
select TestTaker.Name, avg(Score) from
TestTake inner join Scores
on TestTaker.ID = Scores.testTakerID
group by TestTaker.ID
order by TestTaker.Name
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2016-04-26 10:13 -0600 |
| Message-ID | <mailman.113.1461687261.32212.python-list@python.org> |
| In reply to | #107662 |
On Tue, Apr 26, 2016 at 10:01 AM, <peakgraphicz@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.
[toc] | [prev] | [next] | [standalone]
| From | Adam Davis <peakgraphicz@gmail.com> |
|---|---|
| Date | 2016-04-26 10:00 -0700 |
| Message-ID | <514e507d-42de-400e-b999-14605c4456e8@googlegroups.com> |
| In reply to | #107665 |
On Tuesday, 26 April 2016 17:14:36 UTC+1, Ian wrote: > On Tue, Apr 26, 2016 at 10:01 AM, <peakgraphicz@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?
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2016-04-26 13:50 -0600 |
| Message-ID | <mailman.126.1461700262.32212.python-list@python.org> |
| In reply to | #107672 |
On Tue, Apr 26, 2016 at 11:00 AM, Adam Davis <peakgraphicz@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@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.
[toc] | [prev] | [next] | [standalone]
| From | Adam Davis <peakgraphicz@gmail.com> |
|---|---|
| Date | 2016-04-26 10:05 -0700 |
| Message-ID | <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> |
| In reply to | #107662 |
On Tuesday, 26 April 2016 17:01:41 UTC+1, Adam Davis 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.
>
> Thanks in advance!
Here's my section of code:
with open(class_code+".csv", 'a') as csvfile:
fieldnames = ["Name", "Score 1", "Score 2", "Score 3", "Average"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
#writer.writeheader()
writer.writerow({"Name": name, "Score 1": score1, "Score 2": score2, "Score 3": score3})
It prints when requested as:
Adam,1,0,0,0.3333333333333333
Jake,9,10,6,8.333333333333334
Tom,5,3,3,3.6666666666666665
So basically, if anyone called Adam, Jake or Tom tries the quiz again, it will not let them.
Thanks
[toc] | [prev] | [next] | [standalone]
| From | Joaquin Alzola <Joaquin.Alzola@lebara.com> |
|---|---|
| Date | 2016-04-26 19:05 +0000 |
| Message-ID | <mailman.125.1461697547.32212.python-list@python.org> |
| In reply to | #107675 |
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()
-----Original Message-----
From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com@python.org] On Behalf Of Adam Davis
Sent: 26 April 2016 18:05
To: python-list@python.org
Subject: Re: Howw to prevent the duplication of any value in a column within a CSV file (python)
On Tuesday, 26 April 2016 17:01:41 UTC+1, Adam Davis 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.
>
> Thanks in advance!
Here's my section of code:
with open(class_code+".csv", 'a') as csvfile:
fieldnames = ["Name", "Score 1", "Score 2", "Score 3", "Average"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
#writer.writeheader()
writer.writerow({"Name": name, "Score 1": score1, "Score 2": score2, "Score 3": score3})
It prints when requested as:
Adam,1,0,0,0.3333333333333333
Jake,9,10,6,8.333333333333334
Tom,5,3,3,3.6666666666666665
So basically, if anyone called Adam, Jake or Tom tries the quiz again, it will not let them.
Thanks
--
https://mail.python.org/mailman/listinfo/python-list
This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt.
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2016-04-26 13:51 -0600 |
| Message-ID | <mailman.127.1461700361.32212.python-list@python.org> |
| In reply to | #107675 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Adam Davis <peakgraphicz@gmail.com> |
|---|---|
| Date | 2016-04-26 13:07 -0700 |
| Message-ID | <49f4ffd8-d140-4f1b-95a9-75cb122e8b2f@googlegroups.com> |
| In reply to | #107685 |
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?
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2016-04-26 14:19 -0600 |
| Message-ID | <mailman.128.1461702002.32212.python-list@python.org> |
| In reply to | #107686 |
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
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2016-05-02 07:47 -0600 |
| Subject | Re: Private message regarding: Howw to prevent the duplication of any value in a column within a CSV file (python) |
| Message-ID | <mailman.315.1462196864.32212.python-list@python.org> |
| In reply to | #107687 |
On Mon, May 2, 2016 at 3:52 AM, Adam Davis <peakgraphicz@gmail.com> wrote: > Hi Ian, > > I'm really struggling to implement a set into my code as I'm a beginner, > it's taking me a while to grasp the idea of it. If I was to show you my code > so you get an idea of my aim/function of the code, would you be able to help > me at all? Sure, although I'd recommend posting it to the list so that others might also be able to help.
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2016-04-26 21:23 +0100 |
| Message-ID | <mailman.129.1461702225.32212.python-list@python.org> |
| In reply to | #107686 |
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)
[toc] | [prev] | [next] | [standalone]
| From | Adam Davis <peakgraphicz@gmail.com> |
|---|---|
| Date | 2016-04-26 23:26 -0700 |
| Message-ID | <f8a42577-e3c7-4dd6-a2a7-9cee58c37ee4@googlegroups.com> |
| In reply to | #107688 |
On Tuesday, 26 April 2016 21:23:58 UTC+1, MRAB wrote:
> 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)
I understand what you're saying! But where you say: " the_set = set()", what would go within the set brackets?
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2016-04-27 16:37 +1000 |
| Message-ID | <mailman.143.1461739050.32212.python-list@python.org> |
| In reply to | #107709 |
On Wed, Apr 27, 2016 at 4:26 PM, Adam Davis <peakgraphicz@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
[toc] | [prev] | [next] | [standalone]
| From | Adam Davis <peakgraphicz@gmail.com> |
|---|---|
| Date | 2016-04-27 05:23 -0700 |
| Message-ID | <75d2b984-0a1e-42fa-bb3d-f698d4f5e0a1@googlegroups.com> |
| In reply to | #107711 |
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@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?
[toc] | [prev] | [next] | [standalone]
| From | Andrew Ongko <andrew.ongko@gmail.com> |
|---|---|
| Date | 2016-04-27 19:57 +0700 |
| Message-ID | <mailman.147.1461761880.32212.python-list@python.org> |
| In reply to | #107722 |
On Apr 27, 2016 7:25 PM, "Adam Davis" <peakgraphicz@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@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
[toc] | [prev] | [next] | [standalone]
| From | darnold <darnold992000@yahoo.com> |
|---|---|
| Date | 2016-04-27 08:49 -0700 |
| Message-ID | <dd57a3c2-59cc-4830-9953-f32d20a65a2c@googlegroups.com> |
| In reply to | #107723 |
potential_passengers = ['bob','john','sue','wendy','chris','bob','jen','wendy']
accepted_passengers = set()
for name in potential_passengers:
print('checking on {}...'.format(name))
if name not in accepted_passengers:
accepted_passengers.add(name)
print('welcome aboard, {}!'.format(name))
else:
print('i am sorry, we have already accepted a {}.'.format(name))
print()
HTH,
Don
[toc] | [prev] | [next] | [standalone]
| From | Joaquin Alzola <Joaquin.Alzola@lebara.com> |
|---|---|
| Date | 2016-04-26 16:07 +0000 |
| Message-ID | <mailman.134.1461717639.32212.python-list@python.org> |
| In reply to | #107662 |
import csv
Use dictionary {key:value}
-----Original Message-----
From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara.com@python.org] On Behalf Of peakgraphicz@gmail.com
Sent: 26 April 2016 17:01
To: python-list@python.org
Subject: Howw to prevent the duplication of any value in a column within a CSV file (python)
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.
Thanks in advance!
--
https://mail.python.org/mailman/listinfo/python-list
This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web