tutorial6 lambda



In [1]:
map(lambda x: x * x, [1,2,3])


Out[1]:
[1, 4, 9]

In [2]:
filter(lambda x: x > 3, [1,2,3,4,5,4,3,2,1])


Out[2]:
[4, 5, 4]

In [4]:
nums = [1,2,3,4,5,6]
plusOneNums = [x+1 for x in nums]
plusOneNums


Out[4]:
[2, 3, 4, 5, 6, 7]

In [6]:
oddNums = [x for x in nums if x % 2 == 1]
print oddNums


[2, 6, 10]

In [7]:
oddNumsPlusOne = [x+1 for x in nums if x % 2 ==1]
print oddNumsPlusOne


[2, 4, 6]

In [ ]: