python sort without lambda expressions

后端 未结 4 1581
小蘑菇
小蘑菇 2021-02-09 06:30

I often do sorts in Python using lambda expressions, and although it works fine, I find it not very readable, and was hoping there might be a better way. Here is a typical use

4条回答
  •  灰色年华
    2021-02-09 07:00

    I suppose if I wanted to create another function, I could do it something like this (not tested):

    def sortUsingList(indices, values):
        return indices[:].sort(key=lambda a: values[a])
    

    Though I think I prefer to use lambda instead to avoid having to create an extra function.

提交回复
热议问题