When we sort a dictionary by value in Python, we use lambda func. But i tried this way in my lists, instead of values, using another list index number. This may be a short str function/method for my question.
Here is an example:
cardsorder = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
colors = ['C', 'D', 'S', 'H']
handEx = ['8C','TS','KC','9H','4S']
I want to sort my handEx
list elements by using cardsorder
index numbers.
Firstly i scan every element and i find values for sorting:
for card in handEx:
value = cardsorder.index(card[0])
In this way by using these values, i can sort elements by comparing the others but i think it is a very long way to find the solution. Is there a simpler solution, for example using a lambda function?