Reading and Writing Text Homework 1
For this homework I wanted to mashup 3 Charles Bukowski programs and make them adorable. I started with 3 poems: Death wants more Death, The Riot, and Two Kinds of Hell.
I started with
cat deathwantsmoredeath.txt theriot.txt twokindsofhell.txt
This is how I combined multiple files.
I ran python hwfeb05.py <charles#.txt>charles#.txt with the pound being increasing numbers from 0-5
This is the code for hwfeb05.py this code divides the poem in half
[cc lang=”python”]
import sys
count = 0
for line in sys.stdin:
line = line.strip()
if count % 2 == 0:
output = line
else:
output = “”
print output
count += 1
[/cc]
Then I ran python  hwfeb05replace.py< charles5.txt>charlesreplace.txt
Here is  the code for hwfeb05replace.py. This replace code is what looks for the words I want to make adorable.
[cc lang=”python”]]
import sys
for line in sys.stdin:
line = line.strip()
line = line.replace(‘death’, ‘pandas’)
line = line.replace(‘corpses’, ‘puppies’)
line = line.replace(‘corpse’, ‘puppy’)
line = line.replace(‘drink’, ‘hug’)
line = line.replace(‘dark’, ‘puppy-eyed’)
line = line.replace(‘drinks’, ‘hugs’)
line = line.replace(‘ladies’, ‘unicorns’)
line = line.replace(‘lady’, ‘unicorn’)
line = line.replace(‘crime’,’party’)
line = line.replace(‘enemy’,’buddy’)
line = line.replace(‘enemies’,’buddies’)
line = line.replace(‘bar’,’playground’)
line = line.replace(‘alone’,’holding hands’)
line = line.replace(‘body’,’kitten’)
line = line.replace(‘bodies’,’kittens’)
print line
[/cc]
Finally I ran python hwfeb05finder.py
[cc lang=”python”]
import sys
for line in sys.stdin:
line = line.strip()
offset = line.find(“pandas”)
if offset != -1:
print line
offset = line.find(“puppies”)
if offset != -1:
print line
offset = line.find(“puppy”)
if offset != -1:
print line
offset = line.find(“hug”)
if offset != -1:
print line
offset = line.find(“puppy-eyed”)
if offset != -1:
print line
offset = line.find(“hugs”)
if offset != -1:
print line
offset = line.find(“unicorns”)
if offset != -1:
print line
offset = line.find(“unicorn”)
if offset != -1:
print line
offset = line.find(“party”)
if offset != -1:
print line
offset = line.find(“buddy”)
if offset != -1:
print line
offset = line.find(“buddies”)
if offset != -1:
print line
offset = line.find(“playground”)
if offset != -1:
print line
offset = line.find(“holding hands”)
if offset != -1:
print line
offset = line.find(“kitten”)
if offset != -1:
print line
offset = line.find(“kittens”)
if offset != -1:
print line
[/cc]
That gave me this output:
The only thing that I need to figure out now is how not to print out duplicate lines