'''
Learning outcomes:
1. Lists are mutable, meaning you can add, remove, or modify elements after creation.
2. They are ordered, so the elements are indexed and accessed by their positions.
3. Lists can contain any data type
'''
# Library of books [1....n]
# Where each book has: title, publication year, author, genre
# Create library using:
# 1. lists
library = [
# book 1
# title year author genre
["The Catcher in the Rye", 1951, "J.D. Salinger", "Fiction"],
# book 2
["To Kill a Mockingbird", 1960, "Harper Lee", "Classic"],
# ...
["1984", 1949, "George Orwell", "Dystopian"],
["The Great Gatsby", 1925, "F. Scott Fitzgerald", "Classic"],
["Harry Potter and the Sorcerer's Stone", 1997, "J.K. Rowling", "Fantasy"],
["The Hobbit", 1937, "J.R.R. Tolkien", "Fantasy"],
["Pride and Prejudice", 1813, "Jane Austen", "Romance"],
["The Hitchhiker's Guide to the Galaxy", 1979, "Douglas Adams", "Science Fiction"],
["The Da Vinci Code", 2003, "Dan Brown", "Mystery"],
# book n
["The Lord of the Rings", 1954, "J.R.R. Tolkien", "Fantasy"]
]
print("The length of the books: ", len(library))
print(type(library), type(library[0]))
updated_library = []
books = []
'''
new_book = []
new_book.extend([title, publication_year, author, genre])
'''
# every time I create a new book:
# book 1
new_book = []
title = "The Catcher in the Rye"
publication_year = 1951
author = "J.D. Salinger"
genre = "Fiction"
new_book.extend([title, publication_year, author, genre])
print("Added a new book with details: ", new_book)
# end of adding book steps
# add new book to the books list
books.append(new_book)
print(books)
# add books list to the library
updated_library.append(books)
# book 2
new_book = []
title = "To Kill a Mockingbird"
publication_year = 1960
author = "Harper Lee"
genre = "Classic"
new_book.extend([title, publication_year, author, genre])
print("Added a new book with details: ", new_book)
# end of adding book steps
# add new book to the books list
books.append(new_book)
print(books)
print("Updated library: ", updated_library)
# remove the latest added book:
removed_book = updated_library[0].pop()
# del updated_library[len(updated_library)-1]
print("I deleted the latest added book: ", removed_book)
print("The publication year of the first book before update: ", updated_library[0][0][1])
updated_library[0][0][1] = 1989
print("The publication year of the first book after update: ", updated_library[0][0][1])
# remove the whole list of books from library
del updated_library[0]
print(updated_library)