How to sort with lambda in Python

前端 未结 4 1513
感情败类
感情败类 2020-11-30 19:41

In Python, I am trying to sort by date with lambda. I can\'t understand my error message. The message is:

() takes exactly 1 argument (2 given         


        
4条回答
  •  無奈伤痛
    2020-11-30 20:11

    lst = [('candy','30','100'), ('apple','10','200'), ('baby','20','300')]
    lst.sort(key=lambda x:x[1])
    print(lst)
    

    It will print as following:

    [('apple', '10', '200'), ('baby', '20', '300'), ('candy', '30', '100')]
    

提交回复
热议问题