DEV Community

Keerti Sadana S
Keerti Sadana S

Posted on

PYTHON - STRING MANIPULATION 2

Anagram

word1 = input('Enter word: ')
word2 = input('Enter word: ')
if len(word1) != len(word1):
    print('Not Anagram')
else:
    for letter in word1:
        if word1.count(letter) != word2.count(letter):
            print('Not Anagram')
            break
    else:
        print('Anagram')
Enter fullscreen mode Exit fullscreen mode

Output:
Enter word: cat
Enter word: act
Anagram

Rotation:

word = 'abcd' 
for i in range(len(word)):
    rotate = word[1:]+word[0]
    word = rotate
    print(rotate)
Enter fullscreen mode Exit fullscreen mode

Output:
bcda
cdab
dabc
abcd

Top comments (0)