PYTHON   37
laceStringsRecur
Guest on 26th August 2023 12:36:07 AM


  1. def laceStringsRecur(s1, s2):
  2.     """
  3.    s1 and s2 are strings.
  4.  
  5.    Returns a new str with elements of s1 and s2 interlaced,
  6.    beginning with s1. If strings are not of same length,
  7.    then the extra elements should appear at the end.
  8.    """
  9.     def helpLaceStrings(s1, s2, out):
  10.         if s1 == '':
  11.             #PLACE A LINE OF CODE HERE
  12.             return out+s2
  13.         if s2 == '':
  14.             #PLACE A LINE OF CODE HERE
  15.             return out+s1
  16.         else:
  17.             #PLACE A LINE OF CODE HERE
  18.             return helpLaceStrings(s1[1:], s2[1:], out+s1[0]+s2[0])
  19.     return helpLaceStrings(s1, s2, '')

Raw Paste

Login or Register to edit or fork this paste. It's free.