Alphabet Math With Python

Chase Thompson
5 min readMar 13, 2020

We left off the last time with the challenge to apply a 1–26 numerical value to each letter of the alphabet. Then find a five-letter word where the numerical sum of the last four letters equaled the value of the first letter.

Ex. ZEBRA : 26 = 5 + 2 + 18 + 1

If you chose to take up the challenge, here was a prompt to get you started:

with open('/usr/share/dict/words') as f:
words = f.read().split('\n')
print(words[:5])

This particular code prompt, if you’re using a Mac, would give you access to a rather large library of words to use for the challenge.

Let’s get started.

Apply Numerical Value to Letters

The first thing we have to do to tackle this challenge is assigning a 1–26 value to each letter in the alphabet.

Though this challenge could be completed with vanilla Python, which is Python without importing any additional libraries, I decided to use Pandas. I highly recommend, if you are unfamiliar with the library Pandas, you do a search here on Medium to find some of the great content covering the topic.

import pandas as pdwith open(‘/usr/share/dict/words’) as f: 
words = f.read().split()

--

--