Given a sequence, I was wondering how to find duplicates using ONLY for loops (no imported modules, sorting functions, and etc.) in Python. Here's my following code that involves nested for loops so far:
def has_duplicates(list):
x = 0
ans = False
for i in range(len(list)):
index = i
for object in list:
x = object
if list[i] == x:
ans = True
break
return ans
I really do not know what to code for the inner loop... Are nested loops even necessary to find the duplicates of a sequence?
Examples of following outputs:
list = [10, 11, 12, 13, 14, 15]
print(ans)
False
list = "Hello"
print(ans)
True
set?enumerateallowed?