I am trying to copy the names of books that are <2000 to a new list. But the problem is that it only copies “1984” and copies it as a separate character to the list, and does not copy all the names that it should have
from collections import namedtuple
Book = namedtuple('Book','author title genre year price instock')
BSI = [ Book('John Green', 'Paper Towns', 'Young Adult', 2008, 7.00, 200),
Book('Beverly Clearly', 'Ramona Forever', 'Children', 1924, 9.00, 150),
Book('Vladmir Nabokov', 'Lolita', 'Tragicomedy', 1958, 15.00 , 80),
Book('J.D. Salinger', 'Catcher in the Rye', 'Young Adult', 1951, 10.00, 130),
Book('George Orwell', '1984', 'Dystopia', 1949, 7.00, 300),
Book('Jeannette Walls','The Glass Castle','Memoir', 2006, 15.00 , 100)]
older_books = []
for books in BSI:
if (books.year<2000):
older_books=list(books.title)
print(older_books)
What should he infer
Ramona Forever
Lolita
Catcher in the Rye
1984