Created
April 24, 2015 13:05
-
-
Save adampalay/c2f202a66051e3bc24b8 to your computer and use it in GitHub Desktop.
Shakespeare Names with Z
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:b853c79b722e44cd0f1910fba4a18876e5cb6ce3a1e4465b7f1f445fe7c095b6" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from lxml import etree\n", | |
"import os\n", | |
"play_directory = \"/Users/adampalay/projects/PlayShakespeare.com-XML/playshakespeare_editions\"\n", | |
"plays = []\n", | |
"for filename in os.listdir(play_directory):\n", | |
" with open(os.path.join(play_directory, filename)) as filehandle:\n", | |
" play = etree.fromstring(filehandle.read())\n", | |
" if play.tag == \"play\":\n", | |
" plays.append(play)\n", | |
"for play in plays:\n", | |
" play_title = play.find('title').text\n", | |
" for name in play.iterdescendants('persname'):\n", | |
" name_text = name.text\n", | |
" if \"z\" in name_text.lower() and \"citizen\" not in name_text.lower():\n", | |
" print play_title, \": \", name_text" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"The Comedy of Errors : Balthazar\n", | |
"The Comedy of Errors : Courtezan\n", | |
"Double Falsehood, or The Distressed Lovers : Lopez\n", | |
"Double Falsehood, or The Distressed Lovers : Henriquez\n", | |
"The Tragedy of Hamlet, Prince of Denmark : Both Rosencrantz and Guildenstern\n", | |
"The Tragedy of Hamlet, Prince of Denmark : Rosencrantz\n", | |
"The Tragedy of Hamlet, Prince of Denmark : Both Rosencrantz and Guildenstern\n", | |
"The Third Part of Henry the Sixth : Queen Elizabeth\n", | |
"The Famous History of the Life of King Henry the Eighth : Princess Elizabeth\n", | |
"The Tragedy of King Richard the Second : Lord Fitzwater\n", | |
"The Merchant of Venice : Lorenzo\n", | |
"The Merchant of Venice : Balthazar\n", | |
"Pericles, Prince of Tyre : Dionyza\n", | |
"The Tragedy of Richard the Third : Queen Elizabeth\n", | |
"The Tragedy of Richard the Third : Both Queen Elizabeth and Duchess of York\n", | |
"The Tragedy of Richard the Third : Both Queen Elizabeth and Duchess of York\n", | |
"The Tempest : Gonzalo\n", | |
"The Life of Timon of Athens : First Lady Amazon Masker\n", | |
"The Life of Timon of Athens : All Lady Amazon Maskers\n", | |
"The Life of Timon of Athens : All Lady Amazon Maskers\n", | |
"The Two Noble Kinsmen : Friz\n", | |
"The Winter\u2019s Tale : Florizel\n" | |
] | |
} | |
], | |
"prompt_number": 11 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment