Let me create an alphabet and a list of words:
In [32]: alphabet = "bafmxpzv"
In [33]: a = ['af', 'ax', 'am', 'ab', 'zvpmf']
Now sort them according to where the letters appear in alphabet:
In [34]: sorted(a, key=lambda word: [alphabet.index(c) for c in word])
Out[34]: ['ab', 'af', 'am', 'ax', 'zvpmf']
The above sortings are in the correct order.
sorted . sorted : cmp, key reverse:
cmp . , cmp It, . , , , , . cmp .
key, spedified, , , python . .
key alphabet.
reverse, true, .
:
In [35]: sorted(a, key=lambda word: [alphabet.index(c) for c in word[0]])
Out[35]: ['af', 'ax', 'am', 'ab', 'zvpmf']
, . , key . key:
In [2]: key=lambda word: [alphabet.index(c) for c in word[0]]
In [3]: key('af')
Out[3]: [1]
In [4]: key('ax')
Out[4]: [1]
, key , af ax. . - sorted , af ax.