Monday, May 29, 2023

Python lambda map and filter

 >>> names = ['Cat' , 'Dog' , 'Mouse' , 'Orangutan']

>>> list(map(lambda x:x[::-1],names))

['taC', 'goD', 'esuoM', 'natugnarO']

>>>

>>> numbs = [ 1,2,3,4,5,6,7,8]
>>> list(filter(lambda x : x%2 == 0, numbs))
[2, 4, 6, 8]
>>>

No comments:

Post a Comment