"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>You're almost double printing the list so to speak. You don't want to print in the function since you're already calling <code>print</code> right after it. Instead you'll want to <code>return</code> the list and then have the <code>print</code> function print the returned list when you call <code>lensort</code>. </p>

<p>Here's a corrected version that should hopefully clarify what I mean: </p>

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

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

python sorting