How to insert elements of a list into another list depending on date value?

后端 未结 3 1808
孤独总比滥情好
孤独总比滥情好 2021-01-22 09:39

I have a list of homes :

list1 = [home1, home2, home3, home4]

and I have another list of specific homes:

list2 = [ home6, home7         


        
3条回答
  •  情歌与酒
    2021-01-22 10:42

    To return a new sorted list, you should use the sorted() built-in function:

    sorted_list = sorted(list1 + list2, key=lambda x: x.date, reverse=True)
    

提交回复
热议问题