检查字符串是否是彼此的字谜

时间:2017-04-28 15:06:24

标签: python-3.x

我编写了检查两个字符串是否是Python中彼此字符串的逻辑。有人可以检查这是否正确或是否有更好的出路:

def checkanagram(str1,str2):
    l1 = list(str1)
    l2 = list(str2)
    temp = str1
    for c in temp:
        if c in l2:
            l1.remove(c)
            l2.remove(c)
    if len(l1) == 0 and len(l2) == 0:
        return True
    else:
        return False

str1 = input()
str2 = input()
if checkanagram(str1,str2):
    print ("It is an anagram")
else:
    print ("Its not an anagrams")

0 个答案:

没有答案