If I understand you correctly, you want to know how to apply the key sorting method when the key should be applied to an element of your object. In other words, you want to apply the key function to "wordx" and not to the ['wordx', ...] element that you are actually sorting. In this case, you can do this:
my_alphabet = "..." def my_key(elem): word = elem[0] return [my_alphabet.index(c) for c in word] my_list.sort(key=my_key)
or using the style in your first link:
my_alphabet = "..." my_list.sort(key=lambda elem: [my_alphabet.index(c) for c in elem[0]])
Keep in mind that my_list.sort will be sorted in place, actually modifying your list. sorted (my_list, ...) will return a new sorted list.
source share