April 14, 2024, 5:52 p.m. | Main

DEV Community dev.to


#Optimized bubble sort
def bubble_sort(lst):

swapped = True
c = 0
while swapped == True:
swapped = False
for j in range(len(lst)-1):

if(lst[j]>lst[j+1]):
lst[j], lst[j + 1] = lst[j + 1], lst[j] #swap the elements
swapped = True
c +=1
return c

#sort a list
L = [9, 0, 2, 1, 0, 1, 100, -2, 8, 7, 4, 3, 2]

bubble_sort(L)
print("The sorted list is: ", L)

Bubble sort is the most basic sorting algorithm. Its simplicity makes it suitable …

bubble false list python true

Data Architect

@ University of Texas at Austin | Austin, TX

Data ETL Engineer

@ University of Texas at Austin | Austin, TX

Lead GNSS Data Scientist

@ Lurra Systems | Melbourne

Senior Machine Learning Engineer (MLOps)

@ Promaton | Remote, Europe

Senior Data Engineer

@ Quantexa | Sydney, New South Wales, Australia

Staff Analytics Engineer

@ Warner Bros. Discovery | NY New York 230 Park Avenue South