In Python, you can use the sorted() function and the all() function to check if a list is already sorted in ascending or descending order. Here's an example:
listtimestamps = [1, 2, 3, 5, 6, 7]
def is_sorted(lst):
return lst == sorted(lst) or lst == sorted(lst, reverse=True)
print(is_sorted(listtimestamps)) # Output: True
The sorted(lst) function returns a sorted version of the list in ascending order, while sorted(lst, reverse=True) returns a sorted version in descending order. By comparing the original list with both sorted versions using lst == sorted(lst) and lst == sorted(lst, reverse=True), you can determine if the list is sorted in either ascending or descending order. The is_sorted() function returns True if the list is sorted and False otherwise.
In the example above, is_sorted(listtimestamps) returns True since the listtimestamps list is sorted in ascending order.