0
What's wrong with this simple duplicate-checker?
def dup(x): for k in x: for z in x: if x.index(k) != x.index(z): if k == z: return True return False print(dup([1,3,2,1]))
7 odpowiedzi
+ 3
it’s not so much that it’s too complex, but rather, you seem to be trying to scissor walk backwards so you can get in your car more easily without having to turn around when you sit down.
+ 1
I think by trying to make this more efficient using a double for loop, you’ve actually made it more confusing. What I recommend is adding the characters in the string to a new string as you go through them, but first checking if they’re not in the string already.
+ 1
what you can also do is use the count method of the string object for each character, bucking the loop if it returns true.
0
yeah, I think a better way is to do set(x) == x.
but it should still work.
0
I’m sorry, I mean if it returns >1
0
ok.. that would work, my code is probably too complex and there's something wrong with it internally that i don't understand. oh well, i will use another method!
0
hahaha, "True"