SyntaxFix
Write A Post
Hire A Developer
Questions
Another one liner for sign()
sign = lambda x: (1, -1)[x<0]
If you want it to return 0 for x = 0:
sign = lambda x: x and (1, -1)[x<0]