2 ms·
It depends on you case. If you are doing: slist = list(mylist) #create new copy of the list slist.sort() #sort the list use_sorted_list(slist) The u
by sophacles 15y ago
It depends on you case.
If you are doing:
slist = list(mylist) #create new copy of the list
slist.sort() #sort the list
use_sorted_list(slist)
The use of sorted is more more convenient, and really doesn't use more memory (since the memory from that statement you quoted is for the list copy).
More usefully: sorted will take anything that is iterable, allowing you to write simpler code, rather than testing for various types and dealing with them in type specific ways.