I am given an assignment, where the input will be a list and my task is to bubble sort the list to ascending order. Here's a sample input and output that I want.
Input:
45 22 34 79 23
Output:
22 45 34 79 23
22 34 45 79 23
22 34 45 79 23
22 34 45 23 79
22 34 45 23 79
22 34 45 23 79
22 34 23 45 79
22 34 23 45 79
22 23 34 45 79
22 23 34 45 79
However I tried a piece of code but it didn't work, the I tried:
l = list(map(int, input().split()))
swapped = True
while swapped:
swapped = False
for i in range(len(l) - 1):
if l[i] > l[i + 1]:
l[i] , l[i + 1] = l[i + 1], l[i]
swapped = True
print(*l)
I just wanted to know the python code and explanation of the code that could provide me result exactly like the output in assignment.