Checking if two strings are permutations of each other in Python

前端 未结 22 2484
旧时难觅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:18

    I did a pretty thorough comparison in Java with all words in a book I had. The counting method beats the sorting method in every way. The results:

    Testing against 9227 words.
    
    Permutation testing by sorting ... done.        18.582 s
    Permutation testing by counting ... done.       14.949 s
    

    If anyone wants the algorithm and test data set, comment away.

提交回复
热议问题