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']

 

posted @ 2019-09-06 14:18  nevermore_29  阅读(1764)  评论(0编辑  收藏  举报