Answer to Question #267504 in Python for Sajju

Question #267504

given two strings write a program to determine if a string s2 is a rotation of another string s1 in python in easy method


1
Expert's answer
2021-11-17T06:30:45-0500
def is_rotation(string1, string2):
    size1 = len(string1)
    size2 = len(string2)
    temp = ''
    if size1 != size2:
        return '{} is not a rotation of {}'.format(string1, string2)
    temp = string1 + string1
    if temp.count(string2) > 0:
        return '{} is a rotation of {}'.format(string1, string2)
    else:
        return '{} is not a rotation of {}'.format(string1, string2)

is_rotation('AACD', 'ACDA')
'AACD is a rotation of ACDA'

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS