How to check if strings are rotations of each other in Python

1 Answer

0 votes
def rotations(str1, str2):
    size1 = len(str1)
    size2 = len(str2)

    if size1 != size2:
        return 0
 
    print(str1 + str1)
 
    if ((str1 + str1).count(str2) > 0):
        return 1
    else:
        return 0
 
 
str1 = "abcxd"
str2 = "cxdab"
 
if rotations(str1, str2):
    print("yes")
else:
    print("no")
    
    
    
'''
run:

abcxdabcxd
yes

'''

 



answered Dec 23, 2021 by avibootz

Related questions

1 answer 176 views
1 answer 124 views
1 answer 191 views
1 answer 98 views
1 answer 165 views
...