Downtown Func

This week at ITP, "Reading & Writing Electronic Text" is bringing the func back to "functions." Where did it go? I don't know, just keep reading please.

For this assignment, I took my midterm project, "#LoveSucks," and transformed an arduous into a simple, repeatable, scalable one, through use of functions in Python.

Here's the code before:

 

And after:

The function "trimLines" takes the words in a given list, does the following:

def trimLines(loveSucksLine, separator, n=5):
    for item in loveSucksList:
        return separator.join(loveSucksLine[0:n])

  1. Joins them together by removing the comma that currently separates them.
  2. Trims that line down to 5-words (as the rules of the poetry structure dictate).
  3. Prints out eleven iterations, for a total of ten lines (as the rules of the poetry structure dictate).

As you can see, I left variables that make it easy to manipulate the rules of the poem. The number of words to be printed is stores int he variable "n," which can be easily replaced. The separator can also be manipulated, as well s the list from which the function pulls.