For this simple exercise, you will need a plain text document with lines to upcycle. As I have a lot of poems broken into lines already, this was pretty easy for me to come up with. You don't have to use your own writing, but I encourage you to do so. I have conjured useful surprises from my own work using this program.

Yes, I use Windows, so my file path takes that into account. Look up specifics for reading in files to Python from different OSs.

 

#Exercise 1
#Create your own source file (the more lines of text, the better) 
#and run the program with it. Edit the output(s) into a newly conceived poem 
#(taking the idea of a poem very broadly.)


import random

#filename is the full file path 
filename = 'C:\\Users\\lillian.bertram\\Documents\\samplepoems1.txt'

lines = [ ]

with open (filename, 'r') as file:
    for line in file:
        lines.append (line)

#The "i in range" is arbitrary. 
random_lines = [random.choice(lines) for i in range (20)]

for line in random_lines:
    print (line)
 

Sample Raw Output

(I wouldn't use this as-is, but would edit it or edit it into a pre-existing work and combine them.)

 

 

enter the demon

in miles

bloodied applies

a wave of expediency

dangling

they were armed with long guns

the county roads

nothing innocent

where this is going

kill this deer

on the

or maybe we are still lovers

greatness.

because nothing but

the miller, the baker the candlestick maker

of frontiers,

to the height of kites

page through the faces

return me to my mother

from the swings