1001 Books You Must Read Before You Die - Part 2
|
I just couldn't leave it alone. I had to keep scratching at it, like a festering wound. |
I knew from the Amazon reviewers that Ian McEwan had eight books on the list. I was curious to know who the other multi-book authors were. First of all, I grabbed the list, cleaned it up and saved it as a text file.
I then wrote a small Python script to read in that text file and determine two things:
- The number of authors that had more than one book listed.
- For each of those authors, exactly how many books they had listed.
Here's the code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Change to False to print a book list alphabetically by author.
printSummary = True
authors = {}
bookFile = open("1001Books.txt", "r")
while 1:
line = bookFile.readline()
if not line:
break
tokens = line.split("–")
authorString = tokens[1].lstrip().rstrip()
title = tokens[0].split(".", 1)[1].lstrip().rstrip()
# Adjust author string so last name comes first.
tokens = authorString.split()
author = tokens[len(tokens)-1]
if len(tokens)-1 > 0:
author = author + ", " + " ".join(tokens[0:len(tokens)-1])
if authors.has_key(author):
authors[author].append(title)
else:
authors[author] = [ title ]
if printSummary:
# ------ Print summary of multi-book authors ------
noOfBooks = {}
for author in authors.keys():
total = len(authors[author])
if total > 1:
if noOfBooks.has_key(total):
noOfBooks[total].append(author)
else:
noOfBooks[total] = [ author ]
print "Number of authors: ", len(authors), "\n\n"
keys = noOfBooks.keys()
keys.sort()
for key in keys:
print "Authors with ", key, " books: "
noOfBooks[key].sort()
for i in range (0, len(noOfBooks[key])):
print " ", noOfBooks[key][i]
print
else:
# ------ Print book list alphabetically by author -----
keys = authors.keys()
keys.sort()
for author in keys:
print author
titles = authors[author].sort()
for title in authors[author]:
print " %s" % title
Here's the results.
I actually took it one step further. If you set
printSummary = False
near the top of the script, it'll generate an alphabetical book list by author which you can then print out and easily use when you visit a bookstore. As they say on all the best cooking shows and to save you the trouble, I already have one prepared.
If I was to become even more obsessed with this and wanted to take it further, I'd wonder:
- How many of the authors here had had their books
nominated for the Man Booker prize.
- How much correlation there is between the 1001 Books publisher and the publishers of the authors who have the most number of books on this list.
But that's enough for now.
( Sep 16 2007, 10:09:59 AM PDT ) [Listen] Permalink Comments [6]












