Q15Single correct3 Marks28 Apr 2024
A library maintains a database of book records in the form of a list of dictionaries. Each dictionary represents a book and contains the following keys: title, author, pages. The database is stored in the list records. Write a function named get_longest_book that accepts the list records as argument and retrieves the book with the most pages from the database. The function should return a dictionary containing the details of the longest book. You can assume that the longest book is unique, that is, there is exactly one book with the most number of pages in the list. Which of the two snippets is correct?
# Snippet-1
```
# Snippet-1
def get_longest_book(records):
max_pages = 0
for record in records:
if record['pages'] > max_pages:
max_pages = record['pages']
return max_pages
# Snippet-2
def get_longest_book(records):
max_pages = 0
for record in records:
if record['pages'] > max_pages:
max_pages = record['pages']
for record in records:
if record['pages'] == max_pages:
return record
```