Elliptical Code and Anthology

Hi everyone! Below is the code we used to generate everyone’s elliptical poem, and I added an additional function that builds a poem anthology, which I’ve put into a pdf and attached to this post below the code for your perusal. I’ve done my best to put really detailed comments on everything so that if anyone wants to use the code or do something similar they can follow it. If you put this into the app that will run the code, all the comments will be in purple or green, but generally the comments are anything following a hashtag (note that just because the text wraps doesn’t mean the hashtag comment ends, so in the first line “capabilities” is still part of the comment; the comment only ends when you actually press enter) or in between two sets of triple quotations (so looking like the example below). Anything else is coding syntax. NOTE: the code doesn’t indent the way it’s supposed to when pasted so it probably won’t work the way you need it to if you just copy and paste it into a python shell. But i’m happy to send you the code file or walk you through what the indents should look like and etc.

“””

comment

“””

–Ellie

 

import random #this is just telling the doc to access some pre-existing code to with randomizing capabilities
“””
Below is a list called master_list, a name I arbitrarily set (as in it doesn’t mean anything particular to the computer, I chose it to help me keep track of things.) the list is a type of data (other types are strings, integers, floats, and dictionaries). Lists can also have sub-lists (imagine separating your to-do list by class), which is also why i called this the master_list, because it has a list of all the other lists. Each sub-list is one set of entries. Notice that each list is in brackets and each entry is separated by a comma (so there is also a comma between the brackets of two separate sub-lists). each entry is in ” to tell the computer that it is a string (text), and in python “” and ” are interchangable.
“””

master_list=[[‘know’, ‘be’, ‘powerful’, ‘nice’, ‘talk’, ‘run’, ‘dont’, ‘avoid’, ‘are’, ‘me’, ‘you’, ‘if’, ‘try’, ‘try’, ‘infinity’, ‘walk’, ‘eyesight’, ‘money’, ‘postulate’, ‘never’, ‘lives’, ‘unruly’, ‘negative’],[‘stop taking things personally.’, ‘get up.’, ‘confidential.’, ‘cat-like.’, ‘play by the rules.’, ‘see rain.’, ‘jump off small balconies.’, ‘jump off large balconies.’, ‘cannot fly.’, ‘theoretical flight.’, ‘grass.’, ‘the sky is not always blue.’, ‘listen to the sky.’, ‘hear without glasses.’, ‘illusions.’, ‘speak about it.’, ‘short focal length.’, ‘throw their bodies from things.’, ‘are loved.’, ‘love.’ , ‘vision.’, ‘peculiar.’, ‘.’],[‘understand’, ‘understand’, ‘understanding’, ‘different’, ‘understand’, ‘succeed’, ‘forget’,’remember’, ‘know’, ‘to excel’, ‘substantial’, ‘they are special’, ‘understand’, ‘understand’, ‘Us’, ‘accept’, ‘their success’, ‘achieve’, ‘succeed’, ‘succeed’, ‘success’, ‘difficult’, ‘frequent’],[‘Do anything but assign all my tests to be on the same day’, ‘Be feminist’, ‘Open to me eating cake with my hands’, ‘Complicit’, ‘DO anything’, ‘Uphold the patriarchy’,’Overcharge for Sour Patch Kids’, ‘Care’, ‘Sometimes do not’, ‘Broken printers’, ‘Me purchasing overpriced ink at the 24 hour Walmart in my pajamas’, ‘i am tired’, ‘refill the vending machines with more urgency when they’re out of baked cheddar snack mix’, ‘Find baked cheddar snack mix now that the 24 hour Walmart no longer carries it’, ‘The fact that my fish has fin rot’, ‘Send my fish’s antibiotics via one day shipping without an upcharge’, ‘The fact that they’re not watching him die’, ‘Shipping and handling’, ‘Are part of the capitalist racist heteropatriarchy’, ‘They never pretended to care’, ‘Reputation in anonymous fish owner chat rooms’, ‘Fishy’, ‘Via customer service Instant Messaging Chats at 2:07am’],[‘smile’, ‘be happy’, ‘optimistic’, ‘dull’, ‘say hi!’, ‘ignore us’, ‘yell’, ‘scream’, ‘hate us’, ‘to avoid everything’, ‘nagative for them and everyone around them’,’they bring others down’, ‘smile!’, ‘perk up’, ‘the world around them’,’be social’, ‘their bad upbringing’, ‘our sympathy’, ‘are sad’, ‘had some harmful experiences’, ‘ability to interact normally with others’, ‘morose’, ‘uncomfortable’],[‘do’, ‘try’, ‘avid’, ‘stagnant’, ‘go’, ‘stay’, ‘resist’, ‘refuse’, ‘hear’, ‘dense’, ‘dire’, ‘were here’, ‘try’, ‘respond’, ‘pleasantries and tact’, ‘engage’, ‘a lack of ears’, ‘action’, ‘are not like us’, ‘have not learned’, ‘movement’, ‘odd’, ‘frustrating’],[‘get along’, ‘eat a peach’, ‘glowing’, ‘nebulous’, ‘speak’, ‘speak’, ‘swim backwards’, ‘jump on the bed’, ‘dont think like us’, ‘exaggerated’, ‘negligible’, ‘me’, ‘understand me’, ‘think like me’, ‘shadows’, ‘say no’, ‘unicorns’, ‘unicorns’, ‘arent unicorns’, ‘should be denied’, ‘front fenders’, ‘absurd’, ‘inconsistent’],[‘think’, ‘believe’, ‘selfish’, ‘connected’, ‘open’, ‘break’, ’empty out’, ‘transform’, ‘hold’, ‘implosion’, ‘misunderstood’, ‘everything is gone’, ‘end it’, ‘create’, ‘the other ones’, ‘play along’, ‘the truth’, ‘the senses’, ‘constructed history’, ‘were broken’, ‘impact on us’, ‘quite like our own’, ‘too short’],[‘fit’, ‘know’, ‘fun’, ‘rude’, ‘understand’, ‘scrutinize’, ‘see’, ‘smile’, ‘overthink’, ‘annoyin’, ‘debunked’, ‘I try’, ‘not judge’, ‘be insensitive’, ‘me’, ‘believe’, ‘money’, ‘money’, ‘have money’, ‘can go with out it’ , ‘perspectives’, ‘unchangeable’, ‘permanent’]]
“””
poem_full is exactly what it sounds like, it is the full poem written as a string

“””
poem_full=’They just cant seem to . . . They should try harder to . . . They ought to be more . . . We all wish they werent so . . . They never . . . They always . . . Sometimes they . . . Once in a while they . . . However it is obvious that they . . . Their overall tendency has been . . . The consequences of which have been . . . They don’t appear to understand that . . . If only they would make an effort to . . . But we know how difficult it is for them to . . . Many of them remain unaware of . . . Some who should know better simply refuse to . . . Of course, their perspective has been limited by . . . On the other hand, they obviously feel entitled to . . . Certainly we can’t forget that they . . . Nor can it be denied that they . . . We know that this has had an enormous impact on their . . . Nevertheless their behavior strikes us as . . . Our interactions unfortunately have been’

poem_by_line=poem_full.split(‘. . .’) #this is telling the computer to create a list where each entry is a part of “poem full” and that it should start a new entry every time there is an ellipse. This can also be used in a number of useful ways by splitting at spaces, commas, or other punctuation

“””
what ‘def’ indicates is you’re defining a function. So you know how in math you have f(x)=12x+17 or whatever? that’s effectively what this is, its telling the computer to go through a process to get an outcome on the other side. Some functions take arguments (i.e. x, we’ll see an example of that later, others don’t
“””
def build_poem():
elliptical=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22] #literally just a list that I can use as an index for the lines, length is number of lines in elliptical
olip_poem=[] #empty list that the function will add to as it creates lines for the poem

“””
Below is what’s called a “for loop” and it basically says that for i in elliptical (that is to say for any given entry in elliptical. Basically i is a variable, like when you have a summation from i=0 to n and so you add up everything from i to n, this will go through every entry in elliptical and do the process outlined underneath it.

The first thing that happens in the loop is the poem builds a new line, which it does in three parts. First,poem_by_line[i] tells the function to retrieve whatever is in poem by line at position i (it is using i as an index), remember, in this case, i is just a number from 0-22 (python starts indexing from 0, so the index of the last number is always one less than the length, which will be important in a minute). So basically the computer goes to the list of poem by line, and the first time through will select whatever is in position 0, which is the first line of the poem. Position 1 is the second line and so on. then it adds a space, and then it adds an entry matching the correct line but from a random poem. The way that’s done is:

it goes into master_list (where all the examples are stored). When you have nested lists, you use two indexes so basically what is below is a more convoluted version of master_list[x][y], meaning go to whatever is in the y position of the list that is in the x position of master list. i.e. if we are on line 4 of the poem and we were using entry set number 6 we would say take the third entry (remember indexed from 0) of the fifth list in master list. in this case, however, instead of [x], we have [random.randint(0,(len(master_list)-1))]. One important thing you need to remember when you’re coding is to make sure all of your parenthesis are matched up, which can get convuluted in this case. So that first and last bracket are the brackets that you would find around x or any other entry (such as i). Rather than having a specific number however, we want the computer to choose randomly which poem it is selecting from, so we use random.randint(). Randint means random integer, so basically, it won’t give a decimal, because there’s no 9.75 index point or etc. then you need to tell it what numbers you want that integer in between. In this case we use 0 to len(master_list)-1. len(z) is a function that returns the length of the list (you can also use it for strings). so in this case we want to use the length of master_list so we know how many answer sets we have to choose from (this can be done by hand by just putting in the number of answers, but this way if you want to use it for other people, it is pre-set up to accommodate that. We subtract 1 because, again, of the indexing starting at 0 (so if the length is 23 the last index is 22 and so on.

finally, it adds that new line to that olip_poem empty list we created above the for loop. Since the list is outside the for loop, it does not reset to empty every time the code iterates over the loop. It does, however reset every time the function is run. The last thing it does is print whatever is in position i in that olip_poem list (now populated by however many lines the code has iterated over so far. if we don’t print by line, it would print as a list, or we could code it to print as one large string to be a prose poem if we wanted)
“””
for i in elliptical:
new_line=poem_by_line[i]+’ ‘+master_list[random.randint(0,(len(master_list)-1))][i]
olip_poem.append(new_line)
print olip_poem[i]
return #return is how you tell the computer that the function is done. Sometimes you have the code return something

def wordsearch(word):
“””
This function takes an argument (just like f(x) needs x plugged into it to work, this needs word plugged into it for it to work. You tell this function a word and it will count how many times it appeared in the results. The results variable below is one large string (in ” but not separated by commas so they are all one entry)
“””
results=’know be powerful nice talk run dont avoid are me you if try try infinity walk eyesight money postulate never lives unruly negative stop taking things personally. get up. confidential. cat-like. play by the rules. see rain. jump off small balconies. jump off large balconies. cannot fly. theoretical flight. grass. the sky is not always blue. listen to the sky. hear without glasses. illusions. speak about it. short focal length. throw their bodies from things. are loved. love. vision. peculiar. .understand understand understanding different understand succeed forget remember know to excel substantial they are special understand understand Us accept their success achieve succeed succeed success difficult frequent Do anything but assign all my tests to be on the same day Be feminist Open to me eating cake with my hands Complicit DO anything Uphold the patriarchy Overcharge for Sour Patch Kids Care Sometimes do not Broken printers Me purchasing overpriced ink at the 24 hour Walmart in my pajamas i am tired refill the vending machines with more urgency when theyre out of baked cheddar snack mix Find baked cheddar snack mix now that the 24 hour Walmart no longer carries it The fact that my fish has fin rot Send my fishs antibiotics via one day shipping without an upcharge The fact that theyre not watching him die Shipping and handling Are part of the capitalist racist heteropatriarchy They never pretended to care Reputation in anonymous fish owner chat rooms Fishy Via customer service Instant Messaging Chats at 2:07am smile be happy optimistic dull say hi! ignore us yell scream hate us to avoid everything nagative for them and everyone around them they bring others down smile! perk up the world around them be social their bad upbringing our sympathy are sad had some harmful experiences ability to interact normally with others morose uncomfortable do try avid stagnant go stay resist refuse hear dense dire were here try respond pleasantries and tact engage a lack of ears action are not like us have not learned movement odd frustrating get along eat a peach glowing nebulous speak speak swim backwards jump on the bed dont think like us exaggerated negligible me understand me think like me shadows say no unicorns unicorns arent unicorns should be denied front fenders Think believe selfish connected open break empty out transform hold implosion misunderstood everything is gone end it create the other ones play along the truth the senses constructed history were broken impact on us quite like our own too short absurd inconsistent’

use=results.count(word,0,len(results)) #this is creating a variable that the function is going to return to us for how many times the word was used. results.count is a function whos arguments are (substring, start, finish). It wants to know what you are looking for in the string and where in the string you want it to look. So this is telling the function to count whatever you put in for word throughout the whole string
return use #returns the number
“””
This is the function created in response to requests to see the original poems. {} signify a dictionary, which is pretty much what it sounds like, you have an entry that is given a definition (be it a list, number, a string or something else (in this case it will be lists).
“””
def anthologize():
anthology={} #creating an empty dictionary for us to append
for i in master_list: #same for loop structure and empty list
individual_poem=[]
for k in i: #nested for loop, much like nested lists. It tells you first that you go to index i of master list and then index k of i (make sure you’re doing new variables
new_line=str(poem_by_line[i.index(k)]+’ ‘+k) #creates a new line by using poem_by_line of i.index(k) (which means that you’re going to use whatever position k is at in i to decide what position you’re going to use to select the line from poem_by_line. then you add a space, and then you add k, which in this case is the actual response associated with that line. Each k is from the same poem, so the second for loop builds an individual poem, and the first for loop tells the computer to do that for every set of answers
individual_poem.append(new_line) #adds the line we’ve just created to our empty list (not the list is inside the first for loop, so it resets every time we build a new poem
anthology[master_list.index(i)]=individual_poem #creates an entry in the dictionary. Uses the index function to create numbered entries and makes the value (or ‘definition’ as the intuition of the name might imply, this list we’ve created

print ‘poem’+’ ‘+str(master_list.index(i)) #this prints a title, so literally the word poem and then str(), which tells the computer to treat the object like a string, and then the index function again to number the poem

for l in anthology[master_list.index(i)]: #note this is outside the second for loop but inside the first (so you do it once per poem), this loop tells the computer to print out every individual line in the poem (which, again, we use the index function to tell the computer which dictionary entry we want). This is how we get the poem to print in a line by line format
print l
return anthology #returns the dictionary
def poems():
poem_count=len(master_list)*23
return poem_count

def main(): #main is the function that tells the computer what to do. Even if the main function is empty you always need to create one
print ‘random poem’ #print this to title the output
print build_poem() #run the build poem function
print wordsearch(‘try’) #count how many times the word try is used, and etc
print wordsearch(‘understand’)
print wordsearch(‘be’)
print wordsearch(‘us’)
print wordsearch(‘them’)
print wordsearch(‘.’)
print wordsearch(‘they’)
print ‘poetic anthology’
print anthologize() #print all of the individual poems
return
if __name__==”__main__”: #these last two lines need to appear at the bottom of your code no matter what
main()

 

 

View Fullscreen

Leave a Reply