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))
In [4]:
print(add_def(3))
In [5]:
print(add_lambda(3, 4))
In [6]:
print(add_lambda(3))
In [7]:
get_odd_even = lambda x: 'even' if x % 2 == 0 else 'odd'
In [8]:
print(get_odd_even(3))
In [9]:
print(get_odd_even(4))
In [10]:
l = ['Charle', 'Bob', 'Alice']
In [11]:
l_sorted = sorted(l)
print(l_sorted)
In [12]:
print(len('Alice'))
In [13]:
l_sorted_len = sorted(l, key=len)
print(l_sorted_len)
In [14]:
print((lambda x: x[1])('Alice'))
In [15]:
l_sorted_second = sorted(l, key=lambda x: x[1])
print(l_sorted_second)
In [16]:
l = [0, 1, 2, 3]
In [17]:
map_square = map(lambda x: x**2, l)
print(map_square)
In [18]:
print(list(map_square))
In [19]:
l_square = [x**2 for x in l]
print(l_square)
In [20]:
g_square = (x**2 for x in l)
print(g_square)
In [21]:
print(list(g_square))
In [22]:
filter_even = filter(lambda x: x % 2 == 0, l)
print(list(filter_even))
In [23]:
l_even = [x for x in l if x % 2 == 0]
print(l_even)