Sorting a List - Lakelands Computing

Title
Go to content
Sorting a List
Putting a list in order can be a useful technique, and whilst there are various sorting algorithms you can program, python lists have a built in method for sorting.

  • subjects = ["maths", "music","english", "french", "biology", "art"]
  • subjects.sort()

This would put the list in alphabetical order, so ["art","biology","english","french","maths","music"]

You can also put a list in descending order:

  • subjects.sort(reverse=True)
All Text copyright Lakelands Academy & Mr T Purslow 2020.
All images copyright free / creative commons unless otherwise stated.
You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
Back to content