Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Implementation of a bubble sort.
- # This code is syntactically correct, however there are a couple of
- # problems that prevent it from producing the desired output.
- # Find these errors and correct them, writing a comment explaining
- # what the error was.
- def swap_values(i1, i2, list_):
- list_[i1], list_[i2] = list_[i1], list_[i1]
- return list_
- def sort(values):
- for pass_num in range(1, len(values)):
- pass_size = len(values) - pass_num
- for i in range(pass_size + 1):
- if values[i] > values[i + 1]:
- values = swap_values(i, i, values)
- return values
- print sort([3, 45, 212, 31, 53, 4])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement