Final answer:
The Python program includes functions to delete duplicate book entries, sort books by cost in ascending order, count books costing more than 500, and copy books that cost less than 500 into a new list for a department library.
Step-by-step explanation:
Python Program for a Department Library Management
Here is a Python program that manages books in a department library, based on the operations you've specified:
# Define a list of books where each book is a dictionary
# containing 'title' and 'cost'
books = [
{'title': 'Book1', 'cost': 450},
{'title': 'Book2', 'cost': 500},
... # Add more books as needed
]
# a) Function to delete duplicate entries
def delete_duplicates(books):
return list({book['title']: book for book in books}.values())
# b) Function to display books in ascending order based on cost
def display_books_sorted_cost(books):
return sorted(books, key=lambda book: book['cost'])
# c) Function to count books with cost more than 500
def count_expensive_books(books):
return sum(1 for book in books if book['cost'] > 500)
# d) Function to copy books with cost less than 500
def copy_cheaper_books(books):
return [book for book in books if book['cost'] < 500]
# Example usage
books = delete_duplicates(books)
print('Books sorted by cost:', display_books_sorted_cost(books))
print('Number of expensive books:', count_expensive_books(books))
cheap_books = copy_cheaper_books(books)
print('Cheap books:', cheap_books)
Make sure to replace the '...' in the books list with actual book entries. The functions provided perform the operations of deleting duplicates, sorting books by cost, counting books more expensive than 500, and copying books that are cheaper than 500 into a new list.