tegge-classroom / STAT2984-2018

STAT 2984: Statistical Programming I - Spring 2018
1 stars 13 forks source link

How to sort a list? #7

Open ategge opened 6 years ago

ategge commented 6 years ago

I have a list and I want to sort it. However, online there are two sort functions:

a = [1,4,3,5,7,6,8] sorted(a) a.sort()

What are the differences between these two functions?

cahicks commented 6 years ago

if you use a.sort() then the list will always be sorted throughout the rest of the code. If you use sorted(a) the code will be sorted for that next line, but you would have to continue to use the sorted(a) if you wanted to sort it again