## Lekcja – Przetwarzanie danych z list. Funkcja lambda

```
my_list = list(range(10))
my_list

def fun_square(x):
return x*x

[fun_square(x) for x in my_list]

[(lambda x: x*x)(x) for x in my_list]

[x*x for x in my_list]```

## Rozwiązanie

```
names = ['John Johnson', 'Alicja Policja', 'Wlodimir Wladymirowicz']

def get_sub_name(name, part):
# name that should be splitted by space
# part - which part of the name should be returned (0 - FirstName, 1 - LastName)
first_name = name.split(' ')[part]
return first_name

first_names = [get_sub_name(name, 0) for name in names]
last_names = [get_sub_name(name, 1) for name in names]
print(first_names)
print(last_names)

first_names = [(lambda name: name.split(' ')[0])(name) for name in names]
last_names = [(lambda name: name.split(' ')[1])(name) for name in names]
print(first_names)
print(last_names)

first_names = [name.split(' ')[0] for name in names]
last_names = [name.split(' ')[1] for name in names]
print(first_names)
print(last_names)```