Ad

Lambda with ternary operator

Code
Diff
  • power_of_two = lambda n: (False, True)[n % 2 == 0]
    • power_of_two = lambda n: n % 2 == 0;
    • power_of_two = lambda n: (False, True)[n % 2 == 0]

Used lambda for a simplier look

Code
Diff
  • power_of_two = lambda n: n % 2 == 0;
    • def power_of_two( n ):
    • if n % 2 == 0: return True
    • else: return False
    • power_of_two = lambda n: n % 2 == 0;