20th Jun 2017, 10:35 AM
looper
looper - avatar
7 Antworten
+ 7
You should use print(sorted(a)). a.sort() just executes the sorting, it does not return any value, that's why None is printed.
20th Jun 2017, 10:39 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
Here it proves people of this community. Likes only the answers of experienced person
21st Jun 2017, 5:02 AM
Keep in mind 😎
Keep in mind 😎 - avatar
+ 6
@Keep in mind. Your answer wouldnt have gotten as much exposure as Kubas as it was a good 10 hours after the question was asked. That said, search likestorms here in the q and a.
21st Jun 2017, 5:13 AM
jay
jay - avatar
+ 6
On top what @Keep wrote, you may try the below to see what the difference is between .sort() and sorted() a=[4,2,6,1] print(a) a.sort() print(a) print() b=[4,2,6,1] print(b) print(sorted(b)) As you can see .sort does its job in-place, but returns None. sorted(b) returns the sorted list, but does not change the list itself.
21st Jun 2017, 5:26 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
Yes right sir I get it thanks.
21st Jun 2017, 5:33 AM
Keep in mind 😎
Keep in mind 😎 - avatar
+ 5
You should do like this. a=[4,2,6,1] a.sort() print (a) Now it will print the sorted no
20th Jun 2017, 9:45 PM
Keep in mind 😎
Keep in mind 😎 - avatar
+ 5
Thanks #sir kuba My answer is also correct
21st Jun 2017, 5:09 AM
Keep in mind 😎
Keep in mind 😎 - avatar