Skip to content

Instantly share code, notes, and snippets.

@sidequestboy
Created May 17, 2014 02:04
Show Gist options
  • Save sidequestboy/df7d72e13c98127c37ad to your computer and use it in GitHub Desktop.
Save sidequestboy/df7d72e13c98127c37ad to your computer and use it in GitHub Desktop.
Finding Fixed Points of the Lexicographic ordering of the Phonetic English Alphabet
#!/usr/bin/python
from collections import OrderedDict
conventional_alphabet = list('abcdefghijklmnopqrstuvwxyz')
conventional_phonetic = ['a', 'bee', 'cee', 'dee', 'e', 'ef', 'gee', 'aitch',
'i', 'jay', 'kay', 'el', 'em', 'en', 'o', 'pee',
'cue', 'ar', 'es', 'tee', 'u', 'vee', 'doubleu', 'ex',
'wye', 'zed']
def lexi(letters):
def lexi_(word):
return "".join([conventional_alphabet[list(letters.keys()).index(a)]
for a in word])
return lexi_
def alphabetize(letters):
return OrderedDict(sorted(letters.items(),
key=lambda p: lexi(letters)(p[1])))
if __name__ == "__main__":
alphabet = None
new_alphabet = OrderedDict(zip(conventional_alphabet,
conventional_phonetic))
i = 0
while (alphabet != new_alphabet):
print(list(new_alphabet))
alphabet = new_alphabet
new_alphabet = alphabetize(alphabet)
i += 1
print("Took {} iterations".format(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment