I have a tuple list in which i want to sort according to the order specified in another list. This is the list to be sorted:
Start_Keyword=[(u'NUMBER', u'two', u'2.0', [1]), (u'RND', u'random', u'random', [8])]
The required output is :
Start_Keyword=[(u'RND', u'random', u'random', [8]),(u'NUMBER', u'two', u'2.0', [1])]
What i did is defined an order and sorted according to the index of it:
predefined_list = ['PROB','RND','NUMBER']
ordering = {word: i for i, word in enumerate(predefined_list)}
print sorted(Start_Keyword, key=lambda x: ordering.get)
But i am getting the following error:
print sorted(Start_Keyword2, key=ordering.get)
TypeError: unhashable type: 'list'
please can anyone help on this?