变位词的判断,怎样编写程序

【问题描述】如果一个字符串是另一个字符串的重新排列组合,那么这两个字符串互为变位词。例如:”heart”与”earth”互为变位 词,”Mary”与”arMy”也互为变位词。提示:两个相同的字符串不是变位词。

【输入格式】第一行输入第一个字符串,第二行输入第二个字符串。

【输出格式】如果是变位词,则输出“yes”;如果不是变位词,输出“no”

def judge(a,b):
    if sorted(list(a))==sorted(list(b)):
        print('yes')
    else:
        print('no')

word1 = input()
word2 = input()
judge(word1,word2)

'''
example:
judge('heart','earth')
judge('Mary','arMy')
'''