Ad
  • Default User Avatar

    Nice solution and the single line ifs make it fairly neat/concise. Maybe not best practice though. In if, elif statements - only one is ever called based on the conditions. In yours it looks at both ifs each time. Also, 'open_counter = open_counter + 1' can be reduced to 'open_counter += 1' and likewise, -= 1.

  • Default User Avatar

    Nice, clean solution but what happens if there are 3 or more spaces?

  • Default User Avatar

    imported re for a different method, changed it and different remove import. D'oh

  • Default User Avatar

    Clever, for sure. Not overly readable for beginners and it doesn't gain any efficiency for being a one-liner.

    Two joins, two for-loops. Using timeit.timeit over 1,000,000 executions, this solution took 13 seconds. Others with one loop took 9 seconds.

    Best to unpack it sometimes.