Hello and welcome back, today I have solved another python related problem on CodeWars and would like to post the solution here.

The question is as follows:-

Given 2 strings, a and b, return a string of the form short+long+short, with the shorter string on the outside and the long string on the inside. The strings will not be the same length, but they may be empty ( length 0 ).

For example:

solution(“1”, “22”) # returns “1221”

solution(“22”, “1”) # returns “1221”

And here is the solution for the above given question.

def solution(a, b): short ='' long = '' if len(a) > len(b): return b+a+b else: return a+b+a

Do you have a better solution for the above question? Post your own solution below this post.

Click to rate this post!

[Total: 2 Average: 1]

Please follow and like us:

def f(a, b):

a, b = sorted((a, b), key=len)

return f”{a}{b}{a}”

ðŸ™‚