You’ll notice that the above code is a conditional expression in a lambda expression. I’m not sure the conditional expression is even taught in the basic Python course or anywhere expressly that I can recall. It’s not uncommon for authors to throw in code patterns that haven’t been taught. Better course auditing would bring this to bear, but that is not our purview over here.
def cmp(a, b):
return 1 if a > b else -1 if b > a else 0
This is the Python near equivalent to a JS ternary expression…
return a > b ? 1 : b > a ? -1 : 0;
print (cmp(6, 5), cmp(5, 6), cmp(6, 6)) # 1 -1 0
lambda is an anonymous function expression nearly equivalent to a defined function except it can be returned (or assigned) in its written form. If this is new then a quick segue to the documentation and/or some articles on the subject would be well worthwhile.
The advanced courses can sometimes take it for granted that a learner has more background that they might actually have. Whenever coming across code patterns you don’t recognize, bring them up here and give attribution to the lesson where you found it. That way you don’t get in too deep before grinding to a halt.