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
        return a+b+a

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

Please follow and like us:


Leave a Reply

Your email address will not be published. Required fields are marked *