Question: URGENT! THANK YOU! 2. Write a function weave(s1, s2) that takes as inputs two strings s1 and s2 and uses a loop to construct and
URGENT! THANK YOU!


2. Write a function weave(s1, s2) that takes as inputs two strings s1 and s2 and uses a loop to construct and return a new string that is formed by "weaving" together the characters in the strings s1 and s2 to create a single string. In other words, the new string should alternate characters from the two strings: the first character from s1, followed by the first character from s2, followed by the second character from s1, followed by the second character from s2, etc. If one of the strings is longer than the other, its "extra" characters - the ones with no counterparts in the shorter string - should appear immediately after the "woven" characters (if any) in the new string >>weaveC' aaaaaa', "bbbbbb'") abababababab >weave('abcde', 'VWXYZ aVbWcXdYeZ >>> weave(' aaaaaa', 'bb') # four extra 'a' characters at the end ababaaaa >>> weave(' aaaa', 'bbbbbb') # two extra 'b' characters at the end ababababbb >>>weave( aaaa', '") # all of the 'a' characters are extra! weave ', bbbb') # all of the 'b' characters are extra! weave(', '' You solved this problem using recursion in [Problem Set 2][ps2], but for this problem set you must use a loop
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
