判断是否是anagram

所谓anagram,就是两个词所用的字母及其个数都是一样的,但是它们字母的位置不一样,比如abc,bac,acb。在Python中,Counter可以解决这个问题。

from collections import Counter

str1,str2="abc","bca"
if(Counter(str1)==Counter(str2)):
    print("This is anagram")
else:
    print("This is Not anagram")

附加的收获是学了一个有趣的单词“anagram”。

猜你喜欢

转载自blog.csdn.net/acflair/article/details/82750242