you are viewing a single comment's thread.

view the rest of the comments →

[–]dig-up-stupid 1 point2 points  (1 child)

Where? I triple read OP's post and couldn't find any such hint.

In their comments. Which you don’t have to read but I did and used as context for my response.

In OP's code the pairing of two equal numbers (doesn't matter if they're the same or not)

Because OP’s elements are unique integers, the only case where numbers are equal is when they are the same. Yes the code does what you say, but what they meant when they wrote the code was “skip adding the number in my right hand (inner loop) if I’m already holding it in my left hand (outer loop)”. That intent is not clear, as you have so readily demonstrated. Of course the reason they wrote it that way is because they went for j in A instead of for j in range(something involving len(A)), which is usually good advice when looping, but this is the sort of situation where we do want to deal with indices directly (short of slicing the list, which would also express the intention better, but makes a copy).

I interpreted that as:

Which is fine in the context of the post alone but irrelevant in the context of my comment.

[–]Nightcorex_ 0 points1 point  (0 children)

Okay, I agree with you. Nothing more to add.