python difference between sort and sorted

Solutions on MaxInterview for python difference between sort and sorted by the best coders in the world

showing results for - "python difference between sort and sorted"
Jak
06 Jul 2016
1# The sort() function will modify the list it is called on. 
2# The sorted() function will create a new list 
3# containing a sorted version of the list it is given.
4
5list = [4,8,2,1]
6list.sort()
7#--> list = [1,2,4,8] now
8
9list = [4,8,2,1]
10new_list = list.sorted()
11#--> list = [4,8,2,1], but new_list = [1,2,4,8]
12
Edgar
12 Apr 2018
1The primary difference between the list sort() function and
2the sorted() function is that the sort() function will modify
3the list it is called on. The sorted() function will create a 
4new list containing a sorted version of the list it is given.
5... The sort() function modifies the list in-place and has no return value.
queries leading to this page
sorted function in pythondifference between sorted and sort in pythonstring slicing after sort python now workingpython sorted vs sort performancesorted 28 29 vs sort pythonsort vs sorted in python difference between sort and sorted 3fpython sort and sorted differencedifference between sort and sorted in pythosort vs sortedpython return sorted listpython sort vs sorted list reverse orderlist sort vs sorted pythonpython sort lambdapython how works sortwhats the difference between sort and sortedpython cut sorted list by valuehow to limit the sort in pythondifference sort sorted pythonpython sorted 28 29 vs sorted 28 29sort vs sorted in pythonsorted python with different typessort list by the difference between valuesnot list but sortedsorted vs sort pythonpython difference between sort and sortedsort vs sorted method in pythonpython copy sorted directory list sort vs sortedsorted means in pythonwhat is the difference between sorted and sort in pythonpython sortlist sort vs sortedpython sorted list typedoes sorted sort set pythonsort vs sorted python 3sorted in pythonhow to sorting in python workssort 28 29 vs sorteduse sort in pythonsort list and store in pythonpython sort vs sortedsorted vs list sortpython sort sorted differenceordy by pythonsort and sorted in pythowhat is python sort orderdifferences between sort 28 29 and sorted 28 29 in python sort 28 29 vs sorted 28 29how to use sorted in pythonpython sort list and returnsorted vs sort pythonsort 28a 2cb 29 pythoncorrect order pythondifference between sort and sorted 28 29difference between sort 28 29 and sorted 28 29python sort sortedsorting function from the end of list to the beginningdifference between sort and sorted in pythonsorting in python 5b 3a 2c 1 5dsorted function vs sort function in pythonpython2 python3 sorted none problemsorted python vs sorthow to import sort in pythonpython sort vs sorted listpython sort and sortedrules for sorting pythonsort vs sorted pythonhow to sort string pythonsort and sorted in pythonpython sort vs sorted 3flist sort 28 29 vs sorted pythonwhat is the difference between sort and sorted in pythonsort and order pythonpython sort vs sortedsorted 28 29 difference with sort 28 29 in pythoncompare and return ordered string in pythonsorting values in a list via method pythonsort sorted pythonsorted more than one variableexamples python sort or sorted pythonsorted python descendingsort 28 29 vs sorted 28 29help sorted pythonpython sirt vs sortedpython a sort and sort 28a 29python sorted vs sortpython sort 28 29 vs sorted 28 29sorted key by highest numberpythonpython sorting vs sortwrite two disadvantages of sort 28 29 function over a list pythonset is sorting my vaules by default pythonsorted 28 29 vs sort 28 29sorted and sort in pythonpython sortedsort 28 29 vs sorted 28 29 pythonpython sort vs sortedsorted pythonpython copy sorted listdifference between sort 28 29 and sorted 28 29 in pythonsort and sorted pythonsorted 28 29 pythondifference between sorted and sort pythonsorted or sort pythonsorted vs sort in pythonhow do i sort 1 10 in pythonhow efficient is sorted pythonpython sort other than sort 28 29python sorted 28 29 vs sort 28 29sorted 28 29 vs sort 28 29 pythondiff between sort and sorted in pythonpython difference sort and sorteduser defined function to sort number in pythondifference sort and sorted pythonsorted vs sort python outputsort vs sorted in pysorted a python list by value which has valuespython list sort vs sortedsort float by spliyt jojinwhat is difference between sort and sorted in pythonstring sort vs string sorted python sort vs sortedpython sort 28 29 vs sortedsort data in standard output pytis sorted pythonpython sort lambda integerwhat is the difference of sort and sorted functions in python 3python sort orderpython sorted vs list sortpython orderedpython difference between sort and sorted