我想选一本书的书名,然后按字母顺序列出一个新的书名
Book = namedtuple('Book', 'author title genre year price instock')
BSI = [Book('JK Rowling', 'Harry Potter', 'Fiction', 2009, 12.50, 10),
Book('Stephanie Meyer', 'Twilight', 'Fiction', 2007, 9.99, 1),
Book('Walter Isaacson', 'Steve Jobs', 'Technology', 2011, 35.00, 200),
Book('Albert Camus', 'The Stranger', 'Fiction', 1980, 15.99, 62),
Book('Shakespeare', 'Romeo and Juliet', 'Tragedy', 1597, 11.00, 13),
Book('Sake Jager', 'Language Teaching and Language Technology', 'Technology', 1998, 87.00, 27)]
对于BSI中的i: 打印(排序(i.title))
你可以使用
namedtuple
很好。在您对
sorted
的使用不正确。您需要通过提供key
参数对整个集合进行排序。在相关问题 更多 >
编程相关推荐