+ 1

Sorted() vs sort()

Can someone give me the difference between Sorted() and sort() with any suitable example.

10th Sep 2021, 9:46 AM
MOREL
MOREL - avatar
3 odpowiedzi
+ 8
MOREL , ▪︎sort() is a method of the list class, so working for lists only. the sorting is done in-place, no new list will be created. ▪︎sorted() is a builtin function, that can work as already mentioned from raynard , and also can be used with strings. the result of this operation is a list with individual characters, that are sorted. sorted() always creates a new resulting iterable of data type list. ▪︎using search in sololearn is ok, but we have to keep in mind: => the results of a search are NOT verified answers. we can find results that are true or half true or also may be wrong. also some assumptions can be found. if you have not enough of experience, you can get confused
10th Sep 2021, 11:09 AM
Lothar
Lothar - avatar
+ 2
MOREL sort can only sort a list, sorted can be used to sort any iterables like dictionaries,tuples,list etc.
10th Sep 2021, 9:52 AM
raynard
raynard - avatar