"None" string appear after print a line in python
<p>I a new in python programming. Today I practice with sorting a list. 
I've got a strange output with this code:</p>

<pre><code># problem 13
def lensort(list):
   list.sort(key=lambda x: len(x))
   print list 

print "Sort by length: ", lensort(['python', 'perl', 'java', 'c', 'haskell','ruby'])
</code></pre>

<p>The output is: </p>

<pre><code>Sort by length:  ['c', 'perl', 'java', 'ruby', 'python', 'haskell']
None
</code></pre>

<p>So, I have no idea the reason why "None" is shown in 2nd line.
Could anyone help to about this problem?</p>

<p>Thank you very much!</p>

<p>The <code>.sort</code> method sorts a list in place. You do not return its return. Also, no <code>lambda</code> needed:</p>

<pre><code>&gt;&gt;&gt; li=['python', 'perl', 'java', 'c', 'haskell','ruby']
&gt;&gt;&gt; li.sort(key=len)
&gt;&gt;&gt; li
['c', 'perl', 'java', 'ruby', 'python', 'haskell']
</code></pre>

<p>If you want a new sorted list, use the <code>sorted</code> function:</p>

<pre><code>&gt;&gt;&gt; sorted(['python', 'perl', 'java', 'c', 'haskell','ruby'], key=len)
['c', 'perl', 'java', 'ruby', 'python', 'haskell']
</code></pre>

python sorting