How to check whether two words are anagrams python
<p>I'm dealing with a simple problem:</p>

<ul>
<li>checking if two strings are anagrams.</li>
</ul>

<p>I wrote the simple code that can check whether two strings, such as 
'abcd' and 'dcba', are anagrams, but I have no idea what to do with more complex ones, like "Astronomer" and "Moon starter."</p>

<pre><code>line1 = input('Enter the first word: ')
line2 = input('Enter the second word: ')

def deleteSpaces(s):
    s_new = s.replace(" ","")
    return s_new


def anagramSolution2(s1,s2):
    alist1 = list(deleteSpaces(s1))
    alist2 = list(deleteSpaces(s2))

    print(alist1)
    print(alist2)

    alist1.sort()
    alist2.sort()

    pos = 0
    matches = True

    while pos &lt; len(deleteSpaces(s1)) and matches:
        if alist1[pos]==alist2[pos]:
            pos = pos + 1
        else:
            matches = False

    return matches
</code></pre>

<p>Firstly I thought that the problem lies in working with spaces, but then I understood that my algorithm doesn't work if the strings are not the same size.</p>

<p>I have no idea what to do in that case.</p>

<p>Here I found a beautiful solution, but it doesn't work either:</p>

<pre><code>def anagrams(s1,s2):
    return [False, True][sum([ord(x) for x in s1]) == sum([ord(x) for x in s2])]
</code></pre>

<p>If I run this function and test it on two strings, I'll get such output:</p>

<pre><code>Examples:

First Word: apple
Second Word: pleap

output: True

First Word: Moon starter
Second Word: Astronomer

output: False //however it should should be True because this words are anagrams 
</code></pre>