Consider splitting a string into two halves. If the length is even, the front and back half are the same size. If the length is odd, the extra character is in the front half.
Example: 'abcde', the front half is 'abc' and the back half is 'de'.
Finally, given two strings a and b, return a string of the form: a-front + b-front + a-back + b-back
So if a = 'abcde' and b = 'vwxyz', then the returned form is abcvwxdeyz
this is the most pythonic I've got:
def front_back(a, b):
import math
half_a = math.ceil(len(a)/2)
half_b = math.ceil(len(b)/2)
return a[:half_a]+b[:half_b]+a[half_a:]+b[half_b:]
Would there be a pythonic way to go more efficient or with less lines here? Gratitude.