Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
It's not a matter of order; Python simply does not directly allow else clauses as part of list comprehensions (docs). When we use [num if num != 11 else 22 for num in hand] We are actually usin...
Answer
#1: Initial revision
It's not a matter of order; Python simply does not directly allow `else` clauses as part of list comprehensions ([docs](https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries)). When we use ```python [num if num != 11 else 22 for num in hand] ``` We are actually using Python's version of the ternary operator; the `if` and `else` are not part of the list comprehension itself but of the comprehension expression. That is, the above is actually ```python [(num if num != 11 else 22) for num in hand] ```