Digital Writing with Python: Assignment 1

July 5, 2009

My goal for this assignment was to strip all words greater than three letters out of a given text while keeping the original line spaces and formatting. I thought the idea of removing most of the substantive information from a work, rendering it with almost solely articles and short pronouns, would literally deconstruct those works of their ideas, while still providing patterns reminiscent of the original structure. After much trial and error, I settled on:

import sys
for line in sys.stdin:
  line = line.strip()
  words = line.split()
  newstr = ""
  for word in words:
    word = word.replace ("!", "")
    word = word.replace (",", "")
    if len(word) < 4
      newstr += word
      newstr += ' '
  print newstr

In honor of Independence Day, I ran the Star Spangled Banner through the script. Here's how it rendered:

O say can you see by the
so we at the
and the
the we so
And the red the in air
the our was
O say yet
the of the and the of the