Zendesk Guide needs a small in-memory book catalog that supports predictable browsing and checkout processing. Given a list of books, sort them by title or author, then process checkout requests in order.
Implement a function that returns the sorted catalog, the IDs successfully checked out, and the IDs that could not be checked out because the book was already unavailable.
Implement process_books(books, sort_by, checkout_ids).
books is a list of dictionaries. Each dictionary contains:
id: a unique stringtitle: a stringauthor: a stringavailable: a booleansort_by is either "title" or "author".checkout_ids is a list of book IDs processed from left to right.books: the catalog sorted by the selected field, then by title, then by IDchecked_out: IDs successfully checked outunavailable: IDs rejected because they were already checked outThe input list must not be modified. A repeated checkout request for the same book is rejected after its first successful checkout.
sort_by is either title or authordef process_books(books, sort_by, checkout_ids):