Checking if two strings are permutations of each other in Python

前端 未结 22 2433
旧时难觅i
旧时难觅i 2020-12-08 16:04

I\'m checking if two strings a and b are permutations of each other, and I\'m wondering what the ideal way to do this is in Python. From the Zen of

22条回答
  •  自闭症患者
    2020-12-08 16:08

    def permute(str1,str2):
        if sorted(str1) == sorted(str2):
            return True
        else:
            return False
    
    str1="hello"
    str2='olehl'
    a=permute(str1,str2)
    print(a
    

提交回复
热议问题