Working With Data
Thomas J. Kennedy
1 The Problem
In an earlier assignment… I referenced Isaac Asimov and J.R.R. Tolkien with specific note of their grammatical prowess.
Suppose we have a list of tuples in the form…
(Author, Title, Series, # in Series)
where
Series
isNone
if a book is not part of a series# in Series
is0
if a book is not part of a series
We will use the following convention for numbering:
-
0
represents the first book in a series -
n
is then-th
sequel, e.g.,1
would be the first sequel in a series -
-m
is them-th
prequel where-m
is based on in-universe chronology (e.g.,-2
would take place before-1
and-1
would take place immediately before the0
book).
We would like to provide the following search and filter options:
-
Output all books written by a single author
-
Output all books in a given series, in series order
-
List all authors in descending order by number of series written
-
List all authors in descending order by number of books written
-
Output the zeroth book in a series
-
Output the top author based on number of books written
1.1 Input
This subsection will describe the input content, format, and overall structure.
Isaac Asimov, Prelude to Foundation, Foundation, -2 Isaac Asimov, Forward the Foundation, Foundation, -1 Isaac Asimov, Foundation, Foundation, 0 Isaac Asimov, Foundation and Empire Foundation, 2 Isaac Asimov, Second, Foundation Foundation, 3 Isaac Asimov, Foundation's Edge, Foundation, 4 Isaac Asimov, Foundation and Earth, Foundation,5 Frank Herbert, Dune, Dune, 0 Frank Herbert, Dune Messiah, Dune, 1 Frank Herbert, Children of Dune, Dune, 2
Just in case you are wondering… I am a big fan of Isaac Asimov’s Foundation series and Robots series. Dune… is next on that list.
1.2 Output
T.B.W.
2 Your Tasks
You tasks are to implement the following functions…
-
get_all_books_by_author
which takes the list of books and returns an iterable (e.g.,list
) that contains only the books written by that author. -
get_all_books_by_series
which takes the list of books and returns an iterable (e.g.,list
) that contains only the books written by that series. -
get_zeroth_book
which takes a list og books and a series and returns the zeroth book in that series.
3 Mechanics
You can run the main program with…
python3.11 manage_books.py
The test code can be run with…
python3.11 -m pytest -v tests
4 Files
There are two (2) files in this assignment:
manage_books.py
test/test_manage_books.py
You will be working in manage_books.py
. Do not modify the other files.
You can access the starting files on GitHub. You may either clone the starting repository (through Git) or download a zip file.
5 Grading
Your grade will be based on the following criteria…
- test 000 - code passes
test_get_all_books_by_author
- test 001 - code passes
test_get_all_books_by_series
- test 002 - code passes
test_get_zeroth_book
6 Submitting
You will submit your completed copy of manage_books.py
as a file upload through Canvas.
Do not alter any of the other source code files, nor change the module interface.