sorted vs sort python

The primary difference between the list sort() function and
the sorted() function is that the sort() function will modify
the list it is called on. The sorted() function will create a 
new list containing a sorted version of the list it is given.
... The sort() function modifies the list in-place and has no return value.

4.4
5
Stephen M 135 points

                                    # The sort() function will modify the list it is called on. 
# The sorted() function will create a new list 
# containing a sorted version of the list it is given.

list = [4,8,2,1]
list.sort()
#--> list = [1,2,4,8] now

list = [4,8,2,1]
new_list = list.sorted()
#--> list = [4,8,2,1], but new_list = [1,2,4,8]

4.4 (5 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
python difference sort and sorted python sort() vs sorted python sort vs sorted? sort vs. sorted in python sort vs sorted method in python python sort vs sorted .Difference between sort and sorted? sort vs sorted in py what is the difference of sort and sorted functions in python 3 what is the difference between sort and sorted in python sort() vs sorted() python sort () vs sorted what is difference between sort and sorted in python .sort vs sorted list sort vs sorted sorted vs sort python output sort vs sorted difference between sort() and sorted() in python sorted() vs sort() difference between sorted and sort python python sort sorted difference sorted python sorted vs list.sort python sort and sorted difference sorted vs sort in python difference between sort and sorted in pytho sorted() difference with .sort() in python difference between sort() and sorted() sorted function vs sort function in python help sorted python how to import sort in python sorted means in python sorted function in python sorted() python python sorted how efficient is sorted python sorted python descending sorted in python python copy sorted directory how to limit the sort in python sorted more than one variableexamples python string slicing after sort python now working correct_order python how to use sorted in python sort float by spliyt jojin sorted vs .sort python sorting in python [:, 1] .sort or sorted python is sorted python what is the difference between sorted and sort in python python list sort vs sorted not list but sorted whats the difference between sort and sorted python sorted() vs .sort() list.sort vs sorted python ordered write two disadvantages of sort( ) function over a list python how to sort string python python return sorted list python sort list and return sort(a,b) python sort list by the difference between values sorted or sort python sorting function from the end of list to the beginning python sorted vs list.sort sorted a python list by value which has values sort and sorted python sorting values in a list via method python python sorted() vs .sorted() what is python sort order user defined function to sort number in python python sort vs sorted list reverse order python sort vs sorted list python how works sort sort and sorted in pytho sorted key by highest numberpython python copy sorted list python sort sorted string.sort vs string.sorted python rules for sorting python .sort() vs sorted() difference sort and sorted python sort data in standard output pyt python .sort order python difference between sort and sorted sort sorted python python cut sorted list by value difference sort sorted python python sirt vs sorted ordy by python how to sorting in python works python2 python3 sorted None problem sorted() vs sort() python does sorted sort set python set is sorting my vaules by default python how do I sort 1-10 in python sorted and sort in python python a.sort and sort(a) python sort other than sort() python sort and sorted python sorted list type sorted python vs sort python .sort vs sorted compare and return ordered string in python difference between sort and sorted in python sorted() vs .sort python sort vs sorted in python sort list and store in python python sort vs sorted sorted python with different types use sort in python sort() vs sorted() sort and sorted in python python sort lambda integer sort and order python python .sort python sort lambda python sorted vs sort performance python sorted vs sort list.sort() vs sorted python difference between sorted and sort in python diff between sort and sorted in python sort vs sorted python 3 sort vs sorted python sorted vs sort python
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source