Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #week 3 bubble sort - first go
- my_list = [5,9,5,8,1,3]
- def bubble_sort(unsorted):
- sorted = unsorted[:]
- changed = True
- while changed:
- changed = False
- for i in range(len(sorted) - 1):
- if sorted[i] > sorted[i+1]:
- sorted[i], sorted[i+1] = sorted[i+1], sorted[i]
- changed = True
- return sorted
- print(my_list)
- print()
- a_list = bubble_sort(my_list)
- print(a_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement