Created
May 17, 2014 02:04
-
-
Save sidequestboy/df7d72e13c98127c37ad to your computer and use it in GitHub Desktop.
Finding Fixed Points of the Lexicographic ordering of the Phonetic English Alphabet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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