← Back to challenges

Repeat the Shorter String

PythonHardstringsloops

Instructions

Write a function that repeats the shorter string until it is equal to the length of the longer string.

Examples

lengthen("abcdefg", "ab") ➞ "abababa"

lengthen("ingenius", "forest") ➞ "forestfo"

lengthen("clap", "skipping") ➞ "clapclap"

Notes

  • Both strings will differ in length.
  • Both strings will contain at least one character.
  • Either of the two strings could be the shortest in length.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.