Python - Get the second latest file from a file pattern

Solution 1:

You could sort list_of_files, then use index [-2], to get the second last item:

list_of_files = glob.glob('/tmp/*.json')
latest_file = sorted(list_of_files, key=os.path.getctime)
print(latest_file[-2])