Bubble sort in Python

・ Execution environment

name version
Python 3.7.1

The source code is as follows.

src = [3, 5, 1, 8, 5, 9]
print(src)

for i in range(len(src)-1):
    for j in range(len(src)-1-i):
        if src[j] > src[j+1]:
            tmp = src[j]
            src[j] = src[j+1]
            src[j+1] = tmp

print(src)

The execution result is as follows.

[3, 5, 1, 8, 5, 9]
[1, 3, 5, 5, 8, 9]

Thank you for reading until the end. Let's meet again.

Recommended Posts

Bubble sort in Python
Custom sort in Python3
Implemented Stooge sort in Python3 (Bubble sort & Quicksort)
Naturally sort Path in Python
[Python] Sort
python in mongodb in descending sort
Python # sort
Python beginners organize bubble sort
Bubble sort
Bubble sort
Sort by date in python
Sort large text files in Python
Implemented bubble sort in Java (BubbleSort)
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Implemented the algorithm of "Algorithm Picture Book" in Python3 (Bubble Sort)
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
When specifying multiple keys in python sort
New in Python 3.9 (2)-Sort directed acyclic graphs in Python
Sorted list in Python
Daily AtCoder # 36 in Python