New answers tagged

1

You should consider using consistent indentation when writing code - it makes it much easier for people to read (not only for other maintainers, but for you as well). For example let loop = 0; for (; loop < 155; loop++) { let n = 00; // ... zz ="00"; if (loop > 0 ) { x+=loop; console.log('one loop ' + loop ); should be something ...


2

Your code does not run as it is shown there. The problem, as mentioned in the comments, is that int 5 is not iterable. range(5) is, which would perform the action five times. Looking for if a not in l: l.append(a) in each loop requires looking through that list each time. Using sets instead, this operation is still required somewhere under the hood, ...


2

As mentioned in Thomas Weller's post, your for loop only executes a single time. You want to loop over a range(5). You may wish to use a set to collect your unique results. Test for containment using a not in l is an \$O(N)\$ operation when l is a list, but is \$O(1)\$ when l is a set, so can be significantly faster. Moreover, since a set naturally ...


Top 50 recent answers are included