Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- def bubble_sort(unsorted):
- swapped = True
- sorted = unsorted[:]
- while swapped is True:
- swapped = False
- for item in range(len(sorted) - 1):
- if sorted[item] > sorted[item+1]:
- sorted[item], sorted[item+1] = sorted[item+1], sorted[item] #swaps position of list items
- swapped = True
- return sorted
- my_list = [1, 34, 9, 19,91,5,9,5,8,1,3]
- print("Unsorted List", my_list)
- print("Sorted List", bubble_sort(my_list))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement