How to sort numbers in Python without sort function
The sort() is a built-in python function for sorting.
In this article, we will see how to sort number in Python without sort function.
def sort(l): for i in range(0, len(l)): for j in range(1 + i, len(l)): if l[i] > l[j]: temp = l[i] l[i] = l[j] l[j] = temp return l lis = [4, 5, 2, 8, 0, 7, 3, 6, 1, 9] sort(lis) print(lis)
Output:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Subscribe
Login
Please login to comment
0 Discussion