I have a question:
This is list of lists, formed by ElementTree library.
[['word1', <Element tag at b719a4cc>], ['word2', <Element tag at b719a6cc>], ['word3', <Element tag at b719a78c>], ['word4', <Element tag at b719a82c>]]
word1..4 may contain unicode characters i.e (â,ü,ç).
I want to sort this list of lists by my custom alphabet.
I know how to sort by custom alphabet from here
sorting words in python
I also know how to sort by key from here http://wiki.python.org/moin/HowTo/Sorting
The problem is that I couldn’t find the way how to apply these two method to sort my “list of lists”.
Your first link more or less solves the problem. You just need to have the lambda function only look at the first item in your list:
One modification I might suggest, if you’re sorting a reasonably large list, is to change the alphabet structure into a dict first, so that index lookup is faster: