python filter lambda 的使用
Posted nevermore29
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python filter lambda 的使用相关的知识,希望对你有一定的参考价值。
lambda 匿名函数的使用
>>> a=lambda x : x in "1234567890.," >>> a("asd") False >>> a("123") True >>> filter(lambda x : x in "1234567890.,","123asd") ‘123‘
加上filter的混合使用:
>>> filter(lambda x : x in "1234567890.,","123asd") ‘123‘
filter后面的跟的参数是function和string(当然也可以是list)
>>> filter(lambda x : x in "1234567890.,",[‘1‘,‘2‘,‘3‘,‘a‘]) [‘1‘, ‘2‘, ‘3‘]
以上是关于python filter lambda 的使用的主要内容,如果未能解决你的问题,请参考以下文章