python - problems sorting a list elements -


in python found these 2 pieces of code quite weird:

mylist = list (str (2132)) mylist. sort () print mylist  >>> ['1','2','3','4'] 

and

print (list (str (2132))). sort()  >>> none 

what difference?

it yields none inclusive when declare variable this:

mylist = list (str (2132)).sort () 

it seems sort() works in precise way

in python, sort() list method sorts list in-place , returns none, while sorted() returns sorted copy of collection without changing original;

>> = [4,5,3] >> sorted(a) [3, 4, 5]  >>  [4, 5, 3]  >> a.sort() >> [3, 4, 5] 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -