def isRotation(s1, s2):
return len(s1) == len(s2) and s2 in s1*2
isRotation("ABCD", "CDAB")
>> True
The code above was given as one of many ways to check if two strings are a rotation of each other. However, I don't understand why String1(s1) has to be multiplied by 2 in the code.
str * 2will just add a second copy of the string so"ABC" * 2 -> "ABCABC". From there, it can check if the original string is a substring of this string.