Computer science: Python: let’s sort a list.

Self-tutoring about computer science: the tutor mentions the sort() method in Python.

Python lists can be sorted using the_list.sort(). However, it might not work the way one would first think.

the_list.sort() rewrites the_list in sorted order. However, it doesn’t return a value. Therefore, print(the_list.sort()) won’t print anything, except perhaps “None.”

To print the sorted list using the_list.sort() one might do this:

the_list.sort() #the_list now sorted

print(the_list) #prints the_list

Source:

programiz.com

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply