Have a look at this page in the documentation: http://docs.python.org/3.3/faq/programming.html#is-there-an-equivalent-of-c-s-ternary-operator
In older versions of Python the "and-or" idiom was used to emulate a ternary operator. In modern Python you'd write the above expression as
fsa = union(fsa, fsa2) if fsa else fsa2
The trick is the short-cutting behaviour of and and or in Python:
- a and bevaluates to- bif- aas a boolean evaluates to- True, otherwise it evaluates to- a
- a or bevaluates to- bif- aas a boolean evaluates to- False, otherwise it evaluates to- a
Put this together and you have a nice ternary operator emulation :)
EDIT: However, as Alfe rightfully commented, this is not exactly equivalent. If union(fsa, fsa2) is False as a boolean (i.e. if the union function returned None) the existing code would return fsa2 while the "modern" code would return None or whatever false value union returned. I'd stick with the existing code since it continues to work in newer python versions and document it. Have a look at the implementation of union to decide whether you want to transition to the modern, IMHO cleaner, syntax.