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:

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. 👁 74
  1. Nevermind, figured it out! :D

    1. 👍 0
    2. 👎 0
    posted by Student

Respond to this Question

First Name

Your Response

Similar Questions

  1. programming

    write a program that creates a list of employees objects of size n entered from user using list interface and a list class implementation and display all employees in list and print employee name with minimum salary and remove

    asked by moh on July 14, 2014
  2. 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

    asked by hazy on September 1, 2011
  3. Computing: Simple Python

    Hi this is the code I'm working on, but every time I run it, every character inputted is printed, so hello becomes 'h','e','l','l','o', even numbers! I can't seem to fix it so that it can be added to the list and printed normally,

    asked by Python on November 16, 2014
  4. English

    When I am handwriting the names of books and plays, do I underline them or put them in quotes? These are the works that I am writing: Tortilla Flat, The Grapes of Wrath, The Pearl. In handwriting, book titles will need to be

    asked by Anonymous on August 8, 2007
  5. English

    Which of the following items should not be underlined or put in italics? the Bible magazine titles works of art book titles works of art

    asked by christopher on April 25, 2010
  6. Data Analysis Help

    4. Cells must be __________ and the sheet protected to prevent edits being made to the data. locked secured formatted values 5. To print column and row headings on all pages, set the options in the __________ command in the Page

    asked by Bryan on July 26, 2009
  7. English

    I just need to know if I'm correct or not about something. I know book titles are italized or sometimes underlined, but I'm not sure which is more proper. I also know that episodes of TV shows and chapter titles of books are put

    asked by Kaytlin on August 23, 2012
  8. programming

    Design a class named Book that holds a stock number, author, title, price, and number of pages for a book. Include methods to set and get the values for each data field. Also include a displayInfo() method that displays each of

    asked by stephanie on March 30, 2013
  9. Python: Creating function

    The value of the inventory of a particular book is the price of that book times the number of copies we have in stock. Write a function called inventory_value that takes a Book as its argument and returns the value of our

    asked by Student on January 24, 2014
  10. algebra

    suppose you right a book. the printer charges $4 per book to print it, and you spend #3500 on advertising. you sell the book for $15 a copy. how many copies must you sell so that your income from sales is greater than your total

    asked by lille on September 14, 2011

More Similar Questions