Press "Enter" to skip to content

And Our Faces, My Heart, Brief As Photos

An acrostic poem generator using some existing peoms from And our faces, my heart, brief as photos by John Berger.

Inporting 4 different poems: Leaving, Waterfront, A Forest I Knew, and Factory by John Berger; then combine them as one list. Initially I started with only a single poem, but soon I realized that an acrostic generator requires an adequate amount of source text, especially because I’m collecting lines, not words.

Now the list contains all lines from four different poems. The following code checks the first letter [0] in each line, and creates a dictionary of lines in alphabetical order.

The dictionary is completed, although it’s still missing some letters (those ones won’t be available to form the poem). Then, set up a word that will be the seed: first letters of each line. Once the seed word is decided, the next step is going through initials{} dictionary and check if it contains any sentence starting with the same letter. Then, it will choose randomly among the list of sentences, if there are more than one.

Results

Code

 

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *