What error messages are you getting? The most obvious error is nothing is indented.----- Original Message ----- From: "edward" <personal.edward@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx> Sent: Tuesday, October 27, 2009 9:58 AM Subject: RE: Help with python
Hello, If you don't mind taking a look at this function. It is supposed to take out duplicate entries in a list but its not working for some reason. Thanks Edward def dup(old_list): for item in old_list: if old_list[item] not in new_list: new_list.apend.item return new_list a=['eggs','bread','soda','bread'] b=dup(a) print b -----Original Message----- From: programmingblind-bounce@xxxxxxxxxxxxx [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Ken Perry Sent: Saturday, October 24, 2009 11:55 PM To: programmingblind@xxxxxxxxxxxxx Subject: RE: Help with python Well the key is your instructor said it doesn't have to be in order. Thestructure I would use is a dictionary. I am not sure there is a cleaner wayto do this but I can tell you adding to a dictionary in python is one very fast function so the following is how I would do it. Note the try except that is there for the first time you add a word to a dictionary that couldalso be handled by an if statement that checked to see if there was alreadykey in the list and adding it if there wasn't like I do in the except statement but I felt that that would make the code to long. list=['the','word','the','is','the','mode','of','the','list'] dict={} for u in list: try: dict[u]+=1 except: dict[u]=1 print "The unique list is %s\n" % str(dict.keys()) word='' count=0 for k, v in dict.iteritems(): if v>count: word=k count=v print "the string witht he most is %s and there are %d of them\n" % (word,count) -----Original Message----- From: programmingblind-bounce@xxxxxxxxxxxxx [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of edward Sent: Saturday, October 24, 2009 6:21 PM To: programmingblind@xxxxxxxxxxxxx Subject: RE: Help with python Hello Thank you for the email.Yes I think I was reading the problem wrong but I did write the code and itworks fine. Problem two is a problem however. edward -----Original Message----- From: programmingblind-bounce@xxxxxxxxxxxxx [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Martin Slack Sent: Saturday, October 24, 2009 5:57 PM To: programmingblind@xxxxxxxxxxxxx Subject: Re: Help with python I couldn't remember what a mode was so I looked at: http://www.mathgoodies.com/lessons/vol8/mode.html It would seem that both problems have to do with counting the numbers of identical elements in a set or list. Can you write a programme to do that as a start? Martin ----- Original Message ----- From: "edward" <personal.edward@xxxxxxxxx> To: <programmingblind@xxxxxxxxxxxxx> Sent: Saturday, October 24, 2009 10:02 PM Subject: Help with pythonhello all, I have 2 questions on my homework assignment that i cannot figure out. 1. write a function that will return the mode for a data set. A data set is a variable that contains more then one word. 2. Write a function called remove_duplicates that takes a list and returnsa new list with only the unique elements from the original. Hint: they don't have to be in the same order. any help will be greatly appreciated. Edward__________ View the list's information and change your settings at //www.freelists.org/list/programmingblind __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind
__________View the list's information and change your settings at //www.freelists.org/list/programmingblind