CodeFights - Cat Walk - Solution

Problem
You've been working on a particularly difficult algorithm all day, and finally decided to take a break and drink some coffee. To your horror, when you returned you found out that your cat decided to take a walk on the keyboard in your absence, and pressed a key or two. Your computer doesn't react to letters being pressed when an unauthorized action appears, but allows typing whitespace characters and moving the arrow keys, so now your masterpiece contains way too many whitespace characters.
To repair the damage, you need to start with implementing a function that will replace all multiple space characters in the given line of your code with single ones. In addition, all leading and trailing whitespaces should be removed.
Example
For line = "def      m   e  gaDifficu     ltFun        ction(x):",
the output should be
catWalk(line) = "def m e gaDifficu ltFun ction(x):".
Input/Output
  • [execution time limit] 4 seconds (py)
  • [input] string line
    One line from your code containing way too many whitespace characters.
    Guaranteed constraints:
    5 ≤ line.length ≤ 125.
  • [output] string
    line with unnecessary whitespace characters removed.
Solution


def catWalk(code):
    return " ".join(code.strip().split())

7 comments:

  1. Appyzone
    You can get free mac & pc applications. You are one click away from getting best cracks, cheats, and patches of games www.appyzone.com

    ReplyDelete
  2. All good. I am a newcomer, so I jerked until the money was withdrawn. I waited 2 days on Yandex. Thanks to the admins and support service for listening to my whining on the forum and in the chat. Play people! Do not be greedy. All the rules with this casino! perfect casino slot machine games I often spend my time here

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete