Python: Named tuples

I've been trying to print a list of the book titles within the named tuple in alphabetical order, but I don't know what I'm doing wrong. I've set up my named tuple as so:

Book = namedtuple('Book', 'author title genre year price instock')
# Book attributes: author, title of book, category of book, year of publication, and number of copies available
BSI = [
Book('George Orwell', 'Animal Farm', 'Fiction', 1945, 9.99, 21),
Book('J.K. Rowling', 'Harry Potter and the Deathly Hallows', 'Fantasy', 2007, 24.26, 32),
Book('J.R.R. Tolkien', 'The Fellowship of the Ring', 'Fantasy', 1954, 10.87, 26),
Book('Toni Morrison', 'The Bluest Eye', 'Fiction', 1970, 11.02, 13),
Book('Ernesto Galarza', 'Barrio Boy', 'Autobiography', 1971, 13.50, 23),
Book('Stephen Chbosky', 'The Perks of Being a Wallflower', 'Fiction', 1999, 8.01, 25)]

And I'm trying to create several statements that will print the titles in alphabetical order without affecting the original order of the list. So far I've been trying to play around with this:

for Book.title in BSI:
print(sorted(Book.title))

I've tried several other ways, but I've had no luck. Please explain my mistake, I'd like to know what I'm doing wrong. Thanks!

  1. 👍 0
  2. 👎 0
  3. 👁 198
  1. Nevermind, figured it out! :D

    1. 👍 0
    2. 👎 0

Respond to this Question

First Name

Your Response

Similar Questions

  1. English

    Which of the following is used for titles of subdivisions of published works, such as chapters of a book? A. Quotation marks B. Underline C. Italics D. Bolded text D

  2. math

    The cost of printing the first fifteen hundred copies of a book is $1500. It costs y dollars to print each subsequent copy. The cost of printing the first 7500 copies of the book is $7080. Find Y. Please explain how to solve it.

  3. STUDY UNIT: THE PRINTED WORD

    Which one of the following items would be most likely to have a list of chapter titles? A. A magazine B. A novel C. A newspaper D. An article

  4. algebra

    does any body hav the fith grade math note book if so can u give me a web site at the backof the book to go to if i need to go online and getthe pge and print it of something

  1. Programming Using Raptor

    How do i program this into Raptor Language? print "What is the cost of the item?" input cost if ((cost >= 0) && (cost < 20)){print "The shipping is $2.95."} if ((cost >= 20) && (cost < 50)){print "The shipping is $3.95."} if

  2. Web Design

    Ernesto is designing a website and a printed flyer. He needs the colors to match as closely as possible. How can he make sure they do? A).print out a screenshot of the website to match to the flyer B).use a reference color swatch

  3. programming

    Design a class named Book that holds a stock number, author, title, price, and number of pages for a book. Include a method that sets all the data files and another that prints the values for each data field. Create the class

  4. early childhood

    When children do print alphabet letters among the easiest to print are a. A and X b . O and L c. C and U d. S and M is b correct

  1. grammar

    do you underline book titles? or put them in quotes?

  2. Computer Science

    Can anyone please write a basic c++ code for the following instructions? Congratulations! You’ve been hired by the Fly-By-Night-Engineering-Company, Your new supervisor asks you to write a C++ program that will manage a list of

  3. Math

    A framer at a photo gallery wants to frame a print with a matte of uniform width all around the print. To make it pleasing to the eye, the area of the matte should equal the area of the print. If the print measures 40 cm by 60 cm,

  4. Math

    Four good friends, who love cats, have each named their cat after one of the other friends. Of the clues that follow, only one is true; the others are false. Which friend owns which cat? a.Candy’s cat is named either Dody or

You can view more similar questions or ask a new question.