Ad
  • Custom User Avatar

    Obviously, it would be better to convert numbers to strings once only.

  • Custom User Avatar

    This will work in the mentionned case since, in Python, "0" != 0.

    Note that this solution will transform 0.0s into 0s, but in Python this shouldn't be a problem.

  • Custom User Avatar
  • Custom User Avatar

    Read about python's boolean operations here.

    In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: False, None, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets and frozensets). All other values are interpreted as true.

    In a list comprehension an if can be added which will cause only those elements which satisfy the if condition to be added to the list.