The Workiva platform records recent access events for documents. Given a list of document records, return a new list ordered from most recently accessed to least recently accessed.
If two documents have the same last_access timestamp, order them by document_id in ascending lexicographic order. Do not modify the input list.
Implement sort_documents(documents), where documents is a list of dictionaries. Each dictionary contains:
document_id: a unique stringlast_access: an integer Unix timestampReturn a new list containing the same dictionaries in the required order. The original list and its dictionaries must remain unchanged.
def sort_documents(documents):