1. Напишите этот же код функциональным методом под комментарием functional solution - решение писать нужно внутрь print в одну строчку
Подсказки даны в комментарии
2. Дополните файл 4 кодом, написанным не функционально и затем дайте функциональное решение
from functools import reduce
# 1st question
items = ["lawyer", "attorney", "prosecutor"]
new_list = []
for i in items:
i = i + " is related to legal affairs"
new_list.append(i)
print(new_list)
#functional solution = use map
print(list(()))
# 2nd question
items_2 = [2, 3, 4, 5]
second_list = []
b = 1
for i in items_2:
b = b * i
print(b)
#functional solution = use reduce
print(())
# 3rd question
items_3 = ["tech law", "tech", "legal IT"]
third_list = []
for i in items_3:
if i == "tech":
third_list.append(i)
print(third_list)
#functional solution = use filter
print(list(()))
# 4th problem = write your own non functional problem and its functional solution
# functional solution
Подсказки даны в комментарии
2. Дополните файл 4 кодом, написанным не функционально и затем дайте функциональное решение
from functools import reduce
# 1st question
items = ["lawyer", "attorney", "prosecutor"]
new_list = []
for i in items:
i = i + " is related to legal affairs"
new_list.append(i)
print(new_list)
#functional solution = use map
print(list(()))
# 2nd question
items_2 = [2, 3, 4, 5]
second_list = []
b = 1
for i in items_2:
b = b * i
print(b)
#functional solution = use reduce
print(())
# 3rd question
items_3 = ["tech law", "tech", "legal IT"]
third_list = []
for i in items_3:
if i == "tech":
third_list.append(i)
print(third_list)
#functional solution = use filter
print(list(()))
# 4th problem = write your own non functional problem and its functional solution
# functional solution