Apr-22-2024, 05:43 AM
Of course you must compare things which are comparable.
from string import ascii_lowercase from random import choice, randint mylist1 = [choice(ascii_lowercase) for i in range(5)] mylist2 = [i for i in ascii_lowercase] mylist3 = [randint(1,10) for i in range(10)] mylist4 = [i for i in range(10)] def is_sorted(alist): for i in range(1, len(alist)-1): # exit as soon as the condition is not true if not alist[i-1] <= alist[i] <= alist[i+1]: return False return True