Checking strings against each other (Anagrams)

后端 未结 23 1874
忘了有多久
忘了有多久 2020-11-30 10:55

The assignment is to write a program that accepts two groups of words from the user and then prints a \"True\" statement if the two are anagrams (or at least if all the lett

23条回答
  •  独厮守ぢ
    2020-11-30 11:07

    Just a thought:

    def check_(arg):
            mark = hash(str(set(sorted(arg))))
            return mark
    
    def ana(s1, s2):
            if check_(s1) != check_(s2):
                    pass
            elif len(s1) != len(s2):
                    pass
            else:
                 print("{0} could be anagram of  {1}".format(s1, s2))

提交回复
热议问题