School Revise · Class 11 Computer Science · Chapter 5
Code 083, Class 12. Sorting arranges items in order. Here we use built-in sorting and build a simple bubble sort of our own.
|
|
Sorting puts items in order, smallest to largest or A to Z. Python can sort for us, and we can also write our own sort to see how it works.
list.sort() sorts the list itself, and sorted(list) returns a new sorted list. Add reverse=True for descending order.
|
nums = [3, 1, 2] nums.sort() print(nums) Output: [1, 2, 3] |
Bubble sort compares each pair of neighbours and swaps them if they are in the wrong order, passing through the list again and again until it is sorted.
Sorting makes data easy to read and lets us search it quickly, for example arranging marks from highest to lowest, or names in order.
Explore the idea by tapping. The interactive opens right here in the lesson.
Write and run real Python right here in the lesson, then work through the practice problems with answers.
Type each one into the code lab above, then open the card to see the worked solution and its output.
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
SOLUTION
OUTPUT
sort().
sorted().
Sorts in descending order.
neighbouring items.
|
Sorting arranges items in order. list.sort() sorts in place and sorted() returns a new sorted list; reverse=True gives descending order. Bubble sort compares neighbours and swaps them if out of order, repeating until sorted. Sorting makes data readable and quick to search. |
| Open the Virtual Lab |
These free Class 12 Computer Science notes explain sorting, the built-in sort and sorted functions, ascending and descending order, and the bubble sort algorithm with worked examples and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.
© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 12 Computer Science syllabus. Unauthorised copying is not permitted.