
Originally Posted by
quiney
Thanks! So far I have this:
This returns True whenever there is a duplicate, but I still don't know how to get it to return false when there is no duplicate and the list is greater than 0.
I took the liberty of changing a few things around. Compare, and use whatever aspects of it you like
Code:
def dupl(L):
if len(L)<2:
return False
i=0
L2=sorted(L)
while i<len(L)-1:
if L2[i]==L2[i+1]:
return True
i=i+1
return False
L1 = [1,2,3,4,5]
L2 = [1,2,3,2,5]
if dupl(L1):
print "hello"
if dupl(L2):
print "goodbye" Note in particular that a "return" can render an "else" unnecessary.