'str' object has no attribute 'sort'
<p>I am quite new to python and was wondering if someone could help me fix a problem. Im making an anagram checker and have run into an issue. </p>

<pre><code>def anagram():
    worda = input("Please choose your first word:")     
    wordb = input("Please choose your second word:")
    if worda.isalpha():
        print((worda),"is a word")
    else:
        print((worda),"is not a word, please try again")      
        anagram()
    if wordb.isalpha():
        print((wordb),"is a word")         
    else:
        print((wordb),"is not a word,please try again")
        anagram()
    worda.sort
    wordb.sort    

anagram()
</code></pre>

<p>I get the error: AttributeError: 'str' object has no attribute 'sort'when I try to run it. </p>

<p>There is no property as <code>sort</code> or any <code>sort()</code> function with <code>str</code> in Python. For sorting the <code>str</code> you can use <a href="https://docs.python.org/2/library/functions.html#sorted" rel="nofollow"><code>sorted()</code></a> as:</p>

<pre><code>&gt;&gt;&gt; x = 'abcsd123ab'
&gt;&gt;&gt; sorted(x) # returns list
['1', '2', '3', 'a', 'a', 'b', 'b', 'c', 'd', 's']
</code></pre>

<p>If you need the result as sorted <code>string</code>, you need to explicitly <a href="https://www.tutorialspoint.com/python/string_join.htm" rel="nofollow"><code>join</code></a> it as:</p>

<pre><code>&gt;&gt;&gt; ''.join(sorted(x))
'123aabbcds' 
</code></pre>

python