lst = ["g1 act car", "a8 act zoo", "a2 act car"]
I want to sort a list such that:
- Ignoring 1st token of each string, strings are ordered lexicographically
- If there's a tie, order as per the 1st token
Above list after sorting should be as follows:
lst = ["a2 act car", "g1 act car", "a8 act zoo"]
I want to write the sorting code in a single line. I can write the code for the 1st condition as follows:
lst = sorted(lst, key = lambda x : x.split()[1])
How can I combine the second condition as well in this lambda expression?