Created
November 8, 2012 22:14
-
-
Save diiq/4042087 to your computer and use it in GitHub Desktop.
Fixed point 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
alphabet = [("a", "a"), ("bee", "b"), ("see", "c"), ("dee", "d"), | |
("e", "e"), ("ef", "f"), ("gee", "g"), ("aitch", "h"), | |
("i", "i"), ("jay", "j"), ("kay", "k"), ("ell", "l"), | |
("em", "m"), ("en", "n"), ("o", "o"), ("pee", "p"), | |
("cue", "q"), ("ar", "r"), ("ess", "s"), ("tee", "t"), | |
("u", "u"), ("vee", "v"), ("double-u", "w"), ("ex", "x"), | |
("wye", "y"), ("zee", "z")] | |
def alpha_ind(a): | |
for i in range(len(alphabet)): | |
if (alphabet[i][1] == a): | |
return i | |
def alpha_cmp(a, b): | |
if a == "" and b == "": | |
return 0; | |
if a == "": | |
return -1; | |
if b == "": | |
return 1; | |
if a[0] == b[0]: | |
return alpha_cmp(a[1:], b[1:]); | |
return cmp(alpha_ind(a[0]), | |
alpha_ind(b[0])); | |
def new_alphabet(): | |
global alphabet | |
alphabet = sorted(alphabet, | |
cmp=lambda x, y: alpha_cmp(x[0], y[0])) | |
return alphabet | |
if __name__ == '__main__': | |
while new_alphabet() != new_alphabet(): pass | |
print [a[1] for a in alphabet] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment