Add use of ternary operator for formatting

Using python built-in ternary operator, you can remove some unnecessary
extra lines in the code and buy a little more clarity.

Thanks @antgonza