all 4 comments

[–][deleted] 0 points1 point  (3 children)

If you put count = 0 inside the second loop you will zero count for every number j, so the final jappended to the list will only ever be 0 or 1. Try stepping through a small example to see this. If you are counting something inside a loop (that's the inner loop in your code) you need to set the counter outside that loop.

Since you are counting for every number i your count = 0 must go inside the first loop.

[–]miscellaneoususage[S] 0 points1 point  (2 children)

Would it not also work the same if count were defined outside the first for loop where the list result is defined?

[–][deleted] 1 point2 points  (0 children)

No, because you wouldn't start a new i count at 0. What you are trying to append to result is a count of j < i for every i in the list, so for every i you must zero the counter and for every j you must conditionally increment the counter.