Ad
  • Custom User Avatar

    It's because the a if b else c is a ternary operator, whils appending if to the end of the list comprehension will only include results which satisfy this condition in the list - in the latter case, having an else does not make sense.

  • Custom User Avatar

    It does not. In fact, this is not even necessary - you can just do for age, handicap in data.
    The (x, y) syntax in these sort of loops will perform tuple unpacking.
    This is same sort of syntax as:
    a, b = [1, 2], or (a, b) = [1, 2].