#Sort a list without using sort() def sort_list(nums): sorted_list = [] while nums: minimum = min(nums) sorted_list.append(minimum) nums.remove(minimum) return sorted_list numbers = [5, 3, 8, 2, 7] sorted_numbers = sort_list(numbers) print(f"Sorted list: {sorted_numbers}")
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter