I am quite new in Python and I am starting my journey with sorting algorithms, PEP8 and the Zen of Python. I would like to get some feedback about my BubbleSort algorithm which I wrote.
Also, is there a possibility to change the break statement to something else which will stop the loop?
def bubble_sort(structure):
"""
Bubble sort.
Description
----------
Performance cases:
Worst : O(n^2)
Average : O(n^2)
Best case : O(n)
Parameters
----------
structure : Mutable structure with comparable objects.
Returns
-------
structure : return sorted structure.
Examples
----------
>>> bubble_sort([7,1,2,6,4,2,3])
[1, 2, 2, 3, 4, 6, 7]
>>> bubble_sort(['a', 'c', 'b'])
['a', 'b', 'c']
"""
length = len(structure)
while True:
changed = False
for i in range(length - 1):
if structure[i] > structure[i + 1]:
structure[i], structure[i + 1] = structure[i + 1], structure[i]
changed = True
if not changed:
break
return structure
break\$\endgroup\$breakstatment toreturn structureand delete the last linereturn structure. Will it harmonize with PEP8? \$\endgroup\$