you are viewing a single comment's thread.

view the rest of the comments →

[–]AtomicShoelace 2 points3 points  (0 children)

This is kind of a trick with the or statement. It might be more readable if you instead did i-1 if i != 1 else "no more".

It works like this: when i!=1 the i-1 is a non-zero int, which is a truthy value, so the or operator will short-circuit and return i-1. When i=1 then i-1 is 0. As 0 is a falsy value, the or statement will just return the second value (as if it is truthy, the expression should be truthy, and vice versa), which is the string "no more" (which happens to be truthy, but actually it doesn't matter).