We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
It is in lexographical order due to the nature of the loops.
Spaced out it looks somewhat like
for a in range(x+1):
for b in range(y+1):
for c in range(z+1):
if a + b + c != n:
print(stuff is here)
We start at [0,0,0].
Then c will increment to get to [0,0,1]
When c hits [0,0,z], we get [0,1,0] as the next in the loop. This pattern continues and gives us the lexographical ordering required of the output.
List Comprehensions
You are viewing a single comment's thread. Return to all comments →
It is in lexographical order due to the nature of the loops. Spaced out it looks somewhat like
We start at [0,0,0]. Then c will increment to get to [0,0,1] When c hits [0,0,z], we get [0,1,0] as the next in the loop. This pattern continues and gives us the lexographical ordering required of the output.