0

I would like to order a list using two conditions, sorting by the file extension (txt first) asc and by the file name desc.NameError

# Input list:
lst = ["d.csv", "a.TXT", "b.txt", "c.csv"]

# Expected output:
lst = ["b.txt", "a.TXT", "d.csv", "c.csv"]

I have a sample code, but it uses default order (I have found any posibility to set the reverse option for the second condidiotion only)

sorted(lst, key = lambda x:(x.split(".")[-1].lower(), x.split(".")[0].lower()))
skolukmar
  • 185
  • 1
  • 9
  • Does this answer your question? [How to sort a list with two keys but one in reverse order?](https://stackoverflow.com/questions/37693373/how-to-sort-a-list-with-two-keys-but-one-in-reverse-order) – blhsing Dec 05 '22 at 09:00
  • This particular answer in the linked question answers your question: https://stackoverflow.com/a/56842689/6890912 – blhsing Dec 05 '22 at 09:35

0 Answers0