---
title: "Sort a list without using sort() in python with explanation."  
description: "Sort a list without using sort() in python with explanation."  
author: "Anubhav Sharma"  
published: 2025-04-23  
updated: 2025-04-25  
canonical: https://www.mindstick.com/forum/161530/sort-a-list-without-using-sort-in-python-with-explanation  
category: "python"  
tags: ["python-3.4", "python"]  
reading_time: 2 minutes  

---

# Sort a list without using sort() in python with explanation.

#### Sort a list without using `sort()`

Implement [bubble sort](https://www.mindstick.com/forum/157933/write-a-program-to-sort-an-array-of-integers-using-the-bubble-sort-algorithm) or [selection sort](https://www.mindstick.com/forum/156066/how-does-a-selection-sort-work-for-an-array).

## Replies

### Reply by Khushi Singh

A [Python](https://www.mindstick.com/articles/338013/top-10-python-libraries-for-data-science-and-ai) list needs Bubble Sort implementation to achieve sorting even when not using sort() function. Bubble Sort functions through a straightforward approach that moves across the list sequence to check adjacent elements and swaps them when the first one is greater than the second. The sorting process continues until all elements reach their correct order in the list.

## Bubble Sort Explanation:

- The algorithm executes by checking adjacent pairs of elements and initiates an element swap operation for cases where the first element exceeds the second element.\
- Each time the list receives another pass the largest element rises to the position that matches its true value.\
- Following each round the algorithm applies to the unsorted part of the list the portion decreases in size until all elements are sorted.

## Code Example (Bubble Sort):

```python
def bubble_sort(arr):
   n = len(arr)
   for i in range(n):
       for j in range(0, n-i-1):
           if arr[j] > arr[j+1]:
               arr[j], arr[j+1] = arr[j+1], arr[j]
numbers = [64, 34, 25, 12, 22, 11, 90]
bubble_sort(numbers)
print("Sorted list is:", numbers)
```

## How It Works:

- The outer loop advances through the entire list to put every largest unsorted element in its correct position.\
- Inner loop: Compares each adjacent pair and swaps them if necessary. The largest element in each iteration moves toward the final position of the list.\
- Progressive speed-up of sorting occurs because the process reduces the number of elements that need to be checked when the largest item is placed in its final position.

## Output:

The sorted result sequence for the list [64, 34, 25, 12, 22, 11, 90] should appear as:

```plaintext
Sorted list is: [11, 12, 22, 25, 34, 64, 90]
```


---

Original Source: https://www.mindstick.com/forum/161530/sort-a-list-without-using-sort-in-python-with-explanation

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
