Code from (or inspired by) the book Dive Into Python3