Python 学习杂记

馋奶兔 提交于 2020-03-30 05:24:27

Case:

Suppose we have a very complex list [1,[2,2,2],[3,[4,5[6]]],7,8], and we need to convert it into a one-row list.

Solution:

iter_fuc():

    return sum(map( lambda a: iter_fuc(a) if isinstance(a, (list)) else [a] , array))

Lambda functions -- 差不多就是python的inline function, 需要注意的是lambda彻底就是function,因此在其中是无法print 和raise的.

顺路看了个wiki:http://www.secnetix.de/olli/Python/lambda_functions.hawk

filter(), map(), reduce()都可以和lambda结合起来一起使用

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!