In this assignment you will practice writing Python command-line utilities, file I/O, processing XML files, and using Python data structures.
You’re developing a book selling web site. You receive book data in XML format, like books.xml
, and produce various reports about the books you sell.
Write a module called books.py
with the following functions:
def titles(books):
"""Extract the titles the books XML node and return them in a list.
Parameters:
books: xml.etree.ElementTree books node
Return:
list[str] -- all the authors of the books in the books node
"""
def book_authors(books):
"""Return a dictonary the authors of the books in the books XML node.
Parameters:
books: xml.etree.ElementTree books node
Return:
dict[str, list[str]] -- dictionary mapping book titles to lists of of the books'
authors
"""
def authors_book(books):
"""Return a dictonary the books written by the authors in the books XML node.
Parameters:
books: xml.etree.ElementTree books node
Return:
dict[str, list[str]] -- dictionary mapping authors to lists of of their books
"""
Use the functions above and the books.xml
file to do things like: