Skip to content

Instantly share code, notes, and snippets.

@ievans3024
Created August 1, 2018 13:53
Show Gist options
  • Select an option

  • Save ievans3024/158c2e2d5a47a5d36077a3f01ff00aa2 to your computer and use it in GitHub Desktop.

Select an option

Save ievans3024/158c2e2d5a47a5d36077a3f01ff00aa2 to your computer and use it in GitHub Desktop.
An overengineered way to get what 1-based index a letter is in the roman alphabet
import struct
"""
An overengineered way to get what 1-based index a letter is in the roman alphabet
"""
class AlphaBytes:
UPPERCASE = set([struct.pack('>b', i) for i in range(65, 91)])
LOWERCASE = set([struct.pack('>b', i) for i in range(97, 123)])
def alphabet_index(character):
cbytes = bytes(character, 'ascii')
if cbytes in AlphaBytes.UPPERCASE:
modifier = -64
elif cbytes in AlphaBytes.LOWERCASE:
modifier = -96
return struct.unpack('>b', cbytes)[0] + modifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment