Hanging on His Every Word

I adapted an old hangman code I wrote to guess words tweeted by Donald Trump

Tim Hintz
3 min readNov 11, 2020

It was late last Friday night and I was feeling particularly anxious. The US presidential elections hadn’t been announced yet which meant that my time was equally spent pouring over election data scraped from the NYT api, fivethirtyeight and doom-scrolling twitter. In addition, I had been given a new project for school and I was recalling with dread the wait times I had just endured trying to grid search a decision tree. I needed something to occupy my hands and my mind.

I was reminded of a game of hangman I wrote while taking an MIT MOOC and realized I could get a little catharsis by combining the code I wrote then, with the feelings I have now.

First let’s take a quick look at the actual game. It runs from the command line, it takes in a word list (more on this later) selects a word from random and then displays to the user how long the word is, which letters they have not tried and how many guesses they have left. Rules are simple, you guess a letter, if you are right, the game displays the letter you got right and give you some encouragement.

--

--

Tim Hintz

Analytic Consultant | Data Science | Lifelong Leaner