Oh no! Ghosts have reportedly swarmed the city. It's your job to get rid of them and save the day!

In this kata, strings represent buildings while whitespaces within those strings represent ghosts.

So what are you waiting for? Return the building(string) without any ghosts(whitespaces)!

Example:

Should return:

If the building contains no ghosts, return the string:

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def ghostbusters(building):
	

Solutions:
ghostbusters = lambda s: s.replace(' ', '') if ' ' in s else "You just wanted my autograph didn't you?"


import re

def ghostbusters(building):
	bs = re.subn('\\s', '', building)
	return bs[0] if bs[1] else "You just wanted my autograph didn't you?"


message = "You just wanted my autograph didn't you?"

def ghostbusters(building):
	return building.replace(' ', '') if ' ' in building else message


def ghostbusters(spookyStr):
	charToRemove = ' '
	deSpookedStr = spookyStr.replace(charToRemove, '')
	if deSpookedStr == spookyStr:
		deSpookedStr = "You just wanted my autograph didn't you?"
	return deSpookedStr


def ghostbusters(building):
	return "You just wanted my autograph didn't you?" if building.isalnum() else building.replace(' ', '')


from re import match, sub

def ghostbusters(building):
	return sub('\\s', '', building) if match('.*\\s.*', building) else "You just wanted my autograph didn't you?"