It's crucial to remember to get rid of the implicit \n character from lines as you read them in, as well as strip any whitespace from words after you've split on the comma.
I don't think you are building your dictionary of stresses correctly. This is what I have so far: import string Sorry if this is a convoluted or messy question. I would like it so that it only prints sentences which are iambic pentameters. The first sentence will be assigned from the stress dictionary like this: 0101010101, and the second is obviously not a pentameter( 011).
I am trying to get sentences from a text file which have multiple sentences, and to see if the sentence (ignoring punctuation and case) is an iambic pentameter.įor example if the text file contains this: If music be the food of love play on So I need to get some words and their stress patterns from a text file that look somewhat like this: if, 0Īnd from the file, you can assume there will be much more words for different sentences. I am kind of stuck on a question that I have to do regarding iambic pentameters, but because it is long, I'll try to simplify it.