+ 2

What is the difference between sort and sorted ?

Sort() Sorted()

31st May 2020, 12:08 PM
Nithish
Nithish - avatar
6 Answers
+ 8
The difference of sort() and sorted() in short words: sort() - using sort() will change (sort) the passed list to the function inline, that mean that the original list will be sorted. sort() only works for lists. sorted() - using sorted() will take any iterable (list, tuple, string, dict), not only list, and will return a new sorted iterable.
31st May 2020, 12:26 PM
Lothar
Lothar - avatar
+ 5
Nithish Helper for lists. It's only start for me after your question:) https://code.sololearn.com/c9jF0Ha9oCio/?ref=app
31st May 2020, 7:08 PM
Petr
+ 4
list.sort() - Sorts the list. sorted(list) - Returns a sorted copy of the list.
31st May 2020, 1:05 PM
Seb TheS
Seb TheS - avatar
+ 3
Thanks kiibo It is very easy to understand
31st May 2020, 12:15 PM
Nithish
Nithish - avatar