def is_sorted(lst): for i in range(len(lst) - 1): if lst[i] > lst[i + 1]: return False return True my_list = [1, 2, 3, 4, 5] print(is_sorted(my_list)) my_list = [1, 3, 2, 4, 5] print(is_sorted(my_list))
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