Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python sorted vs sort

numbers = [2,3,5,10,1]
# sorted(numbers): creates a new list, without modifying the numbers list
# numbers.sort(): modifies the numbers list


sorted_numbers = sorted(numbers)
#--> numbers: 		 [2,3,5,10,1]
#--> sorted_numbers: [1,2,3,5,10]

numbers.sort()
#--> numbers: 		 [1,2,3,5,10]
Source by discuss.codecademy.com #
 
PREVIOUS NEXT
Tagged: #python #sorted #sort
ADD COMMENT
Topic
Name
4+7 =