You are viewing a single comment's thread. Return to all comments →
You can use sort() it is efficient than sorted() as it does in-place sorting. They used sorted, so that they write it in lesser number of characters.
sort() returns None whereas sorted() returns the newly created list.
Using sort() :
nums.sort() #here in-place sorting takes place
'set' object has no attribute 'sort'
^ This. The set function doesn't create a list, and sets don't allow for the sort attribute. Using sorted() converts the data into a list, then sorts it.