In [1]:
def add_def(a, b=1):
    return a + b

In [2]:
add_lambda = lambda a, b=1: a + b

In [3]:
print(add_def(3, 4))


7

In [4]:
print(add_def(3))


4

In [5]:
print(add_lambda(3, 4))


7

In [6]:
print(add_lambda(3))


4

In [7]:
get_odd_even = lambda x: 'even' if x % 2 == 0 else 'odd'

In [8]:
print(get_odd_even(3))


odd

In [9]:
print(get_odd_even(4))


even

In [10]:
l = ['Charle', 'Bob', 'Alice']

In [11]:
l_sorted = sorted(l)

print(l_sorted)


['Alice', 'Bob', 'Charle']

In [12]:
print(len('Alice'))


5

In [13]:
l_sorted_len = sorted(l, key=len)

print(l_sorted_len)


['Bob', 'Alice', 'Charle']

In [14]:
print((lambda x: x[1])('Alice'))


l

In [15]:
l_sorted_second = sorted(l, key=lambda x: x[1])

print(l_sorted_second)


['Charle', 'Alice', 'Bob']

In [16]:
l = [0, 1, 2, 3]

In [17]:
map_square = map(lambda x: x**2, l)

print(map_square)


<map object at 0x1072fd128>

In [18]:
print(list(map_square))


[0, 1, 4, 9]

In [19]:
l_square = [x**2 for x in l]

print(l_square)


[0, 1, 4, 9]

In [20]:
g_square = (x**2 for x in l)

print(g_square)


<generator object <genexpr> at 0x1072b6d00>

In [21]:
print(list(g_square))


[0, 1, 4, 9]

In [22]:
filter_even = filter(lambda x: x % 2 == 0, l)

print(list(filter_even))


[0, 2]

In [23]:
l_even = [x for x in l if x % 2 == 0]

print(l_even)


[0, 2]