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

 

相关文章:

  • 2022-12-23
  • 2021-06-05
  • 2021-09-09
  • 2021-06-19
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-26
  • 2021-07-01
  • 2021-05-18
  • 2022-12-23
  • 2022-01-28
  • 2022-02-07
相关资源
相似解决方案