How to sort a list by last character of string

后端 未结 4 848
渐次进展
渐次进展 2021-02-19 13:56

I am trying to write a program that orders a list of strings based on the last character in the item.

[\"Tiger 6\", \"Shark 4\", \"Cyborg 8\"] are how my li

4条回答
  •  悲&欢浪女
    2021-02-19 14:21

    def last_letter(word):
        return word[::-1]
    
    mylst = ["Tiger 6", "Shark 4", "Cyborg 8"]
    sorted(mylst, key=last_letter)
    

提交回复
热议问题