Skip to content

Instantly share code, notes, and snippets.

@gogsbread
Created January 4, 2013 03:40
Show Gist options
  • Save gogsbread/4449708 to your computer and use it in GitHub Desktop.
Save gogsbread/4449708 to your computer and use it in GitHub Desktop.
Algorithms - Character Swapping
def CharacterSwap(inputString):
middle = len(inputString)/2
length = len(inputString)
inputList = list(inputString)
for i in range(middle):
temp = inputList[i]
inputList[i] = inputList[length - 1 -i]
inputList[length -1-i] = temp
return ''.join(inputList)
if __name__ == '__main__':
print CharacterSwap('mdam')
print CharacterSwap("Madam, I'm Adam")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment