"""Given 2 strings, a and b, return a string of the form: shorter+reverse(longer)+shorter. In other words, the shortest list has to be put as prefix and as suffix of the reverse of the longest. Strings a and b may be the empty string, but not null. If a and b has the same length treat a as the longer producing b+reverse(a)+b""" def shorter_reverse_longer(a,b): if len(a)>len(b): print b + a[::-1] + b elif len(a)<len(b): print a + b[::-1] + a else: print b + a[::-1] + b shorter_reverse_longer("first","abcde")
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