[ad_1]
The problem
Given 2 strings, a
and b
, return a string of the shape quick+lengthy+quick, with the shorter string on the surface and the longer string on the within. The strings is not going to be the identical size, however they might be empty ( size “ ).
For instance:
answer("1", "22") # returns "1221"
answer("22", "1") # returns "1221"
The answer in Python code
Possibility 1:
def answer(a, b):
if a.isdigit():
if a<b:
return f"{a}{b}{a}"
else:
return f"{b}{a}{b}"
else:
if len(a)<len(b):
return f"{a}{b}{a}"
else:
return f"{b}{a}{b}"
Possibility 2:
def answer(a, b):
return a+b+a if len(a)<len(b) else b+a+b
Possibility 3:
def answer(a, b):
return '{0}{1}{0}'.format(*sorted((a, b), key=len))
Check circumstances to validate our answer
import take a look at
from answer import answer
@take a look at.describe("Mounted Checks")
def fixed_tests():
@take a look at.it('Primary Check Circumstances')
def basic_test_cases():
take a look at.assert_equals(answer('45', '1'), '1451')
take a look at.assert_equals(answer('13', '200'), '1320013')
take a look at.assert_equals(answer('Quickly', 'Me'), 'MeSoonMe')
take a look at.assert_equals(answer('U', 'False'), 'UFalseU')
[ad_2]