0

I have two strings in variables x and y, where the length of x is greater than the length of y. How can you map the smaller string (y) to the size of the large string (x)?

For example:

x = "appleappleapple" # (length 15)
y = "abc" # (length 3) This should be mapped to "abcabcabcabcabc"

while len(y) < len(x):
    y+=y
while len(y) > len(x):
    y = y[:-1] 

print x 
print y 

appleappleapple
abcabcabcabcabc

Is there a very pythonic/efficient way to do this operation?

Noob Coder
  • 949
  • 2
  • 10
  • 17

1 Answers1

4
x = "appleappleapple" # (length 15)
y = "abc" # (length 3) This should be mapped to "abcabcabcabcabc"
z = (y*(len(x)/len(y)+1))[:len(x)]
Daniel
  • 42,087
  • 4
  • 55
  • 81