[Tutor] List issues

Dave Angel davea at davea.name
Thu Apr 17 12:03:56 CEST 2014

"Wheeler, Gabriel" <wheelerg at seattleu.edu> Wrote in message:

(not much I could read there. This is a text mailing list, so
 please tell your mail program to send in text mode, not html.
 Only parts of your code were visible here, and your question not
 at all. Fortunately, Peter quoted all or most of your message. 
 His comments are all good.  Mine are in addition,  not instead.

Your code:

list = [1,2,2,2,3,4]

def duplicate(list):
   for i in range(len[list]):
       if list.count(i) > 1:
           return True

print duplicate(list)


Peter's hints should fix your main bugs. Then:

When an if-test doesn't seem to be doing what you expect,  add a
 print statement right before it of the exact expression it's
 testing.  Or even make a new variable of the expression so you
 can be sure you're looking at the same thing. 

When a standard method seems to be misbehaving,  look up its
 definition.  What should the argument to count be?

list is a typename in the standard library,  so it really
 shouldn't be used to name your own objects. I'd use something
 like mylist.

Whenever you see a loop like 
       for i in range(len[list]):

be suspicious of it. Usually you want the items, not the indices. 
        for item in mylist:

This function doesn't return any value if the if test always
 fails. Is that what you wanted? 


More information about the Tutor mailing list