Computer Science
What is the difference between sort( ) and sorted( )?
Python List Manipulation
32 Likes
Answer
sort( ) | sorted( ) |
---|---|
It modifies the list it is called on. That is, the sorted list is stored in the same list; a new list is not created. | It creates a new list containing a sorted version of the list passed to it as argument. It does not modify the list passed as a parameter. |
It works on a list and modifies it. | It can take any iterable sequence type, such as a list or a tuple etc, and it always returns a sorted list irrespective of the type of sequence passed to it. |
It does not return anything (no return value). It modifies the list in place. | It returns a newly created sorted list. It does not change the passed sequence. |
Answered By
17 Likes
Related Questions
What do you understand by true copy of a list? How is it different from shallow copy?
What is the difference between appending a list and extending a list?
Do functions max( ), min( ), sum( ) work with all types of lists.
An index out of bounds given with a list name causes error, but not with list slices. Why?