Checking strings against each other (Anagrams)

后端 未结 23 1982
忘了有多久
忘了有多久 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

    This case we check using two containers for each sorted string.

    def anagram(s1, s2):
        str1 = ''
        str2 = ''
    
        for i in s1:
          str1 += i
    
        for j in s2:
          str2 += j
    
        if str1 == str2:
          return True
    
        return False
    

提交回复
热议问题