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
Post a Comment