Reading and Writing – Now with python!

This week we started out with python. We were asked to make a UNIX command-like python script for text manipulation. In the previous assignment I struggled with line length and that kind of came up again. I played around with the .replace() method and escape characters. I thought that by inserting “\n” into a line it would then be considered a new line in the rest of the script but it did not seem to work that way. Then I decided to try to remove a specific list of words (in this case conjunctions) and I was able to get that working in a for-loop. Eventually I did something similar to the two columns of words I made last week.

This time I chose a Federal Reserve statement on interest rates and a CNN news release about that release as the two source texts. I was able to go through each article and pick out all of the capitalized words over 3 characters in length and print them as a list. Then I added a randomized conjunction to each and created two columns with mostly proper nouns. The output reads fairly well and does seem to juxtapose the institutional and authoritative way the fed speaks with the more speculative and popular language of the CNN article.

Here’s the python code:

Here’s the output:

Information and Federal so

Federal nor Reserve and

Open so Trump so

Market so America’s for

Committee so Wednesday or

December nor President or

Household nor Trump’s or

Measures nor Trump’s for

Inflation so U.S. so

Committee’s yet That but

Market-based but Faster so

Consistent so Right but

Committee or Americans but

Committee for Trump and

Near-term for Republicans nor

Committee or Fed’s but

Committee and Trump nor

Committee so Mexican but

This nor Trade nor

Committee so Mexico so

Committee or House for

However, and Republicans nor

Committee for Supporters but

Treasury nor Some yet

This but Trump’s yet

Committee’s so Congress. nor

Voting for Michael or

FOMC or Arone, for

Janet nor State for

Yellen, but Street so

Chair; but Global but

William for Advisors. nor

Dudley, and Trump’s yet

Vice or America’s yet

Chairman; yet Francisco and

Lael but President or

Brainard; but John and

Charles but Williams but

Evans; or Financial but

Stanley so Times and

Fischer; or Jan. for

Patrick yet March or

Harker; yet Investors or

Robert for March, but

Kaplan; yet Group. or

Neel for

Kashkari; for

Jerome for

Powell; and

Daniel or

Tarullo. nor

Leave a Reply

Your email address will not be published. Required fields are marked *