List comprehension vs. lambda + filter

前端 未结 14 2145
挽巷
挽巷 2020-11-22 02:01

I happened to find myself having a basic filtering need: I have a list and I have to filter it by an attribute of the items.

My code looked like this:



        
14条回答
  •  醉酒成梦
    2020-11-22 02:41

    I find the second way more readable. It tells you exactly what the intention is: filter the list.
    PS: do not use 'list' as a variable name

提交回复
热议问题