Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 18789

fast bubble sort

$
0
0
def bubble(lst):    swap = 'True'    counter = 0    n = len(lst)    m = len(lst)    while swap == 'True':            for j in range(n-1):                    if lst[j] > lst[j+1]:                            lst[j],lst[j+1] = lst[j+1],lst[j]                            counter += 1                            swap = 'True'                    else:                            swap = 'False'            n = n - 1    return counter

How do I shorten the time this function takes because I want to use it on a larger list.


Viewing all articles
Browse latest Browse all 18789

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>