I've got a list of times and a current time. I'm trying to find the closest and furthest time to the current time. I find it difficult to solve such tasks in strings.
However, I can print the minimum and maximum time in the list of strings using min and max functions.
I saw @kennytm posting a similar solution to the problem using:
min(myList, key=lambda x:abs(x-myNumber))
, but I'm not entirely sure if that works on strings.
Can anyone provide a solution to my question?
current_time = '09:00'
time = ['09:30','11:50','11:55','11:55','12:00','12:10','12:15','12:25','12:35','12:50','12:55', '13:00']
print(min(time))
# 09:30
print(max(time))
# 13:00