# Given a phrase. reverse string in the phrase # Keepping the same other # Input: 'My name is Hermann Kontcho' # Output: 'yM eman si nnamreH ohctnoK' def reverse(phrase): # split it by the separator. Can be ' ', ',' or whatever the separator is strings = phrase.split(' ') #initialise the result result = '' # iterate thru them and reverse them one at the time for str in strings: result = result + str[::-1] + ' ' return result # Test here input = 'My name is Hermann Kontcho' output = reverse(input) print output
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question