DEV Community

Durga Pokharel
Durga Pokharel

Posted on

2

Day 16 of 100DaysofCode: A Simple Program To Do Bubble Sort

Today is my 16th day of #100Daysofcode. I learned more about python code to access web data including retrieving web page using urllib in python, parsing web page, web scraping on. Learned about BeautifulSoup and its important on coursera.

Learning sorting algorithms little at a time. First one is bubble sort. Attempt one challenge on Advent of Code 2020

Program To Do Bubble Sort

Bubble sort is a simple sorting algorithm that repeatedly step through the list, compare adjacent elements and swaps them if they are in a wrong order.

The pass through the list is repeated until the list is sorted. I tried to do one simple program on bubble sort which is given below.

# bubble sort
l1 = [2, 1, 4, 3, 5, 0]

def sort(l1):
    for i in range(len(l1)-1):
        for j in range(len(l1)-i-1):
            if l1[j]>l1[j+1]:
                l1[j], l1[j+1] = l1[j+1], l1[j]
    return l1
sort(l1)

Enter fullscreen mode Exit fullscreen mode

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay